diff --git a/modules/juce_gui_basics/misc/juce_DropShadower.cpp b/modules/juce_gui_basics/misc/juce_DropShadower.cpp index df5a1bb811..d431a033bb 100644 --- a/modules/juce_gui_basics/misc/juce_DropShadower.cpp +++ b/modules/juce_gui_basics/misc/juce_DropShadower.cpp @@ -131,17 +131,25 @@ private: //============================================================================== void update() { - const auto newHasReasonToHide = [this]() - { - if (! component.wasObjectDeleted() && isWindows && component->isOnDesktop()) - { - startTimerHz (5); - return ! detail::WindowingHelpers::isWindowOnCurrentVirtualDesktop (component->getWindowHandle()); - } + bool newHasReasonToHide = false; + if (! component.wasObjectDeleted() && isWindows && component->isOnDesktop()) + { + startTimerHz (5); + + WeakReference weakThis (this); + + // During scaling changes this call can trigger a call to HWNDComponentPeer::handleDPIChanging() + // which deletes this VirtualDesktopWatcher. + newHasReasonToHide = ! detail::WindowingHelpers::isWindowOnCurrentVirtualDesktop (component->getWindowHandle()); + + if (weakThis == nullptr) + return; + } + else + { stopTimer(); - return false; - }(); + } if (std::exchange (hasReasonToHide, newHasReasonToHide) != newHasReasonToHide) for (auto& l : listeners) @@ -158,6 +166,8 @@ private: const bool isWindows = (SystemStats::getOperatingSystemType() & SystemStats::Windows) != 0; bool hasReasonToHide = false; std::map> listeners; + + JUCE_DECLARE_WEAK_REFERENCEABLE (VirtualDesktopWatcher) }; class DropShadower::ParentVisibilityChangedListener : public ComponentListener