Fix crash using Sprite:close() Lua API on modified sprites (fix #2142)

This commit is contained in:
David Capello 2019-08-30 17:17:58 -03:00
parent 23b6e1d118
commit eb2e0e52dc
2 changed files with 14 additions and 2 deletions

View File

@ -98,10 +98,16 @@ void BackupObserver::onRemoveDocument(Doc* doc)
base::remove_from_container(m_documents, doc);
}
if (m_config->keepEditedSpriteDataFor > 0 &&
doc->needsBackup())
doc->needsBackup() &&
// If the backup is disabled, we don't need it (e.g. when the
// document is destroyed from a script with Sprite:close(), the
// backup is disabled)
!doc->inhibitBackup()) {
m_closedDocs.push_back(doc);
else
}
else {
m_session->removeDocument(doc);
}
}
void BackupObserver::backgroundThread()

View File

@ -184,6 +184,12 @@ namespace app {
void destroyDocument() {
ASSERT(m_doc != nullptr);
// Don't create a backup for destroyed documents (e.g. documents
// are destroyed when they are used internally by Aseprite or by
// a script and then closed with Sprite:close())
if (m_doc->needsBackup())
m_doc->setInhibitBackup(true);
m_doc->close();
Doc* doc = m_doc;
unlock();