From e121e8addb22b0dd0f7e106ba89ae04c43850886 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 20 Jun 2017 15:32:00 +0200 Subject: [PATCH] Check for view presence in wxDocument::RemoveView() Return false and avoid calling OnChangedViewList() if the view wasn't present in the first place. This is not, strictly speaking, backwards compatible, but most of the existing code doesn't seem to check the return value of RemoveView() at all and it's hard to imagine that someone would rely on it returning true when removing a non-existent view, so in practice this changes seems to be safe. Closes #17888. --- interface/wx/docview.h | 8 ++++++-- src/common/docview.cpp | 4 +++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/interface/wx/docview.h b/interface/wx/docview.h index b4670d759d..ed74d5d320 100644 --- a/interface/wx/docview.h +++ b/interface/wx/docview.h @@ -1530,8 +1530,12 @@ public: virtual bool OnSaveModified(); /** - Removes the view from the document's list of views, and calls - OnChangedViewList(). + Removes the view from the document's list of views. + + If the view was really removed, also calls OnChangedViewList(). + + @return @true if the view was removed or @false if the document didn't + have this view in the first place. */ virtual bool RemoveView(wxView* view); diff --git a/src/common/docview.cpp b/src/common/docview.cpp index 176c53444c..5be66f1190 100644 --- a/src/common/docview.cpp +++ b/src/common/docview.cpp @@ -570,7 +570,9 @@ bool wxDocument::AddView(wxView *view) bool wxDocument::RemoveView(wxView *view) { - (void)m_documentViews.DeleteObject(view); + if ( !m_documentViews.DeleteObject(view) ) + return false; + OnChangedViewList(); return true; }