Skip to content
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
This repository was 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

Description

@boundsj

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.

Activity

  1. added
    Core
    iOS
    on May 3, 2017
  2. added
    archived
    on Nov 7, 2018
  3. stale commented on Nov 27, 2018

    @stale

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

  4. reopened this on Aug 1, 2019
  5. removed
    archived
    on Aug 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Corecrashgl-iosiOSruntime styling

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions