Skip to content

apprt/gtk: fix SIGSEGV on ImGui GLArea re-realize - #11025

Merged
mitchellh merged 1 commit into
mainfrom
push-toupvwrpypwz
Feb 26, 2026
Merged

mitchellh merged 1 commit into
mainfrom
push-toupvwrpypwz

Conversation

@mitchellh

Copy link
Copy Markdown
Contributor

Fixes #10406

ImGui_ImplOpenGL3_Shutdown() calls imgl3wShutdown() which dlcloses the GL library handles but does not zero out the imgl3w function pointer table (imgl3wProcs). When a GLArea is re-realized (e.g. during reparenting), ImGui_ImplOpenGL3_Init() calls ImGui_ImplOpenGL3_InitLoader() which checks "if (glGetIntegerv == nullptr)". Since the stale pointers are non-null, it skips re-initialization. The next GL call through a dangling function pointer causes a SIGSEGV.

Fix this by introducing ImGui_ImplOpenGL3_ShutdownWithLoaderCleanup() which calls the normal shutdown and then zeroes the imgl3wProcs table, forcing the next Init to reload GL function pointers via imgl3wInit().

Also properly destroy the ImGui context and reset widget state in glAreaUnrealize so re-realize starts clean. This was extra but was probably leaking memory.

Fixes #10406

ImGui_ImplOpenGL3_Shutdown() calls imgl3wShutdown() which dlcloses the
GL library handles but does not zero out the imgl3w function pointer
table (imgl3wProcs). When a GLArea is re-realized (e.g. during
reparenting), ImGui_ImplOpenGL3_Init() calls ImGui_ImplOpenGL3_InitLoader()
which checks "if (glGetIntegerv == nullptr)". Since the stale pointers
are non-null, it skips re-initialization. The next GL call through a
dangling function pointer causes a SIGSEGV.

Fix this by introducing ImGui_ImplOpenGL3_ShutdownWithLoaderCleanup()
which calls the normal shutdown and then zeroes the imgl3wProcs table,
forcing the next Init to reload GL function pointers via imgl3wInit().

Also properly destroy the ImGui context and reset widget state in
glAreaUnrealize so re-realize starts clean. This was extra but was
probably leaking memory.
@mitchellh
mitchellh requested a review from a team as a code owner February 25, 2026 23:25
@mitchellh

Copy link
Copy Markdown
Contributor Author

I fixed the macOS build errors on main.

@mitchellh
mitchellh merged commit eb531ca into main Feb 26, 2026
121 of 129 checks passed
@mitchellh
mitchellh deleted the push-toupvwrpypwz branch February 26, 2026 00:03
@github-actions github-actions Bot added this to the 1.3.0 milestone Feb 26, 2026
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.

Opening the Terminal Inspector a second time crashes ghostty

2 participants