From ad4368bbf185cc1a632a4556427b8271eebe01d3 Mon Sep 17 00:00:00 2001 From: reuk Date: Wed, 15 Dec 2021 16:43:03 +0000 Subject: [PATCH] UIViewComponentPeer: Clear focused peer on destruction to avoid dangling pointer --- .../juce_gui_basics/native/juce_ios_UIViewComponentPeer.mm | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/modules/juce_gui_basics/native/juce_ios_UIViewComponentPeer.mm b/modules/juce_gui_basics/native/juce_ios_UIViewComponentPeer.mm index d52eadaebc..c654296102 100644 --- a/modules/juce_gui_basics/native/juce_ios_UIViewComponentPeer.mm +++ b/modules/juce_gui_basics/native/juce_ios_UIViewComponentPeer.mm @@ -680,8 +680,13 @@ UIViewComponentPeer::UIViewComponentPeer (Component& comp, int windowStyleFlags, Desktop::getInstance().addFocusChangeListener (this); } +static UIViewComponentPeer* currentlyFocusedPeer = nullptr; + UIViewComponentPeer::~UIViewComponentPeer() { + if (currentlyFocusedPeer == this) + currentlyFocusedPeer = nullptr; + currentTouches.deleteAllTouchesForPeer (this); Desktop::getInstance().removeFocusChangeListener (this); @@ -1007,8 +1012,6 @@ void UIViewComponentPeer::onScroll (UIPanGestureRecognizer* gesture) #endif //============================================================================== -static UIViewComponentPeer* currentlyFocusedPeer = nullptr; - void UIViewComponentPeer::viewFocusGain() { if (currentlyFocusedPeer != this)