Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

fix lingering backgrounding crashes & add debug mode #1451

Merged
merged 1 commit into from
May 6, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 45 additions & 18 deletions platform/ios/MGLMapView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ @interface MGLMapView () <UIGestureRecognizerDelegate, GLKViewDelegate, CLLocati
@property (nonatomic) CGFloat scale;
@property (nonatomic) CGFloat angle;
@property (nonatomic) CGFloat quickZoomStart;
@property (nonatomic, getter=isDormant) BOOL dormant;
@property (nonatomic, getter=isAnimatingGesture) BOOL animatingGesture;
@property (nonatomic, readonly, getter=isRotationAllowed) BOOL rotationAllowed;

Expand Down Expand Up @@ -361,8 +362,10 @@ - (BOOL)commonInit

// observe app activity
//
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appDidBackground:) name:UIApplicationDidEnterBackgroundNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appWillForeground:) name:UIApplicationWillEnterForegroundNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(sleepGL:) name:UIApplicationWillResignActiveNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(sleepGL:) name:UIApplicationDidEnterBackgroundNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(wakeGL:) name:UIApplicationWillEnterForegroundNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(wakeGL:) name:UIApplicationDidBecomeActiveNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didReceiveMemoryWarning) name:UIApplicationDidReceiveMemoryWarningNotification object:nil];

// set initial position
Expand Down Expand Up @@ -613,7 +616,7 @@ - (void)updateConstraints
// This is the delegate of the GLKView object's display call.
- (void)glkView:(GLKView *)view drawInRect:(CGRect)rect
{
if ( ! self.glSnapshotView || self.glSnapshotView.hidden)
if ( ! self.isDormant)
{
[self notifyMapChange:@(mbgl::MapChangeWillStartRenderingMap)];

Expand Down Expand Up @@ -651,32 +654,56 @@ - (void)layoutSubviews
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-parameter"

- (void)appDidBackground:(NSNotification *)notification
- (void)sleepGL:(NSNotification *)notification
{
[MGLMapboxEvents flush];
MGLAssertIsMainThread();

if ( ! self.glSnapshotView)
if ( ! self.isDormant)
{
self.glSnapshotView = [[UIImageView alloc] initWithFrame:self.glView.frame];
self.glSnapshotView.autoresizingMask = self.glView.autoresizingMask;
[self insertSubview:self.glSnapshotView aboveSubview:self.glView];
}
self.dormant = YES;

[MGLMapboxEvents flush];

if ( ! self.glSnapshotView)
{
self.glSnapshotView = [[UIImageView alloc] initWithFrame:self.glView.frame];
self.glSnapshotView.autoresizingMask = self.glView.autoresizingMask;
[self insertSubview:self.glSnapshotView aboveSubview:self.glView];
}

self.glSnapshotView.image = self.glView.snapshot;
self.glSnapshotView.hidden = NO;
self.glSnapshotView.image = self.glView.snapshot;
self.glSnapshotView.hidden = NO;

if (_mbglMap->getDebug() && [self.glSnapshotView.subviews count] == 0)
{
UIView *snapshotTint = [[UIView alloc] initWithFrame:self.glSnapshotView.bounds];
snapshotTint.autoresizingMask = self.glSnapshotView.autoresizingMask;
snapshotTint.backgroundColor = [[UIColor redColor] colorWithAlphaComponent:0.25];
[self.glSnapshotView addSubview:snapshotTint];
}

_mbglMap->pause();
_mbglMap->pause();

[self.glView deleteDrawable];
[self.glView deleteDrawable];
}
}

- (void)appWillForeground:(NSNotification *)notification
- (void)wakeGL:(NSNotification *)notification
{
self.glSnapshotView.hidden = YES;
MGLAssertIsMainThread();

if (self.isDormant)
{
self.dormant = NO;

self.glSnapshotView.hidden = YES;

[self.glView bindDrawable];
[self.glSnapshotView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];

_mbglMap->resume();
[self.glView bindDrawable];

_mbglMap->resume();
}
}

- (void)tintColorDidChange
Expand Down