Don't call wxDocument::OnCloseDocument() twice when closing

When closing the document using wxDocManager::CloseDocument(), which is
what happens when using the standard wxID_CLOSE menu command handler,
OnCloseDocument() was called twice: first when wxDocument::Close() was
called directly from CloseDocument() itself and once again later when it
was implicitly called from DeleteAllViews().

This was unexpected and also resulted in calling DeleteContents() twice,
which is even more so for a function supposed to perform cleanup.

Fix this by not calling Close() itself but instead a new CanClose()
function from CloseDocument() to check whether we can close and then
relying on DeleteAllViews() to actually close the document.
This commit is contained in:
Vadim Zeitlin 2022-07-14 23:52:03 +01:00
parent 3e195db27e
commit ee6d58abe2
3 changed files with 25 additions and 5 deletions

View file

@ -11,6 +11,12 @@ INCOMPATIBLE CHANGES SINCE 3.2.x:
Changes in behaviour not resulting in compilation errors
--------------------------------------------------------
- wxDocument::OnCloseDocument() was called twice in previous versions when
closing the document from the menu. Now it is only called once and after
destroying all the existing document views. If you overrode this function,
please check that you don't rely on any views existing when it's called.
Changes in behaviour which may result in build errors
-----------------------------------------------------