diff --git a/software/talipot/src/main.cpp b/software/talipot/src/main.cpp index b4f9b0eba1..f9c1d0cf47 100644 --- a/software/talipot/src/main.cpp +++ b/software/talipot/src/main.cpp @@ -212,7 +212,16 @@ int main(int argc, char **argv) { exit(1); } + auto cleanup = []() { + // We need to clear allocated OpenGL resources to avoid a + // segfault when we close talipot + GlTextureManager::deleteAllTextures(); + GlOffscreenRenderer::instance().deleteEarly(); + PythonInterpreter::instance().deleteEarly(); + }; + if (debugPluginsLoad && !pluginErrors.isEmpty()) { + cleanup(); return 1; } @@ -240,11 +249,7 @@ int main(int argc, char **argv) { mainWindow.deleteEarly(); - // We need to clear allocated OpenGL resources to avoid a - // segfault when we close talipot - GlTextureManager::deleteAllTextures(); - GlOffscreenRenderer::instance().deleteEarly(); - PythonInterpreter::instance().deleteEarly(); + cleanup(); return result; }