diff --git a/common/lc_application.cpp b/common/lc_application.cpp index 1a05ea97..87379814 100644 --- a/common/lc_application.cpp +++ b/common/lc_application.cpp @@ -758,22 +758,8 @@ lcStartupMode lcApplication::Initialize(QList>& LibraryPath return lcStartupMode::Error; } - if (AASamples > 1) - { #ifdef LC_USE_QOPENGLWIDGET - QSurfaceFormat Format = QSurfaceFormat::defaultFormat(); - Format.setSamples(AASamples); - QSurfaceFormat::setDefaultFormat(Format); -#else - QGLFormat Format; - Format.setSampleBuffers(true); - Format.setSamples(AASamples); - QGLFormat::setDefaultFormat(Format); -#endif - } - -#ifdef LC_USE_QOPENGLWIDGET - if (!lcContext::CreateOffscreenContext()) + if (!InitializeRenderer(AASamples)) return lcStartupMode::Error; #endif @@ -1014,8 +1000,47 @@ lcStartupMode lcApplication::Initialize(QList>& LibraryPath void lcApplication::Shutdown() { + delete gMainWindow; + gMainWindow = nullptr; + + delete mProject; + mProject = nullptr; + delete mLibrary; mLibrary = nullptr; + + ShutdownRenderer(); +} + +bool lcApplication::InitializeRenderer(int AASamples) +{ + if (AASamples > 1) + { +#ifdef LC_USE_QOPENGLWIDGET + QSurfaceFormat Format = QSurfaceFormat::defaultFormat(); + Format.setSamples(AASamples); + QSurfaceFormat::setDefaultFormat(Format); +#else + QGLFormat Format; + Format.setSampleBuffers(true); + Format.setSamples(AASamples); + QGLFormat::setDefaultFormat(Format); +#endif + } + +#ifdef LC_USE_QOPENGLWIDGET + if (!lcContext::CreateOffscreenContext()) + return false; +#endif + + return true; +} + +void lcApplication::ShutdownRenderer() +{ +#ifdef LC_USE_QOPENGLWIDGET + lcContext::DestroyOffscreenContext(); +#endif } void lcApplication::ShowPreferencesDialog() diff --git a/common/lc_application.h b/common/lc_application.h index 70058ee0..320e3026 100644 --- a/common/lc_application.h +++ b/common/lc_application.h @@ -104,6 +104,8 @@ public: QByteArray mClipboard; protected: + bool InitializeRenderer(int AASamples); + void ShutdownRenderer(); void UpdateStyle(); QString GetTabLayoutKey() const; diff --git a/qt/qtmain.cpp b/qt/qtmain.cpp index cf6018a0..bd34c02b 100644 --- a/qt/qtmain.cpp +++ b/qt/qtmain.cpp @@ -1,9 +1,7 @@ #include "lc_global.h" #include "lc_application.h" #include "lc_qupdatedialog.h" -#include "lc_mainwindow.h" #include "lc_profile.h" -#include "lc_context.h" #include #include @@ -198,12 +196,7 @@ int main(int argc, char *argv[]) ExecReturn = Application.exec(); } -#ifdef LC_USE_QOPENGLWIDGET - lcContext::DestroyOffscreenContext(); -#endif - - delete gMainWindow; - gMainWindow = nullptr; + Application.Shutdown(); return ExecReturn; }