Skip to content

Commit

Permalink
Fix crash when performing undo/redo on deleted object
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Vankata453 committed Oct 21, 2024
1 parent f65b0c3 commit 7c4a0f7
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/supertux/game_object_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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)
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand Down

0 comments on commit 7c4a0f7

Please sign in to comment.