-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Crash when changing styleURL if there is an empty datasource? #7124
Comments
Thanks for sending the sample app. However, I'm unable to reproduce the crash with beta.3. You should indeed be able to create a |
I still have this issue with Beta 4. You can't reproduce with the sample app? |
I do see the issue now with your code. You are adding the same source (and layer) instances each time Relatedly, it is also not a good idea to use the same identifier for source and layer objects across distinct instances no matter the sub-type. In fact, in the next iOS beta for 3.4.0, reusing identifiers will trigger an exception for sources (#7203) and layers (#7257). This bug report is a good reminder that we should raise an Note: It is fine to add a source with no features: func mapViewDidFinishLoadingMap(_ mapView: MGLMapView) {
if (alreadyAdded) { return }
let source = MGLGeoJSONSource(identifier: "source", features: [], options: nil)
mapView.style().add(source)
alreadyAdded = true
} And you can add features later on: func mapViewDidFinishLoadingMap(_ mapView: MGLMapView) {
if (alreadyAdded) { return }
let source = MGLGeoJSONSource(identifier: "source", features: [], options: nil)
mapView.style().add(source)
let layer = MGLCircleStyleLayer(identifier: "layer", source: source)
layer.circleColor = MGLStyleValue(rawValue: .red)
layer.circleRadius = MGLStyleValue(rawValue: 100)
mapView.style().add(layer)
alreadyAdded = true
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 2) {
let feature = MGLPointFeature()
feature.coordinate = CLLocationCoordinate2D(latitude: 40.73581, longitude: -73.99155)
source.features = [feature]
}
} I'm going to close this and we can track the related work in: |
@boundsj, Something I just realized and can't find a clear answer to in the documentation.
How are we supposed to handle changing the base StyleURL and existing I've implemented To get them to re-appear again I'm setting So, currently:
is at least working. Should I be nulling/removing the |
Particular use case: What if I have a |
Hi @nitrag. The feature you are asking about persist layers and sources across styles is tracked in #6180. Your current workaround seems reasonable to me. You can continue to recreate the source (and you don't need to store it in a class property) because you can't reuse a source once it is added to a style (even a different style) if you don't remove it first because of the transfer of ownership of the source to the rendering layer of the SDK. If there is performance gain to be had from caching the source, you could continue to store it as a property and try removing it from the current style before you change to the new style and add the source again. Removing a source (or layer) transfers the ownership of the instance back from the rendering layer of the SDK to the instance that your application (in this case) keeps a reference to. |
PSA: Don't use class variables for sources and layers. It'll open a can of 💩 . Instead, just re-init in |
I get a hard crash when changing map base layers -- I THINK -- when you have an empty data source? Seems to crash when re-adding a GeoJSON data source.
Actual:
If you don't comment out the line below, the app will crash when you click the button to change the map base layer.
Why do I have an empty data geojson layer? Well, I create an empty repository and add it to the map, then as a user scrolls to a particular area data is populated from the internet. It may be empty for the entirety of the application too.
Here is the sample app, without Mapbox Pod:
MapboxBUG-ChangeStyle.zip
The text was updated successfully, but these errors were encountered: