Skip to content

Fix Linux segfault on application exit (dead GL context in global destructors) - #577

Open
Arm4g3ddon wants to merge 2 commits into
CrealityOfficial:masterfrom
Arm4g3ddon:fix/linux-exit-crash
Open

Arm4g3ddon wants to merge 2 commits into
CrealityOfficial:masterfrom
Arm4g3ddon:fix/linux-exit-crash

Conversation

@Arm4g3ddon

Copy link
Copy Markdown

Problem

On Linux, Creality Print segfaults on every exit (reproducible across 7.0.x → 7.2.0). systemd records a SIGSEGV coredump each time the app is closed.

The coredumpctl traces are truncated (the unwinder itself crashes), and a stray libjavascriptcoregtk frame makes it look WebKit-related. A full backtrace against an unstripped build shows the real cause:

GUI_App::OnExit()
  -> std::exit(0)
    -> <C++ global/static destructors>
      -> Slic3r::GUI::GLModel::~GLModel()
        -> GLModel::reset()
          -> GLModel::RenderData::release()
            -> ::glDeleteBuffers()          <-- SIGSEGV

GUI_App::OnExit() ends with std::exit(0), which drives the C++ global/static destructors. Static GLModel instances are torn down there and call RenderData::release() -> glDeleteBuffers() after the GL/GTK context has already been destroyed, so the GL entry point is stale and dereferencing it faults. breakpad's signal handler then double-faults on top (see second commit).

Fix

1. Skip the global-destructor teardown on Linux exit. All persistent state (AppConfig, presets) is already saved during the window-close sequence and wxApp::OnExit(), so there is nothing left to flush by the time we reach the end of OnExit(). On Linux, terminate via std::_Exit(0) instead of std::exit(0) to avoid running the global destructors that touch a dead GL context. Windows/macOS are unchanged (#ifdef __linux__).

2. Make dumpCallback exception-safe. It runs from breakpad's signal handler but performs throwing boost::filesystem operations (rename, create_directories). When one throws (e.g. the crash-dump dir is missing) the exception unwinds out of the signal handler and double-faults into a second, harder crash, losing the minidump. The body is now wrapped in a catch-all so no exception can escape the handler.

Testing

Built for Linux (Ubuntu 24.04 / GCC 13) and run on Arch Linux + X11. Before: a SIGSEGV coredump on every exit. After: the app exits cleanly, no coredump.

Both changes are Linux-only in effect and don't alter Windows/macOS behavior.

Tim Johannes added 2 commits July 3, 2026 11:39
On exit, GUI_App::OnExit() called std::exit(0), which drives the C++
global/static destructors. Static GLModel instances are destroyed there and
call GLModel::RenderData::release() -> glDeleteBuffers() after the GL/GTK
context has already been torn down, dereferencing a stale GL entry point and
segfaulting. breakpad's signal handler then double-faults on top.

Backtrace (Linux, 7.2.x):
  GUI_App::OnExit -> std::exit -> <global dtors> -> GLModel::~GLModel
    -> GLModel::reset -> RenderData::release -> glDeleteBuffers -> SIGSEGV

All persistent state is already saved during the window-close sequence and
wxApp::OnExit(), so on Linux terminate via std::_Exit(0) to skip the
global-destructor teardown. Windows/macOS keep std::exit(0).
dumpCallback() runs from breakpad's signal handler but performs throwing
boost::filesystem operations (rename/create_directories). When one throws
(e.g. missing crash-dump dir), the exception unwinds out of the signal
handler and double-faults into a second, harder crash, losing the minidump.
Wrap the body in a catch-all so no exception can escape the handler.
@Arm4g3ddon

Copy link
Copy Markdown
Author

Still reproducible in Creality's temporary Linux build V7.2.0.5251 (the one posted in #552 that fixes the read-only regression). That build does not address this exit crash — closing the app produces a fresh SIGSEGV coredump every time.

Coredump top frames (5251, stripped binary, but the signature matches):

#0  libgcc_s.so.1        (unwinder)
#1  _Unwind_RaiseException
#2  __cxa_throw
#3  CrealityPrint + 0x4fda11a   (exception thrown during shutdown)

Same pattern as the traced cause here: an exception thrown out of the global-destructor teardown / breakpad signal handler on exit. So this is orthogonal to the read-only fix and still needs merging.

  • build sha256: 572f8cfdc6c6818aaaf059acc01c36a023b08e8ec4f86674b3febebf17e84954
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants