From 3972983c729a6d4f467afc5cb983424474f08616 Mon Sep 17 00:00:00 2001 From: fgenesis Date: Thu, 26 Oct 2023 00:17:33 +0200 Subject: [PATCH] fix some editor crashes when switching edit modes while dragging a thing --- Aquaria/Game.h | 2 +- Aquaria/SceneEditor.cpp | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Aquaria/Game.h b/Aquaria/Game.h index 38d3c4b..6782622 100644 --- a/Aquaria/Game.h +++ b/Aquaria/Game.h @@ -251,7 +251,7 @@ public: void removePath(size_t idx); void clearPaths(); size_t getNumPaths() const {return paths.size();} - Path *getPath(size_t idx) const {return paths[idx];} + Path *getPath(size_t idx) const {return idx < paths.size() ? paths[idx] : NULL;} Path *getFirstPathOfType(PathType type) const {return firstPathOfType[type];} Path *getPathByName(std::string name); size_t getIndexOfPath(Path *p); diff --git a/Aquaria/SceneEditor.cpp b/Aquaria/SceneEditor.cpp index 8c7d295..a8aa78b 100644 --- a/Aquaria/SceneEditor.cpp +++ b/Aquaria/SceneEditor.cpp @@ -291,7 +291,7 @@ void SceneEditor::setBackgroundGradient() void SceneEditor::updateSelectedElementPosition(Vector dist) { - if (state == ES_MOVING) + if (state == ES_MOVING && multi) { // the actual tile position is updated when we release the mouse multi->position = oldPosition + dist; @@ -2621,7 +2621,10 @@ void SceneEditor::update(float dt) } break; case ES_MOVING: - game->getPath(selectedIdx)->nodes[selectedNode].position = dsq->getGameCursorPosition() + cursorOffset; + { + if(Path *p = game->getPath(selectedIdx)) + p->nodes[selectedNode].position = dsq->getGameCursorPosition() + cursorOffset; + } break; case ES_ROTATING: case ES_MAX: