mapbox-gl-native icon indicating copy to clipboard operation
mapbox-gl-native copied to clipboard

Multiple Maps EXEC_BAD_ACCESS TransformState::getLatLng()

Open jonathanduty opened this issue 11 years ago • 16 comments

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 ()

jonathanduty avatar Mar 25 '15 19:03 jonathanduty

[MGLMapView trackGestureEvent:forRecognizer:]

@bleege want to investigate?

incanus avatar Mar 25 '15 19:03 incanus

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.

jonathanduty avatar Mar 25 '15 20:03 jonathanduty

This may be related to #1109.

bleege avatar Mar 26 '15 03:03 bleege

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 avatar Mar 26 '15 06:03 friedbunny

@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.

bleege avatar Mar 26 '15 15:03 bleege

@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.

incanus avatar Mar 26 '15 17:03 incanus

@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 avatar Mar 26 '15 17:03 incanus

@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.

  1. 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.
  2. 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.

jonathanduty avatar Mar 26 '15 17:03 jonathanduty

Any workarounds for this until it can be fixed? This one hurts after adding a second map to my app. Thanks!

picciano avatar Apr 15 '15 16:04 picciano

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.

mb12 avatar Apr 15 '15 16:04 mb12

That did the trick. Thanks.

picciano avatar Apr 15 '15 17:04 picciano

Can someone explain me how to share the map between views? The map returns nil for me by singleton instance.

crazyBoat avatar Apr 25 '15 20:04 crazyBoat

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 view property 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.

incanus avatar Apr 29 '15 21:04 incanus

Simple use case showing problems with 2+ map views:

https://github.com/incanus/PushTest

ios simulator screen shot apr 29 2015 5 23 42 pm

incanus avatar Apr 29 '15 21:04 incanus

Related: https://github.com/mapbox/mapbox-gl-native/issues/1102

incanus avatar Apr 29 '15 21:04 incanus

Above 858bb5d seems to solve this simply. Currently piggybacking a solution to #1102 on top of it now.

incanus avatar Apr 30 '15 19:04 incanus