From ba4aff29a17ecb11cb9af99d2a5bc168df40ac14 Mon Sep 17 00:00:00 2001 From: Arne-W Date: Wed, 15 Feb 2023 18:54:57 +0100 Subject: [PATCH] MainWindow: Fix segfault when calling dtor due to static singleton object. Uses static pointer again. --- src/ui/MainWindow.cc | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/ui/MainWindow.cc b/src/ui/MainWindow.cc index b38639ae1..17ca66859 100644 --- a/src/ui/MainWindow.cc +++ b/src/ui/MainWindow.cc @@ -128,8 +128,14 @@ void LogWindowSingleton::removeDebugOutput() MainWindow* MainWindow::instance() { - static MainWindow myWindow; - return &myWindow; + // This singleton impl. is NOT thread safe. Fortunately we do not need + // thread safety as the first call is always done @ application start. + static MainWindow* instance{nullptr}; + if(instance == nullptr) + { + instance = new MainWindow(); + } + return instance; } // inline function definitions