mirror of
https://github.com/ghostty-org/ghostty.git
synced 2026-04-14 03:25:50 +00:00
apprt/gtk: fix SIGSEGV on ImGui GLArea re-realize
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.
This commit is contained in:
@@ -27,4 +27,25 @@ CIMGUI_API void ImGuiStyle_ImGuiStyle(cimgui::ImGuiStyle* self)
|
||||
::ImGuiStyle defaults;
|
||||
*reinterpret_cast<::ImGuiStyle*>(self) = defaults;
|
||||
}
|
||||
|
||||
// Perform the OpenGL3 backend shutdown and then zero out the imgl3w
|
||||
// function pointer table. ImGui_ImplOpenGL3_Shutdown() calls
|
||||
// imgl3wShutdown() which dlcloses the GL library handles but does not
|
||||
// zero out the function pointers. A subsequent ImGui_ImplOpenGL3_Init()
|
||||
// sees the stale (non-null) pointers, skips loader re-initialization,
|
||||
// and crashes when calling through them. Zeroing the table forces the
|
||||
// next Init to reload the GL function pointers via imgl3wInit().
|
||||
#ifndef IMGUI_DISABLE
|
||||
#if __has_include("backends/imgui_impl_opengl3.h")
|
||||
#include "backends/imgui_impl_opengl3.h"
|
||||
#include "backends/imgui_impl_opengl3_loader.h"
|
||||
|
||||
CIMGUI_API void ImGui_ImplOpenGL3_ShutdownWithLoaderCleanup()
|
||||
{
|
||||
::ImGui_ImplOpenGL3_Shutdown();
|
||||
memset(&imgl3wProcs, 0, sizeof(imgl3wProcs));
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user