mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-02-01 03:10:06 +00:00
iOS: Fixed a crash due to a dangling JuceUIViewController when updating screen bounds
This commit is contained in:
parent
9f9d4de77d
commit
11c2ca10fd
1 changed files with 39 additions and 1 deletions
|
|
@ -101,6 +101,23 @@ namespace Orientations
|
|||
}
|
||||
}
|
||||
|
||||
struct AsyncBoundsUpdater : public AsyncUpdater
|
||||
{
|
||||
AsyncBoundsUpdater (UIViewController* vc)
|
||||
: viewController (vc)
|
||||
{
|
||||
}
|
||||
|
||||
~AsyncBoundsUpdater() override
|
||||
{
|
||||
cancelPendingUpdate();
|
||||
}
|
||||
|
||||
void handleAsyncUpdate() override;
|
||||
|
||||
UIViewController* viewController;
|
||||
};
|
||||
|
||||
//==============================================================================
|
||||
} // namespace juce
|
||||
|
||||
|
|
@ -134,8 +151,12 @@ using namespace juce;
|
|||
//==============================================================================
|
||||
@interface JuceUIViewController : UIViewController
|
||||
{
|
||||
@public
|
||||
std::unique_ptr<AsyncBoundsUpdater> boundsUpdater;
|
||||
}
|
||||
|
||||
- (JuceUIViewController*) init;
|
||||
|
||||
- (NSUInteger) supportedInterfaceOrientations;
|
||||
- (BOOL) shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation) interfaceOrientation;
|
||||
- (void) willRotateToInterfaceOrientation: (UIInterfaceOrientation) toInterfaceOrientation duration: (NSTimeInterval) duration;
|
||||
|
|
@ -342,6 +363,11 @@ static void sendScreenBoundsUpdate (JuceUIViewController* c)
|
|||
juceView->owner->updateTransformAndScreenBounds();
|
||||
}
|
||||
|
||||
void AsyncBoundsUpdater::handleAsyncUpdate()
|
||||
{
|
||||
sendScreenBoundsUpdate ((JuceUIViewController*) viewController);
|
||||
}
|
||||
|
||||
static bool isKioskModeView (JuceUIViewController* c)
|
||||
{
|
||||
JuceUIView* juceView = (JuceUIView*) [c view];
|
||||
|
|
@ -358,6 +384,15 @@ MultiTouchMapper<UITouch*> UIViewComponentPeer::currentTouches;
|
|||
//==============================================================================
|
||||
@implementation JuceUIViewController
|
||||
|
||||
- (JuceUIViewController*) init
|
||||
{
|
||||
self = [super init];
|
||||
|
||||
boundsUpdater = std::make_unique<AsyncBoundsUpdater> (self);
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (NSUInteger) supportedInterfaceOrientations
|
||||
{
|
||||
return Orientations::getSupportedOrientations();
|
||||
|
|
@ -390,7 +425,8 @@ MultiTouchMapper<UITouch*> UIViewComponentPeer::currentTouches;
|
|||
|
||||
// On some devices the screen-size isn't yet updated at this point, so also trigger another
|
||||
// async update to double-check..
|
||||
MessageManager::callAsync ([=] { sendScreenBoundsUpdate (self); });
|
||||
if (boundsUpdater != nullptr)
|
||||
boundsUpdater->triggerAsyncUpdate();
|
||||
}
|
||||
|
||||
- (BOOL) prefersStatusBarHidden
|
||||
|
|
@ -629,6 +665,8 @@ UIViewComponentPeer::~UIViewComponentPeer()
|
|||
currentTouches.deleteAllTouchesForPeer (this);
|
||||
Desktop::getInstance().removeFocusChangeListener (this);
|
||||
|
||||
((JuceUIViewController*) controller)->boundsUpdater = nullptr;
|
||||
|
||||
view->owner = nullptr;
|
||||
[view removeFromSuperview];
|
||||
[view release];
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue