From 7c4a0f7abd76b316a95026dd760f893c6fab832b Mon Sep 17 00:00:00 2001 From: Vankata453 <78196474+Vankata453@users.noreply.github.com> Date: Mon, 22 Jan 2024 20:47:02 +0200 Subject: [PATCH] Fix crash when performing undo/redo on deleted object Previously, an assertion was used for performing this check, which was the cause of the crash. It wasn't taken into account performing undo/redo on a remotely-deleted object. Additionally, the warning message now includes the class name of the object. --- src/supertux/game_object_manager.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/supertux/game_object_manager.cpp b/src/supertux/game_object_manager.cpp index 8c170d77cf..64245f867b 100644 --- a/src/supertux/game_object_manager.cpp +++ b/src/supertux/game_object_manager.cpp @@ -394,7 +394,7 @@ GameObjectManager::apply_object_change(const GameObjectChange& change, bool trac case GameObjectChange::Action::DELETE: { if (!object) - throw std::runtime_error("Object does not exist."); + throw std::runtime_error("Object '" + change.name + "' does not exist."); object->m_track_undo = track_undo; object->remove_me(); @@ -404,7 +404,7 @@ GameObjectManager::apply_object_change(const GameObjectChange& change, bool trac case GameObjectChange::Action::MODIFY: { if (!object) - throw std::runtime_error("Object does not exist."); + throw std::runtime_error("Object '" + change.name + "' does not exist."); auto settings = object->get_settings(); if (track_undo) @@ -544,7 +544,8 @@ GameObjectManager::process_object_change(GameObjectChange& change) { case GameObjectChange::Action::CREATE: /** Object was added, remove it. */ { - assert(object); + if (!object) + throw std::runtime_error("Object '" + change.name + "' no longer exists."); object->m_track_undo = false; object->remove_me(); @@ -566,7 +567,8 @@ GameObjectManager::process_object_change(GameObjectChange& change) case GameObjectChange::Action::MODIFY: /** Object was modified, revert settings. */ { - assert(object); + if (!object) + throw std::runtime_error("Object '" + change.name + "' no longer exists."); auto settings = object->get_settings(); settings.save_state();