From cfea90e9d25c1b335c00df2eee54d1c295fa713d Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Sat, 16 Nov 2019 15:24:46 -1000 Subject: [PATCH] Segfault fixes --- .clang-format | 9 ++++ CMakeSettings.json | 54 +++++++++---------- externals/LibCommon | 2 +- src/Core/Tweaks/CTweakManager.cpp | 16 +++--- src/Editor/CProgressDialog.cpp | 6 +-- src/Editor/CProgressDialog.h | 4 +- .../CResourceTableContextMenu.cpp | 4 +- src/Editor/WorldEditor/CWorldEditor.cpp | 6 ++- 8 files changed, 55 insertions(+), 46 deletions(-) create mode 100644 .clang-format diff --git a/.clang-format b/.clang-format new file mode 100644 index 00000000..a37ce3d8 --- /dev/null +++ b/.clang-format @@ -0,0 +1,9 @@ +UseTab: Never +IndentWidth: 4 +BreakBeforeBraces: Allman +AllowShortIfStatementsOnASingleLine: false +IndentCaseLabels: false +ColumnLimit: 0 +DerivePointerAlignment: false +PointerAlignment: Left +AccessModifierOffset: -4 \ No newline at end of file diff --git a/CMakeSettings.json b/CMakeSettings.json index 358e8099..0b207ecd 100644 --- a/CMakeSettings.json +++ b/CMakeSettings.json @@ -1,30 +1,28 @@ { - "configurations": [ - { - "name": "x64-Debug", - "generator": "Ninja", - "configurationType": "Debug", - "inheritEnvironments": [ - "msvc_x64_x64" - ], - "buildRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\build\\${name}", - "installRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\install\\${name}", - "cmakeCommandArgs": "-DCMAKE_PREFIX_PATH=C:/Qt/5.12.3/msvc2017_64/lib/cmake/Qt5", - "buildCommandArgs": "-v", - "ctestCommandArgs": "" - }, - { - "name": "x64-Release", - "generator": "Ninja", - "configurationType": "RelWithDebInfo", - "inheritEnvironments": [ - "msvc_x64_x64" - ], - "buildRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\build\\${name}", - "installRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\install\\${name}", - "cmakeCommandArgs": "-DCMAKE_PREFIX_PATH=C:/Qt/5.12.3/msvc2017_64/lib/cmake/Qt5", - "buildCommandArgs": "-v", - "ctestCommandArgs": "" - } - ] + "configurations": [ + { + "name": "x64-Debug", + "generator": "Ninja", + "configurationType": "Debug", + "inheritEnvironments": [ "msvc_x64_x64" ], + "buildRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\build\\${name}", + "installRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\install\\${name}", + "cmakeCommandArgs": "-DCMAKE_PREFIX_PATH=C:/Qt/5.12.6/msvc2017_64/lib/cmake/Qt5", + "buildCommandArgs": "", + "ctestCommandArgs": "", + "variables": [] + }, + { + "name": "x64-Release", + "generator": "Ninja", + "configurationType": "RelWithDebInfo", + "inheritEnvironments": [ "msvc_x64_x64" ], + "buildRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\build\\${name}", + "installRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\install\\${name}", + "cmakeCommandArgs": "-DCMAKE_PREFIX_PATH=C:/Qt/5.12.6/msvc2017_64/lib/cmake/Qt5", + "buildCommandArgs": "", + "ctestCommandArgs": "", + "variables": [] + } + ] } \ No newline at end of file diff --git a/externals/LibCommon b/externals/LibCommon index 83934320..9ee4e6ac 160000 --- a/externals/LibCommon +++ b/externals/LibCommon @@ -1 +1 @@ -Subproject commit 8393432003b8e634cba4e89c27635fec0ae43a6f +Subproject commit 9ee4e6ac6cb1fa6b7db45099ae37026db2d2c49c diff --git a/src/Core/Tweaks/CTweakManager.cpp b/src/Core/Tweaks/CTweakManager.cpp index eedb7221..5d65ba06 100644 --- a/src/Core/Tweaks/CTweakManager.cpp +++ b/src/Core/Tweaks/CTweakManager.cpp @@ -1,8 +1,8 @@ #include "CTweakManager.h" #include "Core/GameProject/CGameProject.h" #include "Core/GameProject/CResourceIterator.h" -#include "Core/Tweaks/CTweakLoader.h" #include "Core/Tweaks/CTweakCooker.h" +#include "Core/Tweaks/CTweakLoader.h" CTweakManager::CTweakManager(CGameProject* pInProject) : mpProject(pInProject) @@ -16,16 +16,18 @@ CTweakManager::~CTweakManager() void CTweakManager::LoadTweaks() { - ASSERT( mTweakObjects.empty() ); + ASSERT(mTweakObjects.empty()); // MP1 - Load all tweak assets into memory if (mpProject->Game() <= EGame::Prime) { for (TResourceIterator It(mpProject->ResourceStore()); It; ++It) { - CTweakData* pTweaks = (CTweakData*) It->Load(); - pTweaks->Lock(); - mTweakObjects.push_back(pTweaks); + if (CTweakData* pTweaks = (CTweakData*)It->Load()) + { + pTweaks->Lock(); + mTweakObjects.push_back(pTweaks); + } } } @@ -40,9 +42,7 @@ void CTweakManager::LoadTweaks() { // For Wii builds, there is another game-dependent subfolder. EGame Game = mpProject->Game(); - TString GameName = (Game == EGame::Prime ? "MP1" : - Game == EGame::Echoes ? "MP2" : - "MP3"); + TString GameName = (Game == EGame::Prime ? "MP1" : Game == EGame::Echoes ? "MP2" : "MP3"); mStandardFilePath = mpProject->DiscFilesystemRoot(false) / GameName / "Standard.ntwk"; // MP3 might actually be FrontEnd diff --git a/src/Editor/CProgressDialog.cpp b/src/Editor/CProgressDialog.cpp index dc0c0a14..8628c304 100644 --- a/src/Editor/CProgressDialog.cpp +++ b/src/Editor/CProgressDialog.cpp @@ -16,7 +16,7 @@ CProgressDialog::CProgressDialog(QString OperationName, bool UseBusyIndicator, b mpUI->ProgressBar->setMaximum(UseBusyIndicator ? 0 : 10000); setWindowTitle(OperationName); -#if WIN32 +#ifdef WIN32 QWinTaskbarButton *pButton = new QWinTaskbarButton(this); QWindow *pWindow = UICommon::FindWidgetWindowHandle( parentWidget() ); @@ -63,7 +63,7 @@ void CProgressDialog::closeEvent(QCloseEvent *pEvent) { pEvent->accept(); -#if WIN32 +#ifdef WIN32 if (mpTaskbarProgress) { mpTaskbarProgress->reset(); @@ -108,7 +108,7 @@ void CProgressDialog::UpdateUI(const QString& rkTaskDesc, const QString& rkStepD int ProgressValue = 10000 * ProgressPercent; mpUI->ProgressBar->setValue(ProgressValue); -#if WIN32 +#ifdef WIN32 if (mpTaskbarProgress) mpTaskbarProgress->setValue(ProgressValue); #endif diff --git a/src/Editor/CProgressDialog.h b/src/Editor/CProgressDialog.h index 9290d556..b639dafb 100644 --- a/src/Editor/CProgressDialog.h +++ b/src/Editor/CProgressDialog.h @@ -10,7 +10,7 @@ #include #include -#if WIN32 +#ifdef WIN32 #include #include #endif @@ -28,7 +28,7 @@ class CProgressDialog : public IProgressNotifierUI bool mFinished; bool mCanceled; -#if WIN32 +#ifdef WIN32 QWinTaskbarProgress *mpTaskbarProgress; #endif diff --git a/src/Editor/ResourceBrowser/CResourceTableContextMenu.cpp b/src/Editor/ResourceBrowser/CResourceTableContextMenu.cpp index 9d7a589b..bb78cd48 100644 --- a/src/Editor/ResourceBrowser/CResourceTableContextMenu.cpp +++ b/src/Editor/ResourceBrowser/CResourceTableContextMenu.cpp @@ -26,9 +26,9 @@ void CResourceTableContextMenu::InitMenu() if (mpClickedEntry) { - #if WIN32 + #ifdef WIN32 const QString kOpenInExplorerString = "Show in Explorer"; - #elif __APPLE__ + #elif defined(__APPLE__) const QString kOpenInExplorerString = "Show in Finder"; #else const QString kOpenInExplorerString = "Show in file manager"; diff --git a/src/Editor/WorldEditor/CWorldEditor.cpp b/src/Editor/WorldEditor/CWorldEditor.cpp index 41772277..93e19a88 100644 --- a/src/Editor/WorldEditor/CWorldEditor.cpp +++ b/src/Editor/WorldEditor/CWorldEditor.cpp @@ -222,7 +222,8 @@ CWorldEditor::~CWorldEditor() mScene.ClearScene(); mpArea = nullptr; mpWorld = nullptr; - gpResourceStore->DestroyUnreferencedResources(); // this should destroy the area! + if (gpResourceStore) + gpResourceStore->DestroyUnreferencedResources(); // this should destroy the area! delete mpScriptSidebar; // For some reason WCreateTab filters an event during the viewport's destructor delete ui; @@ -244,7 +245,8 @@ bool CWorldEditor::CloseWorld() mpArea = nullptr; mpWorld = nullptr; - gpResourceStore->DestroyUnreferencedResources(); // this should destroy the area! + if (gpResourceStore) + gpResourceStore->DestroyUnreferencedResources(); // this should destroy the area! UpdateWindowTitle(); ui->ActionSave->setEnabled(false);