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

Crash when mutating sources and layers that were added to a previously loaded style #8882

Open
boundsj opened this issue May 3, 2017 · 1 comment
Labels
Core The cross-platform C++ core, aka mbgl crash gl-ios iOS Mapbox Maps SDK for iOS runtime styling

Comments

@boundsj
Copy link
Contributor

boundsj commented May 3, 2017

Currently, it is possible to fall into the following trap:

  1. Create and display an MGLMapView in an application's UIViewController
  2. In -[MGLMapViewDelegate mapView:didFinishLoadingStyle:], create and add a shape source and layer
  3. Store a reference (i.e. property) to the added source in the app's view controller
  4. Sometime later, set a new style
  5. When the new style loads, attempt to mutate the shape of the shape source via the property reference

Because the source in the previous steps is tied to the previous style that is in the process of being replaced by the new style, the application will crash with traces that can change as a function of where the previous style unloading process is and the state of the mbgl::style::GeoJSONSource (that becomes invalid and dangerous to attempt to mutate). A partial example of such a trace is:

Mapbox`mbgl::style::GeoJSONSource::Impl::setGeoJSON(mapbox::util::variant<mapbox::geometry::geometry<double>, mapbox::geometry::feature<double>, mapbox::geometry::feature_collection<double, std::__1::vector> > const&) [inlined] std::__1::unique_ptr<mbgl::AsyncRequest, std::__1::default_delete<mbgl::AsyncRequest> >::reset(this=0x0000000000772f16, __p=0x0000000000000000) at memory:2733
    frame #1: 0x000000010544d3d1 Mapbox`mbgl::style::GeoJSONSource::Impl::setGeoJSON(this=0x0000000000772e36, geoJSON=0x00007fff5b641550) at geojson_source_impl.cpp:56
    frame #2: 0x000000010544c581 Mapbox`mbgl::style::GeoJSONSource::setGeoJSON(this=0x0000608000429e40, geoJSON=0x00007fff5b641550) at geojson_source.cpp:18
    frame #3: 0x0000000104c0f3a0 Mapbox`::-[MGLShapeSource setShape:](self=0x0000600000056f20, _cmd="setShape:", shape=0x00006000002c5d30) at MGLShapeSource.mm:130
    frame #4: 0x00000001045d9148 Mapbox GL`__51-[MBXViewController mapView:didFinishLoadingStyle:]_block_invoke((null)=0x0000608000058ea0) at MBXViewController.m:1847

Workarounds for this issue include recreating and adding the source and layer stack each time a style loads or only adding the source/layer to a specific style and also using APIs like -[MGLStyle sourceWithIdentifier:] instead of keeping references to sources in objects in the application space.

#6180 tracks a feature to persist sources and layers across style changes. Additionally improvements like #6386 and #7988 would help with the ergonomics in this area.

In the meantime, we should consider adding better exception handling and documentation to help guide developers around this trap. The somewhat random stack traces we get now make it hard to understand the underlying problem and how to work around it.

@boundsj boundsj added Core The cross-platform C++ core, aka mbgl crash iOS Mapbox Maps SDK for iOS runtime styling labels May 3, 2017
@jfirebaugh jfirebaugh mentioned this issue Jun 8, 2017
28 tasks
@stale stale bot added the archived Archived because of inactivity label Nov 7, 2018
@stale
Copy link

stale bot commented Nov 27, 2018

This issue has been automatically detected as stale because it has not had recent activity and will be archived. Thank you for your contributions.

@stale stale bot closed this as completed Nov 27, 2018
@jmkiley jmkiley reopened this Aug 1, 2019
@stale stale bot removed the archived Archived because of inactivity label Aug 1, 2019
@jmkiley jmkiley added the gl-ios label Nov 21, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Core The cross-platform C++ core, aka mbgl crash gl-ios iOS Mapbox Maps SDK for iOS runtime styling
Projects
None yet
Development

No branches or pull requests

2 participants