-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Defer initialization until app enters foreground #1821
Conversation
Looking good. :fingerscrossed: |
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. |
c1d6239665d8fdb62c7b437f808298436e7a6c38 addresses the misgivings I had in #1821 (comment). After some testing, I think this change will be ready to go in. |
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:
|
Given that |
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.
caf874f
to
1a3ae88
Compare
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 (
particularlysetting 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