Error Removing Single/Sequence Operational Layer(s) but removing all works? Maps SDK 200.1.0

1343
9
Jump to solution
05-31-2023 03:38 PM
vansant
New Contributor II

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

0 Kudos
2 Solutions

Accepted Solutions
Ting
by Esri Contributor
Esri Contributor

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.

View solution in original post

Ting
by Esri Contributor
Esri Contributor
9 Replies
Ting
by Esri Contributor
Esri Contributor

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.

Ting
by Esri Contributor
Esri Contributor

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.

vansant
New Contributor II

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

0 Kudos
Ting
by Esri Contributor
Esri Contributor

If everything go smoothly, typically it will be released around August.

0 Kudos
alionthego
New Contributor II

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

0 Kudos
Ting
by Esri Contributor
Esri Contributor

Should be fixed now in ArcGIS Maps SDK for Swift 200.2!

vansant
New Contributor II

Confirmed working with 200.2!!

0 Kudos
alionthego
New Contributor II

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.  

0 Kudos
sveinhal
New Contributor II

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.

0 Kudos