Here is a method that toggles the state of a boolean variable called imageryOn.
When I tap a button the code runs, and I am able to set the first object in the Operational Layers array as a ArcGISTiledLayer. Cool, tapping the on screen button shows the satellite imagery hosted service on the map and sets it to Operational Layers at index 0.
When I toggle the imageryOn bool to false I get an error message when trying to remove the first operational layer:
Thread 1: Fatal error: Object is already in use and may not be reused.
However, if I used the removeAllOperationalLayers method I am able to remove all operational layers (including the imagery layer). And the toggle then just shows imagery on and then imagery off.
func toggleImagery(){
imageryOn = !imageryOn
print(map.operationalLayers)
if imageryOn {
let imageryLayer = ArcGISTiledLayer(url: URL(string: "https://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer")!)
map.insertOperationalLayer(imageryLayer, at: 0)
print(map.operationalLayers.first!)
print(map.operationalLayers)
} else {
map.removeOperationalLayer(map.operationalLayers[0])
//map.removeAllOperationalLayers()
}
}
Any ideas on what could be going on here?
Thanks
Solved! Go to Solution.
Thanks for reporting! This bug will be fixed in the next release of the SDK. It is due to a misuse of the mutable array in the SDK.
In the meantime, you can still use the "remove all" approach, or set the isVisible property on the layers to show/hide a layer.
Should be fixed now in ArcGIS Maps SDK for Swift 200.2!
Thanks for reporting this bug 🐛. It seems like a regression between 200.0.0 and 200.1.0 - in the recent release we adjusted some error logic that might have caused it. Will share more details once our team discuss the root cause.
Thanks for reporting! This bug will be fixed in the next release of the SDK. It is due to a misuse of the mutable array in the SDK.
In the meantime, you can still use the "remove all" approach, or set the isVisible property on the layers to show/hide a layer.
@Ting thank you for looking into this and posting back with info on the resolution. Any idea on when the next release of the SDK will be available?
Thanks again!
If everything go smoothly, typically it will be released around August.
I am noticing this same error when the app is forced into the background. I have several operational layers on my Mobile Scene and when the user swipes up to force the app into the background I get a crash with the message: "Fatal Error: Object is already in use and may not be reused."
Should be fixed now in ArcGIS Maps SDK for Swift 200.2!
Confirmed working with 200.2!!
Not sure if I should raise a separate issue but this has not resolved my problem. Updated to 200.2, App with scene containing operational layers is crashing every time I force app into background while scene is displayed with he error "Fatal Error: Object is already in use and may not be reused." If the layers are removed before forcing app into background I do not get this error.
I'm on ArcGIS 200.3 and I also see " Object is already in use and may not be reused." sporadically. I doesn't happen when doing any explicit mutations, so I'm not sure why this happens, but it may happen as a result of re-rendering the SwiftUI view hierarchy. It may be that views are getting new implicit ids, and that the view model (ObservableObject) is reused, and this causes issues. I'm not sure.