Select to view content in your preferred language

Fatal error: Object is already in use and may not be reused

548
7
Jump to solution
05-22-2024 04:02 AM
zdtorok
New Contributor III

I have two ArcGIS Maps, one for online and one for offline maps.

There are objects (graphicsOverlay) assigned to the online map and once I download a map, I'd expect to see the same graphics overlays (objects) on the map if they were part of the area that were downloaded.

This was working on 100.x but now I'm migrating to 200.x and I receive the following:

ArcGIS/CoreMutableArray.swift:47: Fatal error: Object is already in use and may not be reused.

This happens when I try to append an ArcGIS.GraphicsOverlay object to the model of my offline map.

If I remove this line, the offline map renders correctly without the objects.

Can it be that one GraphicsOverlay object cannot be used on more than one SwiftUI ArcGIS.Map? Or is it a bug?

I also changed simply changing the grraphicsOverlay's id to some unique value but still no luck.

Thank youl

0 Kudos
1 Solution

Accepted Solutions
rolson_esri
New Contributor III

A specific Graphics Overlay instance can only be part of one MapView at a time. If you are showing the MapViews at the same time then it's something that will have to change at your app level (ie. clone the overlay). If you are not showing the map views at the same time, but in succession, then please try 200.4 as we made some changes in that version that help with issues like that.

View solution in original post

7 Replies
DuanePfeiffer
New Contributor III

I believe you can't have the same graphic layer at the same time.  Has the layer been removed from the online map?

zdtorok
New Contributor III

Yes, I just replied to the other comment, but I called `graphicsOverlays.removeAll()` from my model that is used by the SwiftUI Map for the online UIViewController and added the graphics with `.append(...)` to the offline map.

0 Kudos
rolson_esri
New Contributor III

A specific Graphics Overlay instance can only be part of one MapView at a time. If you are showing the MapViews at the same time then it's something that will have to change at your app level (ie. clone the overlay). If you are not showing the map views at the same time, but in succession, then please try 200.4 as we made some changes in that version that help with issues like that.

zdtorok
New Contributor III

I have a model where I have the graphicsOverlays, see this:

var body: some View {
        ArcGIS.MapViewReader { proxy in
            ArcGIS.MapView(map: model.map,
                           viewpoint: model.viewpoint,
                           graphicsOverlays: model.graphicsOverlays)
            ...
        }
    }
}   

The two Maps are nested in an `UIViewController` as this is a legacy code which we are updating from 100.x to 200.x. Basically I hide/show the two UIViewControllers when there is a change.

When I want to show the offline map:

1. I remove the graphicsOverlays from the online map's model with `graphicsOverlays.removeAll()`
2. Add the new graphicsOverlays to the offline map's model.

Is there something else that I'm missing in this concept?

I'm already using 200.4.

Thanks! 

0 Kudos
rolson_esri
New Contributor III

If the overlay is removed from the first MapView before added to the second MapView then it should work. If the timing isn't correct you will get this error. Can you send us code that reproduces the problem you are seeing and we can try to debug it.

0 Kudos
zdtorok
New Contributor III

Also, how does it check if a Graphics Overlay is assigned to more than one MapView? Based on its ID or there is some reference on the Graphics Overlay to the assigned MapView that I could check?

0 Kudos
rolson_esri
New Contributor III

It's based on the instance, so it's the actual reference. You could check ObjectIdentifier(...) for equality or you could check identity equality (`===`). If the problem persists, you can clone the overlay but that solution might not work for you if you are mutating it.

0 Kudos