From 4389788a1d08cc8945c6b6739b93e6affa8039b5 Mon Sep 17 00:00:00 2001 From: David Capello Date: Sat, 16 Jul 2022 13:14:24 -0300 Subject: [PATCH] The document associated w/SpriteEvents can be nullptr in special cases SpriteEvents can be re-created just when we're closing the sprite if we access Sprite.events property in app 'sitechange' event. When this second instance of SpriteEvents is deleted after the sprite was closed, the document cannot be found (as it was already destroyed). Associated test: https://github.com/aseprite/tests/commit/02a2f1f933e2b8d830cc8c6d91eba399ebe62498 --- src/app/script/events_class.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/app/script/events_class.cpp b/src/app/script/events_class.cpp index e070d61e9..c44b4fc4a 100644 --- a/src/app/script/events_class.cpp +++ b/src/app/script/events_class.cpp @@ -202,7 +202,12 @@ public: ~SpriteEvents() { auto doc = this->doc(); - ASSERT(doc || ui::get_app_state() == ui::AppState::kClosingWithException); + // The document can be nullptr in some cases like: + // - When closing the App with an exception + // (ui::get_app_state() == ui::AppState::kClosingWithException) + // - When Sprite.events property was accessed in a app + // "sitechange" event just when this same sprite was closed + // (so the SpriteEvents is created/destroyed for second time) if (doc) { disconnectFromUndoHistory(doc); doc->remove_observer(this);