diff --git a/modules/juce_gui_basics/layout/juce_Viewport.cpp b/modules/juce_gui_basics/layout/juce_Viewport.cpp index 7d0e491240..b6ac2ca979 100644 --- a/modules/juce_gui_basics/layout/juce_Viewport.cpp +++ b/modules/juce_gui_basics/layout/juce_Viewport.cpp @@ -54,7 +54,7 @@ Viewport::Viewport (const String& name) Viewport::~Viewport() { - deleteContentComp(); + deleteOrRemoveContentComp(); } //============================================================================== @@ -62,20 +62,24 @@ void Viewport::visibleAreaChanged (const Rectangle&) {} void Viewport::viewedComponentChanged (Component*) {} //============================================================================== -void Viewport::deleteContentComp() +void Viewport::deleteOrRemoveContentComp() { if (contentComp != nullptr) + { contentComp->removeComponentListener (this); - if (deleteContent) - { - // This sets the content comp to a null pointer before deleting the old one, in case - // anything tries to use the old one while it's in mid-deletion.. - ScopedPointer oldCompDeleter (contentComp); - } - else - { - contentComp = nullptr; + if (deleteContent) + { + // This sets the content comp to a null pointer before deleting the old one, in case + // anything tries to use the old one while it's in mid-deletion.. + ScopedPointer oldCompDeleter (contentComp); + contentComp = nullptr; + } + else + { + contentHolder.removeChildComponent (contentComp); + contentComp = nullptr; + } } } @@ -83,7 +87,7 @@ void Viewport::setViewedComponent (Component* const newViewedComponent, const bo { if (contentComp.get() != newViewedComponent) { - deleteContentComp(); + deleteOrRemoveContentComp(); contentComp = newViewedComponent; deleteContent = deleteComponentWhenNoLongerNeeded; diff --git a/modules/juce_gui_basics/layout/juce_Viewport.h b/modules/juce_gui_basics/layout/juce_Viewport.h index 9873c4cc5c..50b01c43bd 100644 --- a/modules/juce_gui_basics/layout/juce_Viewport.h +++ b/modules/juce_gui_basics/layout/juce_Viewport.h @@ -274,7 +274,7 @@ private: Point viewportPosToCompPos (Point) const; void updateVisibleArea(); - void deleteContentComp(); + void deleteOrRemoveContentComp(); #if JUCE_CATCH_DEPRECATED_CODE_MISUSE // If you get an error here, it's because this method's parameters have changed! See the new definition above..