Skip to content

Commit 05e0a01

Browse files
committed
frontend: release widget OpenGL resources before the context is destroyed
igexplorer segfaulted on close: the static Context outlived the stack-local Application, so RenderWidget was destroyed during exit handlers and its GLTexture members called glDeleteTextures through invalidated glad pointers. Drop the Context references while the Application is alive, and clear the Application children before ui::shutdown. Both owners must release early; either one alone keeps the widgets alive past glfwTerminate. Regression from the SDL2 to GLFW migration.
1 parent c98374e commit 05e0a01

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

src/frontend/explorer/main.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,21 @@ class Context {
5858
app->setDropCallback(openFileCallback);
5959
}
6060

61+
// Must be called while the Application, and therefore the OpenGL context, is still alive
62+
void teardown()
63+
{
64+
mRegistryWidget.reset();
65+
mRegistryMenuItem.reset();
66+
mOverviewWidget.reset();
67+
mOverviewMenuItem.reset();
68+
mParameterWidget.reset();
69+
mParameterMenuItem.reset();
70+
mHelpControlWidget.reset();
71+
mHelpAboutWidget.reset();
72+
mRenderWidget.reset();
73+
mApplication = nullptr;
74+
}
75+
6176
static inline Context& instance()
6277
{
6378
static Context sContext;
@@ -190,6 +205,7 @@ int main(int argc, char** argv)
190205

191206
const int exitcode = app.exec() ? EXIT_SUCCESS : EXIT_FAILURE;
192207
Context::instance().renderWidget()->cleanup();
208+
Context::instance().teardown();
193209

194210
return exitcode;
195211
} catch (const std::exception& e) {

src/frontend/ui/Application.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ class ApplicationInternal {
4242

4343
~ApplicationInternal()
4444
{
45+
// Widgets may own OpenGL resources, which must be released while the context is still current
46+
mChildren.clear();
4547
ui::shutdown(mWindow);
4648
}
4749

0 commit comments

Comments
 (0)