From 5ca460c0bf5e01dbec01aaf26f071e9795f1e4ae Mon Sep 17 00:00:00 2001 From: Leonardo Zide Date: Sun, 10 Jan 2021 11:03:54 -0800 Subject: [PATCH] Set default surface format before creating lcApplication instance. Fixes #594 , #577. --- common/lc_application.cpp | 25 ++++++++++++------------- common/lc_application.h | 4 ++-- qt/qtmain.cpp | 18 ++++++++++++++++++ 3 files changed, 32 insertions(+), 15 deletions(-) diff --git a/common/lc_application.cpp b/common/lc_application.cpp index 2a5a1af4..552c92ea 100644 --- a/common/lc_application.cpp +++ b/common/lc_application.cpp @@ -140,26 +140,20 @@ void lcPreferences::SetInterfaceColors(lcColorTheme ColorTheme) lcApplication::lcApplication(int& Argc, char** Argv) : QApplication(Argc, Argv) { - setApplicationDisplayName("LeoCAD"); - setOrganizationDomain("leocad.org"); - setOrganizationName("LeoCAD Software"); - setApplicationName("LeoCAD"); - setApplicationVersion(LC_VERSION_TEXT); + setApplicationDisplayName(QLatin1String("LeoCAD")); + setOrganizationDomain(QLatin1String("leocad.org")); + setOrganizationName(QLatin1String("LeoCAD Software")); + setApplicationName(QLatin1String("LeoCAD")); + setApplicationVersion(QLatin1String(LC_VERSION_TEXT)); gApplication = this; - mProject = nullptr; - mLibrary = nullptr; mDefaultStyle = style()->objectName(); mPreferences.LoadDefaults(); - - UpdateStyle(); } lcApplication::~lcApplication() { - delete mProject; - delete mLibrary; gApplication = nullptr; } @@ -764,7 +758,10 @@ lcStartupMode lcApplication::Initialize(QList>& LibraryPath if (!SaveAndExit) { + UpdateStyle(); + gMainWindow = new lcMainWindow(); + lcLoadDefaultKeyboardShortcuts(); lcLoadDefaultMouseShortcuts(); } @@ -1063,9 +1060,11 @@ void lcApplication::Shutdown() bool lcApplication::InitializeRenderer(int AASamples) { - if (AASamples > 1) + QSurfaceFormat Format = QSurfaceFormat::defaultFormat(); + const int FormatSamples = Format.samples() > 1 ? Format.samples() : 1; + + if (AASamples != FormatSamples) { - QSurfaceFormat Format = QSurfaceFormat::defaultFormat(); Format.setSamples(AASamples); QSurfaceFormat::setDefaultFormat(Format); } diff --git a/common/lc_application.h b/common/lc_application.h index 320e3026..4d514354 100644 --- a/common/lc_application.h +++ b/common/lc_application.h @@ -98,8 +98,8 @@ public: void SetClipboard(const QByteArray& Clipboard); void ExportClipboard(const QByteArray& Clipboard); - Project* mProject; - lcPiecesLibrary* mLibrary; + Project* mProject = nullptr; + lcPiecesLibrary* mLibrary = nullptr; lcPreferences mPreferences; QByteArray mClipboard; diff --git a/qt/qtmain.cpp b/qt/qtmain.cpp index 0ecc90dc..c772225c 100644 --- a/qt/qtmain.cpp +++ b/qt/qtmain.cpp @@ -121,8 +121,23 @@ static void lcRegisterShellFileTypes() #endif +static void lcInitializeSurfaceFormat(int argc, char* argv[]) +{ + lcApplication Application(argc, argv); + const int AASamples = lcGetProfileInt(LC_PROFILE_ANTIALIASING_SAMPLES); + + if (AASamples > 1) + { + QSurfaceFormat Format = QSurfaceFormat::defaultFormat(); + Format.setSamples(AASamples); + QSurfaceFormat::setDefaultFormat(Format); + } +} + int main(int argc, char *argv[]) { + lcInitializeSurfaceFormat(argc, argv); + QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts); lcApplication Application(argc, argv); @@ -181,7 +196,10 @@ int main(int argc, char *argv[]) lcStartupMode StartupMode = Application.Initialize(LibraryPaths); if (StartupMode == lcStartupMode::Error) + { + Application.Shutdown(); return 1; + } int ExecReturn = 0;