Skip to content

Viewer: setExitCode() for a non-zero exit code after a normal shutdown - #7103

Open
Fedr wants to merge 1 commit into
masterfrom
viewer-exit-code
Open

Fedr wants to merge 1 commit into
masterfrom
viewer-exit-code

Conversation

@Fedr

@Fedr Fedr commented Oct 11, 2026

Copy link
Copy Markdown
Contributor

Adds Viewer::setExitCode( int ) and getExitCode(). Viewer::launch now returns the stored code (default 0) instead of always EXIT_SUCCESS after the event loop and launchShut. launchDefaultViewer already passes launch's result on, so main returns it.

Why. An application built on the viewer that needs to exit with an error code, e.g. after a failing command-line script, had no way to do so through the normal shutdown. It had to call std::exit( code ) from inside the event loop. That runs static destructors and atexit handlers while the viewer, the plugins, an embedded Python interpreter and helper threads (SpaceMouse listener, web requests) are still alive, and the process aborts (Crash signal: 6, then 11) instead of returning the code. With this change the application calls setExitCode( code ) and stopEventLoop(), and the viewer shuts down normally.

No behavior change for existing callers: the default stays 0.

🤖 Generated with Claude Code

Viewer::launch always returned EXIT_SUCCESS after the event loop, so an
application that wants to exit with an error code had to call std::exit
while the viewer, plugins and helper threads were still alive, which runs
static destructors under them and crashes. setExitCode() stores the code
and launch returns it after launchShut; launchDefaultViewer passes it on.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant