Opened 3 months ago

Closed 3 months ago

Last modified 12 days ago

#15883 closed defect (fixed)

wxDocument::OnCreate returning false no longer deletes document or removes it from the doc manager

Reported by: snowleopard2 Owned by: vadz
Priority: normal Milestone:
Component: base Version: stable-latest
Keywords: wxDocument, wxDocManager Cc:
Blocked By: Blocking:
Patch: no

Description

In 2.9.4 and before, if wxDocument::OnCreate returned false, then wxDocTemplate::InitDocument would call DeleteAllViews on the document, which in turn would delete it and remove it from the doc manager. This was done via a scope guard that would call DeleteAllViews if OnCreate returned false.

However, after 2.9.4 this scope guard in wxDocTemplate::InitDocument was removed and now DeleteAllViews is only called if OnCreate throws an exception (handled in a catch block). It's good that it handles exceptions now (didn't before), but if OnCreate returns false then the document is never destroyed and it this half-created document remains lingering in the doc manager's document collection.

I'm thinking wxDocTemplate::InitDocument should check OnCreate's return first and call DeleteAllViews if false before returning OnCreate's return value.

Change History (4)

comment:1 Changed 3 months ago by vadz

  • Owner set to vadz
  • Status changed from new to accepted

comment:2 Changed 3 months ago by VZ

  • Resolution set to fixed
  • Status changed from accepted to closed

(In [75646]) 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.

comment:3 Changed 2 weeks ago by snowleopard2

Anyway that this could be backported into the 3.0 branch? Thanks if possible.

comment:4 Changed 12 days ago by VZ

In 76315:

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).

This backports changes of r75646 from trunk, see #15883.

Note: See TracTickets for help on using tickets.