From 23af34de8339125bb7bf58d90c08301d0fb217b2 Mon Sep 17 00:00:00 2001 From: Gene Payne Date: Tue, 13 Oct 2020 00:31:42 -0600 Subject: [PATCH] Fixes to prevent segfault when OpenSpace app closes --- .../ext/launcher/src/launcherwindow.cpp | 4 +++- apps/OpenSpace/main.cpp | 23 +++++++++---------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/apps/OpenSpace/ext/launcher/src/launcherwindow.cpp b/apps/OpenSpace/ext/launcher/src/launcherwindow.cpp index 774b75d82b..15d782fc67 100644 --- a/apps/OpenSpace/ext/launcher/src/launcherwindow.cpp +++ b/apps/OpenSpace/ext/launcher/src/launcherwindow.cpp @@ -332,7 +332,9 @@ bool LauncherWindow::loadProfileFromFile(Profile*& p, std::string filename) { } LauncherWindow::~LauncherWindow() { - delete myEditorWindow; + if (myEditorWindow != nullptr) { + delete myEditorWindow; + } } bool LauncherWindow::wasLaunchSelected() { diff --git a/apps/OpenSpace/main.cpp b/apps/OpenSpace/main.cpp index 0a6725a548..0303d899c2 100644 --- a/apps/OpenSpace/main.cpp +++ b/apps/OpenSpace/main.cpp @@ -63,6 +63,7 @@ #include #include #include +#include #ifdef WIN32 #include @@ -988,16 +989,14 @@ std::string setWindowConfigPresetForGui(const std::string labelFromCfgFile, return preset; } -std::string getSelectedSgctProfileFromLauncher(LauncherWindow* lw, bool hasCliSGCTConfig, +std::string getSelectedSgctProfileFromLauncher(LauncherWindow& lw, bool hasCliSGCTConfig, std::string windowConfiguration, const std::string& labelFromCfgFile, const std::string& xmlExt) { std::string config = windowConfiguration; if (!hasCliSGCTConfig) { - if (lw != nullptr) { - config = lw->selectedWindowConfig(); - } + config = lw.selectedWindowConfig(); if (config.find(labelFromCfgFile) != std::string::npos) { if (config.find("sgct.config") == std::string::npos) { config = config.substr(0, config.length() - labelFromCfgFile.length()); @@ -1165,16 +1164,16 @@ int main(int argc, char** argv) { std::string windowCfgPreset = setWindowConfigPresetForGui(labelFromCfgFile, xmlExt, haveCliSGCTConfig, sgctFunctionName); - QApplication* qaobj = nullptr; - LauncherWindow* launchwin = nullptr; + std::shared_ptr qaobj; + std::shared_ptr launchwin; bool skipLauncherSinceProfileAndWindowAreConfiguredInCli = (haveCliProfile && haveCliSGCTConfig) || global::configuration.bypassLauncher; if (!skipLauncherSinceProfileAndWindowAreConfiguredInCli) { int qac = 0; - qaobj = new QApplication(qac, nullptr); - launchwin = new LauncherWindow(absPath("${BASE}"), !haveCliProfile, - global::configuration, !haveCliSGCTConfig, windowCfgPreset); + qaobj.reset(new QApplication(qac, nullptr)); + launchwin.reset(new LauncherWindow(absPath("${BASE}"), !haveCliProfile, + global::configuration, !haveCliSGCTConfig, windowCfgPreset)); launchwin->show(); qaobj->exec(); @@ -1184,7 +1183,7 @@ int main(int argc, char** argv) { global::configuration.profile = launchwin->selectedProfile(); windowConfiguration = getSelectedSgctProfileFromLauncher( - launchwin, + *launchwin, haveCliSGCTConfig, windowConfiguration, labelFromCfgFile, @@ -1306,8 +1305,8 @@ int main(int argc, char** argv) { } #endif // OPENSPACE_HAS_SPOUT - delete launchwin; - delete qaobj; + launchwin->close(); + qaobj->quit(); ghoul::deinitialize(); exit(EXIT_SUCCESS);