Skip to content

Commit

Permalink
Crash on exit fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
Greg Williamson committed Sep 19, 2021
1 parent 085981a commit 4abfe52
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 21 deletions.
2 changes: 1 addition & 1 deletion Dialogs/EventArgumentsDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions Editors/RoomEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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();
Expand Down
24 changes: 13 additions & 11 deletions MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ QList<QString> MainWindow::EnigmaSearchPaths = {QDir::currentPath(), "./enigma-d
QFileInfo MainWindow::EnigmaRoot = MainWindow::getEnigmaRoot();
QList<buffers::SystemType> MainWindow::systemCache;
MainWindow *MainWindow::_instance = nullptr;
QScopedPointer<ResourceModelMap> MainWindow::resourceMap;
QScopedPointer<TreeModel> MainWindow::treeModel;
ResourceModelMap *MainWindow::resourceMap = nullptr;
TreeModel *MainWindow::treeModel = nullptr;
std::unique_ptr<EventData> MainWindow::_event_data;

static QTextEdit *diagnosticTextEdit = nullptr;
Expand Down Expand Up @@ -412,7 +412,8 @@ void MainWindow::openProject(std::unique_ptr<buffers::Project> openedProject) {
treeConf.SetMessagePassthrough<buffers::TreeNode::Folder>();
treeConf.DisableOneofReassignment<buffers::TreeNode>();

resourceMap.reset(new ResourceModelMap(this));
delete resourceMap;
resourceMap = new ResourceModelMap(this);

auto pm = new MessageModel(ProtoModel::NonProtoParent{this}, _project->mutable_game()->mutable_root());

Expand All @@ -422,7 +423,7 @@ void MainWindow::openProject(std::unique_ptr<buffers::Project> 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<const std::string &, const QString &, const QString &>(&ResourceModelMap::ResourceRenamed),
primitive_model,
[primitive_model](const std::string &type, const QString &newValue, const QString &oldValue) {
Expand All @@ -437,17 +438,18 @@ void MainWindow::openProject(std::unique_ptr<buffers::Project> 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<buffers::TreeNode::TypeCase, const QString &, const QString &>(&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);
}

Expand Down
6 changes: 3 additions & 3 deletions MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ class MainWindow : public QMainWindow {
Q_OBJECT

public:
static QScopedPointer<ResourceModelMap> resourceMap;
static QScopedPointer<MessageModel> resourceModel;
static QScopedPointer<TreeModel> treeModel;
static ResourceModelMap* resourceMap;
static MessageModel* resourceModel;
static TreeModel* treeModel;
static QList<buffers::SystemType> systemCache;

explicit MainWindow(QWidget *parent);
Expand Down
4 changes: 2 additions & 2 deletions Widgets/AssetScrollAreaBackground.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion Widgets/ResourceSelector.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 4abfe52

Please sign in to comment.