From de7cd7bad4ecba7cc221690514361f12241a3cfd Mon Sep 17 00:00:00 2001 From: Greg Williamson Date: Sat, 18 Sep 2021 20:21:46 -0400 Subject: [PATCH] Crash on exit fixup --- Dialogs/EventArgumentsDialog.cpp | 2 +- Editors/RoomEditor.cpp | 4 ++-- MainWindow.cpp | 24 +++++++++++++----------- MainWindow.h | 6 +++--- Submodules/enigma-dev | 2 +- Widgets/AssetScrollAreaBackground.cpp | 4 ++-- Widgets/ResourceSelector.h | 2 +- 7 files changed, 23 insertions(+), 21 deletions(-) diff --git a/Dialogs/EventArgumentsDialog.cpp b/Dialogs/EventArgumentsDialog.cpp index 838ba6953..b612be73c 100644 --- a/Dialogs/EventArgumentsDialog.cpp +++ b/Dialogs/EventArgumentsDialog.cpp @@ -40,7 +40,7 @@ EventArgumentsDialog::EventArgumentsDialog(QWidget *parent, const QStringList &a QMenuView *objMenu = new QMenuView(this); TreeSortFilterProxyModel *treeProxy = new TreeSortFilterProxyModel(this); treeProxy->SetFilterType(TreeNode::TypeCase::kObject); - treeProxy->setSourceModel(MainWindow::treeModel.get()); + treeProxy->setSourceModel(MainWindow::treeModel); objMenu->setModel(treeProxy); objButton->setMenu(objMenu); objButton->setPopupMode(QToolButton::MenuButtonPopup); diff --git a/Editors/RoomEditor.cpp b/Editors/RoomEditor.cpp index b094199e4..bf66a722c 100644 --- a/Editors/RoomEditor.cpp +++ b/Editors/RoomEditor.cpp @@ -62,7 +62,7 @@ RoomEditor::RoomEditor(MessageModel* model, QWidget* parent) : BaseEditor(model, QMenuView* objMenu = new QMenuView(this); TreeSortFilterProxyModel* treeProxy = new TreeSortFilterProxyModel(this); treeProxy->SetFilterType(TreeNode::TypeCase::kObject); - treeProxy->setSourceModel(MainWindow::treeModel.get()); + treeProxy->setSourceModel(MainWindow::treeModel); objMenu->setModel(treeProxy); _ui->objectSelectButton->setMenu(objMenu); @@ -82,7 +82,7 @@ RoomEditor::RoomEditor(MessageModel* model, QWidget* parent) : BaseEditor(model, _ui->statusBar->addWidget(_assetNameLabel); // This updates all the model views in the event of a sprite is changed - connect(MainWindow::resourceMap.get(), &ResourceModelMap::DataChanged, this, [this]() { + connect(MainWindow::resourceMap, &ResourceModelMap::DataChanged, this, [this]() { _ui->instancesListView->reset(); _ui->tilesListView->reset(); _ui->layersPropertiesView->reset(); diff --git a/MainWindow.cpp b/MainWindow.cpp index 6dafe91f2..76318b656 100644 --- a/MainWindow.cpp +++ b/MainWindow.cpp @@ -40,8 +40,8 @@ QList MainWindow::EnigmaSearchPaths = {QDir::currentPath(), "./enigma-d QFileInfo MainWindow::EnigmaRoot = MainWindow::getEnigmaRoot(); QList MainWindow::systemCache; MainWindow *MainWindow::_instance = nullptr; -QScopedPointer MainWindow::resourceMap; -QScopedPointer MainWindow::treeModel; +ResourceModelMap *MainWindow::resourceMap = nullptr; +TreeModel *MainWindow::treeModel = nullptr; std::unique_ptr MainWindow::_event_data; static QTextEdit *diagnosticTextEdit = nullptr; @@ -412,7 +412,8 @@ void MainWindow::openProject(std::unique_ptr openedProject) { treeConf.SetMessagePassthrough(); treeConf.DisableOneofReassignment(); - resourceMap.reset(new ResourceModelMap(this)); + delete resourceMap; + resourceMap = new ResourceModelMap(this); auto pm = new MessageModel(ProtoModel::NonProtoParent{this}, _project->mutable_game()->mutable_root()); @@ -422,7 +423,7 @@ void MainWindow::openProject(std::unique_ptr openedProject) { if (primitive_model) { const FieldDescriptor *const field = primitive_model->GetFieldDescriptor(); if (field && !field->options().GetExtension(buffers::resource_ref).empty()) - connect(resourceMap.get(), + connect(resourceMap, qOverload(&ResourceModelMap::ResourceRenamed), primitive_model, [primitive_model](const std::string &type, const QString &newValue, const QString &oldValue) { @@ -437,17 +438,18 @@ void MainWindow::openProject(std::unique_ptr openedProject) { pm->SetDisplayConfig(msgConf); resourceMap->TreeChanged(pm); - treeModel.reset(new TreeModel(pm, nullptr, treeConf)); + delete treeModel; + treeModel = new TreeModel(pm, nullptr, treeConf); - _ui->treeView->setModel(treeModel.get()); - connect(treeModel.get(), &TreeModel::ItemRenamed, resourceMap.get(), + _ui->treeView->setModel(treeModel); + connect(treeModel, &TreeModel::ItemRenamed, resourceMap, qOverload(&ResourceModelMap::ResourceRenamed)); - connect(treeModel.get(), &TreeModel::TreeChanged, resourceMap.get(), &ResourceModelMap::TreeChanged); - connect(treeModel.get(), &TreeModel::ItemRemoved, resourceMap.get(), &ResourceModelMap::ResourceRemoved, + connect(treeModel, &TreeModel::TreeChanged, resourceMap, &ResourceModelMap::TreeChanged); + connect(treeModel, &TreeModel::ItemRemoved, resourceMap, &ResourceModelMap::ResourceRemoved, Qt::DirectConnection); - connect(pm, &ProtoModel::dataChanged, resourceMap.get(), &ResourceModelMap::dataChanged, + connect(pm, &ProtoModel::dataChanged, resourceMap, &ResourceModelMap::dataChanged, Qt::DirectConnection); - connect(treeModel.get(), &TreeModel::ModelAboutToBeDeleted, this, &MainWindow::ResourceModelDeleted, + connect(treeModel, &TreeModel::ModelAboutToBeDeleted, this, &MainWindow::ResourceModelDeleted, Qt::DirectConnection); } diff --git a/MainWindow.h b/MainWindow.h index 345ae6f22..58ef30e0d 100644 --- a/MainWindow.h +++ b/MainWindow.h @@ -29,9 +29,9 @@ class MainWindow : public QMainWindow { Q_OBJECT public: - static QScopedPointer resourceMap; - static QScopedPointer resourceModel; - static QScopedPointer treeModel; + static ResourceModelMap* resourceMap; + static MessageModel* resourceModel; + static TreeModel* treeModel; static QList systemCache; explicit MainWindow(QWidget *parent); diff --git a/Submodules/enigma-dev b/Submodules/enigma-dev index d8d94f073..02265f0c0 160000 --- a/Submodules/enigma-dev +++ b/Submodules/enigma-dev @@ -1 +1 @@ -Subproject commit d8d94f0730b9b2a4acf4885cf5a97a1f8dedd52c +Subproject commit 02265f0c0208abe05bf07b6de0a80247df6687ad diff --git a/Widgets/AssetScrollAreaBackground.cpp b/Widgets/AssetScrollAreaBackground.cpp index 1b9958d68..e83311cd5 100644 --- a/Widgets/AssetScrollAreaBackground.cpp +++ b/Widgets/AssetScrollAreaBackground.cpp @@ -22,11 +22,11 @@ AssetScrollAreaBackground::AssetScrollAreaBackground(AssetScrollArea* parent) installEventFilter(this); setMouseTracking(true); // Redraw on an model changes - connect(MainWindow::resourceMap.get(), &ResourceModelMap::DataChanged, this, [this]() { this->update(); }); + connect(MainWindow::resourceMap, &ResourceModelMap::DataChanged, this, [this]() { this->update(); }); } AssetScrollAreaBackground::~AssetScrollAreaBackground() { - disconnect(MainWindow::resourceMap.get(), &ResourceModelMap::DataChanged, this, nullptr); + disconnect(MainWindow::resourceMap, &ResourceModelMap::DataChanged, this, nullptr); } void AssetScrollAreaBackground::SetAssetView(AssetView* asset) { diff --git a/Widgets/ResourceSelector.h b/Widgets/ResourceSelector.h index 11ad0494c..f617916e8 100644 --- a/Widgets/ResourceSelector.h +++ b/Widgets/ResourceSelector.h @@ -14,7 +14,7 @@ class ResourceSelector : public QToolButton { _menu = new QMenuView(this); _treeProxy = new TreeSortFilterProxyModel(this); _treeProxy->SetFilterType(type); - _treeProxy->setSourceModel(MainWindow::treeModel.get()); + _treeProxy->setSourceModel(MainWindow::treeModel); _menu->setModel(_treeProxy); setMenu(_menu); }