Fix problem deleting app::Document that are inside a Context

This commit is contained in:
David Capello 2014-07-29 01:29:04 -03:00
parent 81ffb0c5bd
commit 03a085d1e5
2 changed files with 24 additions and 2 deletions

View File

@ -260,8 +260,23 @@ int App::run()
// Destroy all documents in the UIContext.
const doc::Documents& docs = m_modules->m_ui_context.documents();
while (!docs.empty())
delete docs.back();
while (!docs.empty()) {
doc::Document* doc = docs.back();
// First we close the document. In this way we receive recent
// notifications related to the document as an app::Document. If
// we delete the document directly, we destroy the app::Document
// too early, and then doc::~Document() call
// DocumentsObserver::onRemoveDocument(). In this way, observers
// could think that they have a fully created app::Document when
// in reality it's a doc::Document (in the middle of a
// destruction process).
//
// TODO: This problem is because we're extending doc::Document,
// in the future, we should remove app::Document.
doc->close();
delete doc;
}
// Destroy the window.
m_mainWindow.reset(NULL);

View File

@ -75,6 +75,13 @@ Document::Document(Sprite* sprite)
Document::~Document()
{
// We cannot be in a context at this moment. If we were in a
// context, doc::~Document() would remove the document from the
// context and it would generate onRemoveDocument() notifications,
// which could result in serious problems for observers expecting a
// fully created app::Document.
ASSERT(context() == NULL);
if (m_bound.seg)
base_free(m_bound.seg);