Restore correct handling of wxDocument::OnCreate() error return value.

The changes of r74515 didn't quite restore the old behaviour, the document was
still not being cleaned up if its OnCreate() simply returned false and not
threw an exception.

Do add cleanup in this code branch too, just duplicating what we in case of
exception (this duplication can't be easily avoided unfortunately).

Closes #15883.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@75646 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin 2014-01-19 13:15:43 +00:00
parent fe67b68d7a
commit 8aed772f6c

View File

@ -857,11 +857,6 @@ wxDocument *wxDocTemplate::CreateDocument(const wxString& path, long flags)
bool
wxDocTemplate::InitDocument(wxDocument* doc, const wxString& path, long flags)
{
// Normally, if wxDocument::OnCreate() fails, it happens because the view
// initialization fails and then the document is destroyed due to the
// destruction of its last view. But take into account the (currently
// unrealized, AFAICS) possibility of other failures as well and ensure
// that the document is always destroyed if it can't be initialized.
wxTRY
{
doc->SetFilename(path);
@ -869,7 +864,19 @@ wxDocTemplate::InitDocument(wxDocument* doc, const wxString& path, long flags)
GetDocumentManager()->AddDocument(doc);
doc->SetCommandProcessor(doc->OnCreateCommandProcessor());
return doc->OnCreate(path, flags);
if ( doc->OnCreate(path, flags) )
return true;
// The document may be already destroyed, this happens if its view
// creation fails as then the view being created is destroyed
// triggering the destruction of the document as this first view is
// also the last one. However if OnCreate() fails for any reason other
// than view creation failure, the document is still alive and we need
// to clean it up ourselves to avoid having a zombie document.
if ( GetDocumentManager()->GetDocuments().Member(doc) )
doc->DeleteAllViews();
return false;
}
wxCATCH_ALL(
if ( GetDocumentManager()->GetDocuments().Member(doc) )