Multiple Maps EXEC_BAD_ACCESS TransformState::getLatLng()
setup: I modified the left and right navbar buttons to either push a new MBXViewController or pop it using the UINavigationController. I wanted to test navigating from one map to another using push/pop UINavigation controller.
Steps: Open app. Let first map fully load. Hit right bar button to navigate to new map. Hit left button to navigate back to first map. Touch the screen, you get a EXEC_BAD_ACCESS
Thread 1Queue : com.apple.main-thread (serial)
#0 0x0018efb2 in mbgl::TransformState::getLatLng() const at /Users/jonathanduty/Development/mapbox/mapbox-gl-native/src/mbgl/map/transform_state.cpp:98
#1 0x0018f953 in mbgl::TransformState::latLngForPixel(mbgl::vec2<double>) const at /Users/jonathanduty/Development/mapbox/mapbox-gl-native/src/mbgl/map/transform_state.cpp:205
#2 0x00379bc0 in mbgl::Map::latLngForPixel(mbgl::vec2<double>) const at /Users/jonathanduty/Development/mapbox/mapbox-gl-native/include/mbgl/map/map.hpp:152
#3 0x00367971 in -[MGLMapView convertPoint:toCoordinateFromView:] at /Users/jonathanduty/Development/mapbox/mapbox-gl-native/platform/ios/MGLMapView.mm:1154
#4 0x00365d4b in -[MGLMapView trackGestureEvent:forRecognizer:] at /Users/jonathanduty/Development/mapbox/mapbox-gl-native/platform/ios/MGLMapView.mm:992
#5 0x0035f652 in -[MGLMapView handlePanGesture:] at /Users/jonathanduty/Development/mapbox/mapbox-gl-native/platform/ios/MGLMapView.mm:626
#6 0x01923287 in _UIGestureRecognizerSendActions ()
[MGLMapView trackGestureEvent:forRecognizer:]
@bleege want to investigate?
At first glance following variables are declared in global scope in MGLMapView:
mbgl::Map *mbglMap = nullptr; MBGLView *mbglView = nullptr; mbgl::SQLiteCache *mbglFileCache = nullptr; mbgl::DefaultFileSource *mbglFileSource = nullptr;
When the second MGLMapView is dealloced, they are set to null giving the first MGLMapView zombie pointers.
This may be related to #1109.
Got this just now on the latest master, including the #1112 merge (552522ea94d0297b7ad10d1923e9d3b9aa9b8482).
In [MGLMapView trackGestureEvent:forRecognizer:] at:
CGPoint ptInView = CGPointMake([recognizer locationInView:recognizer.view].x, [recognizer locationInView:recognizer.view].y);
@friedbunny good catch ^^. In the light of day that shouldn't be too surprising as it's doing math with UI objects. I'll move it outside the background thread.
@friedbunny @bleege The gesture tracking is unrelated to @jonathanduty's original report, which is about 2+ maps in an app and global variable naming collision. Gesture discussion over in https://github.com/mapbox/mapbox-gl-native/issues/1116.
@jonathanduty Question here: is this two issues or one? i.e. having two maps in the same app, is the problem with view controllers related or another issue? If related to two maps, I think we can push this off of the b1 milestone, but if it's something else, we might want to address it sooner.
@incanus both of these are related to having 2 maps in the same app, however both do not need to be visible at the same time for either of these bugs to happen.
- One appears to be due to scope collision when a map is destroyed before the others. I think this is a bug with how the variables are defined in the mapview.
- the second occurs when you have multiple maps and try to scroll one of them. This appears to be an issue down the stack with how we are using sqlite.
Any workarounds for this until it can be fixed? This one hurts after adding a second map to my app. Thanks!
If you don't need to view two maps simultaneously, just change the style pointing to your new source/style. Basically never delete MGLMapView object and reuse it when switching UIViewControllers.
That did the trick. Thanks.
Can someone explain me how to share the map between views? The map returns nil for me by singleton instance.
To summarize the current status here:
- Workaround of moving map view between view controllers works if you don't need simultaneous visibility (i.e. don't need parent/child view controllers both with map views). @crazyBoat query a VC's
viewproperty or otherwise expose the map view in its public API for another VC to use. Not sure what you mean by a singleton — there is none such for map views. - We still need to fix the root case of not moving a view but having two views potentially overlapping lifetimes. Looking at this now.
Simple use case showing problems with 2+ map views:
https://github.com/incanus/PushTest

Related: https://github.com/mapbox/mapbox-gl-native/issues/1102
Above 858bb5d seems to solve this simply. Currently piggybacking a solution to #1102 on top of it now.