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

Defer initialization until app enters foreground #1821

Merged
merged 1 commit into from
Jul 8, 2015
Merged

Conversation

1ec5
Copy link
Contributor

@1ec5 1ec5 commented Jul 2, 2015

Another speculative fix for #1460, since #1805 didn’t quite do the trick. If MGLMapView is initialized while the app is in the background, defer the nitty-gritty details of initialization (particularly setting up the GL context and GL subview, but also things like events and background snapshotting) until the app enters the foreground for the first time.

This fix assumes that the developer won’t be doing things like switching styles or setting the global access token while the app is still in the background. Correctly handling such cases would require checking for the presence of a map at all times and queueing up changes to map view properties until the app enters the foreground.

Areas to test include backgrounding and foregrounding the app, launching the app via a URL handler, and switching between view controllers that do or do not contain an MGLMapView.

/cc @incanus @friedbunny

@1ec5 1ec5 added iOS Mapbox Maps SDK for iOS crash in progress labels Jul 2, 2015
@friedbunny
Copy link
Contributor

Looking good. :fingerscrossed:

@1ec5
Copy link
Contributor Author

1ec5 commented Jul 2, 2015

To be honest, I’m not entirely sold on this approach yet, because the developer still needs to take care to avoid touching the MGLMapView in any way before the app enters the foreground. It’s important to avoid accessing the mbgl::Map, which hasn’t been created yet because we can’t create the GL context.

@1ec5 1ec5 added the ⚠️ DO NOT MERGE Work in progress, proof of concept, or on hold label Jul 2, 2015
@1ec5 1ec5 changed the title Defer initialization until app enters foreground [WIP] Defer initialization until app enters foreground Jul 2, 2015
@1ec5
Copy link
Contributor Author

1ec5 commented Jul 5, 2015

c1d6239665d8fdb62c7b437f808298436e7a6c38 addresses the misgivings I had in #1821 (comment). After some testing, I think this change will be ready to go in.

@1ec5
Copy link
Contributor Author

1ec5 commented Jul 6, 2015

If for whatever reason the app goes to the foreground after launching in the background, the MGLMapView will continue to be functional. If I force that code path, the only difference I see is this message in the console, which seems benign:

2015-07-06 10:28:43.934 Mapbox GL[5010:736058] [WARNING] {Map}[OpenGL]: Not using Vertex Array Objects

@incanus incanus modified the milestone: iOS Beta 3 Jul 7, 2015
@1ec5
Copy link
Contributor Author

1ec5 commented Jul 7, 2015

@1ec5
Copy link
Contributor Author

1ec5 commented Jul 8, 2015

Given that GLKView still appears on the stack, the issue must be that the app becomes “active” in the background, triggering a UIApplicationWillEnterForegroundNotification that this branch currently responds to by setting up the OpenGL ES context. caf874f9e6b1763fdfae6b441af71b1bf1361c9c would address that issue.

Defer the creation of EAGLEContext and GLKView and the loading of OpenGL ES extensions. It is GLKView that drives the background crash, and Apple documentation specifically warns not to initialize an EAGLContext in the background. All the while, it should be safe for client code to avail itself of any public methods on MGLMapView.

Fixes #1460.
@1ec5 1ec5 force-pushed the 1ec5-defer-init-1460 branch from caf874f to 1a3ae88 Compare July 8, 2015 21:53
@1ec5 1ec5 merged commit 1a3ae88 into master Jul 8, 2015
@1ec5 1ec5 removed the in progress label Jul 8, 2015
@1ec5 1ec5 deleted the 1ec5-defer-init-1460 branch July 8, 2015 22:36
@1ec5 1ec5 changed the title [WIP] Defer initialization until app enters foreground Defer initialization until app enters foreground Jul 8, 2015
@1ec5 1ec5 removed the ⚠️ DO NOT MERGE Work in progress, proof of concept, or on hold label Jul 8, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
crash iOS Mapbox Maps SDK for iOS
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants