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:
02a2f1f933
This commit is contained in:
David Capello 2022-07-16 13:14:24 -03:00
parent f4e83371b8
commit 4389788a1d

View File

@ -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);