Select to view content in your preferred language

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

566
2
07-29-2024 11:32 PM
FadhliFirdausSulaiman
New Contributor

Hi Esri community,

I want to inquire on this crash that's happening on ArcGIS Swift SDK package 200.4. I have an issue whereby when I instantiate a map, and change basemaps, when I click back to previous navigation stack, then reenter the screen where the map is showing by clicking the same button, it gives this error :

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

I understand this is an internal error and I couldn't find the implicit closure #1 within the package, so surely I couldn't understand this issue. 

 

Here's the stack trace : 

#0 0x00000001932a0f68 in _swift_runtime_on_report ()
#1 0x000000019333914c in _swift_stdlib_reportFatalErrorInFile ()
#2 0x0000000192ffe2d8 in _assertionFailure(_:_:file:line:flags:) ()
#3 0x0000000109041a84 in withVectorInsertErrorHandler(_:file:line:) at /Users/jenkins/jenkins/workspace/200.4.0/daily_swift_SDK_release/swift/ArcGIS/Sources/ArcGIS/Common/CoreMutableArray.swift:84
#4 0x00000001090cd180 in ___lldb_unnamed_symbol46538 ()
#5 0x00000001092ea78c in ___lldb_unnamed_symbol65520 ()
#6 0x0000000109410c9c in specialized RangeReplaceableCollection.append<τ_0_0>(contentsOf:) [inlined] ()
#7 0x0000000109410c90 in specialized CoreMapView.__allocating_init(map:viewpoint:timeExtent:graphicsOverlays:) at /Users/jenkins/jenkins/workspace/200.4.0/daily_swift_SDK_release/swift/ArcGIS/Sources/ArcGIS/Views/Map View/MapView.swift:582
#8 0x0000000109407e84 in CoreMapView.__allocating_init(map:viewpoint:timeExtent:graphicsOverlays:) [inlined] ()
#9 0x0000000109407e70 in implicit closure #1 in MapView.init(map:viewpoint:timeExtent:graphicsOverlays:) at /Users/jenkins/jenkins/workspace/200.4.0/daily_swift_SDK_release/swift/ArcGIS/<compiler-generated>:123
#10 0x00000001ccba2990 in ___lldb_unnamed_symbol172083 ()
#11 0x00000001cc7ce32c in ___lldb_unnamed_symbol142035 ()
#12 0x00000001cc7cdc8c in ___lldb_unnamed_symbol142022 ()
#13 0x00000001cd561de8 in ___lldb_unnamed_symbol250828 ()
#14 0x00000001cd561e24 in ___lldb_unnamed_symbol250829 ()
#15 0x00000001930e4f48 in withUnsafePointer<τ_0_0, τ_0_1>(to:_:) ()
#16 0x000000019328c3a8 in withUnsafeMutablePointer<τ_0_0, τ_0_1>(to:_:) ()
#17 0x00000001cd561ca0 in ___lldb_unnamed_symbol250826 ()
#18 0x00000001cd561a28 in ___lldb_unnamed_symbol250825 ()
#19 0x00000001cc2697f4 in ___lldb_unnamed_symbol104313 ()
#20 0x00000001b9d4f5c4 in AG::Graph::UpdateStack::update() ()
#21 0x00000001b9d4fd54 in AG::Graph::update_attribute(AG::data::ptr<AG::Node>, unsigned int) ()
#22 0x00000001b9d57d2c in AG::Graph::input_value_ref_slow(AG::data::ptr<AG::Node>, AG::AttributeID, unsigned int, unsigned int, AGSwiftMetadata const*, unsigned char&, long) ()
#23 0x00000001b9d6ee24 in AGGraphGetValue ()
#24 0x00000001ccfb1dc8 in ___lldb_unnamed_symbol205193 ()
#25 0x00000001ccfb1f40 in ___lldb_unnamed_symbol205201 ()
#26 0x00000001cc2697f4 in ___lldb_unnamed_symbol104313 ()
#27 0x00000001b9d4f5c4 in AG::Graph::UpdateStack::update() ()
#28 0x00000001b9d4fd54 in AG::Graph::update_attribute(AG::data::ptr<AG::Node>, unsigned int) ()
#29 0x00000001b9d57d2c in AG::Graph::input_value_ref_slow(AG::data::ptr<AG::Node>, AG::AttributeID, unsigned int, unsigned int, AGSwiftMetadata const*, unsigned char&, long) ()
#30 0x00000001b9d6ee24 in AGGraphGetValue ()
#31 0x00000001cce72508 in ___lldb_unnamed_symbol194883 ()
#32 0x00000001b9d4f5c4 in AG::Graph::UpdateStack::update() ()
#33 0x00000001b9d4fd54 in AG::Graph::update_attribute(AG::data::ptr<AG::Node>, unsigned int) ()
#34 0x00000001b9d57d2c in AG::Graph::input_value_ref_slow(AG::data::ptr<AG::Node>, AG::AttributeID, unsigned int, unsigned int, AGSwiftMetadata const*, unsigned char&, long) ()
#35 0x00000001b9d6ee24 in AGGraphGetValue ()
#36 0x00000001cc6e1130 in ___lldb_unnamed_symbol134067 ()
#37 0x00000001cc484170 in ___lldb_unnamed_symbol118258 ()
#38 0x00000001cc48312c in ___lldb_unnamed_symbol118257 ()
#39 0x00000001cc610ba8 in ___lldb_unnamed_symbol122648 ()
#40 0x00000001b9d4f5c4 in AG::Graph::UpdateStack::update() ()
#41 0x00000001b9d4fd54 in AG::Graph::update_attribute(AG::data::ptr<AG::Node>, unsigned int) ()
#42 0x00000001b9d57d2c in AG::Graph::input_value_ref_slow(AG::data::ptr<AG::Node>, AG::AttributeID, unsigned int, unsigned int, AGSwiftMetadata const*, unsigned char&, long) ()
#43 0x00000001b9d6ee24 in AGGraphGetValue ()
#44 0x00000001cca3d12c in ___lldb_unnamed_symbol160335 ()
#45 0x00000001cca3d2d4 in ___lldb_unnamed_symbol160344 ()
#46 0x00000001cc34d4cc in ___lldb_unnamed_symbol112381 ()
#47 0x00000001b9d4f5c4 in AG::Graph::UpdateStack::update() ()
#48 0x00000001b9d4fd54 in AG::Graph::update_attribute(AG::data::ptr<AG::Node>, unsigned int) ()
#49 0x00000001b9d57d2c in AG::Graph::input_value_ref_slow(AG::data::ptr<AG::Node>, AG::AttributeID, unsigned int, unsigned int, AGSwiftMetadata const*, unsigned char&, long) ()
#50 0x00000001b9d6ee24 in AGGraphGetValue ()
#51 0x00000001ccf5a544 in ___lldb_unnamed_symbol202298 ()
#52 0x00000001cc34d4cc in ___lldb_unnamed_symbol112381 ()
#53 0x00000001b9d4f5c4 in AG::Graph::UpdateStack::update() ()
#54 0x00000001b9d4fd54 in AG::Graph::update_attribute(AG::data::ptr<AG::Node>, unsigned int) ()
#55 0x00000001b9d57d2c in AG::Graph::input_value_ref_slow(AG::data::ptr<AG::Node>, AG::AttributeID, unsigned int, unsigned int, AGSwiftMetadata const*, unsigned char&, long) ()
#56 0x00000001b9d6ee24 in AGGraphGetValue ()
#57 0x00000001cca3d554 in ___lldb_unnamed_symbol160344 ()
#58 0x00000001cc34d4cc in ___lldb_unnamed_symbol112381 ()
#59 0x00000001b9d4f5c4 in AG::Graph::UpdateStack::update() ()
#60 0x00000001b9d4fd54 in AG::Graph::update_attribute(AG::data::ptr<AG::Node>, unsigned int) ()
#61 0x00000001b9d57d2c in AG::Graph::input_value_ref_slow(AG::data::ptr<AG::Node>, AG::AttributeID, unsigned int, unsigned int, AGSwiftMetadata const*, unsigned char&, long) ()
#62 0x00000001b9d6ee24 in AGGraphGetValue ()
#63 0x00000001cc7703bc in ___lldb_unnamed_symbol138636 ()
#64 0x00000001cc2697f4 in ___lldb_unnamed_symbol104313 ()
#65 0x00000001b9d4f5c4 in AG::Graph::UpdateStack::update() ()
#66 0x00000001b9d4fd54 in AG::Graph::update_attribute(AG::data::ptr<AG::Node>, unsigned int) ()
#67 0x00000001b9d57d2c in AG::Graph::input_value_ref_slow(AG::data::ptr<AG::Node>, AG::AttributeID, unsigned int, unsigned int, AGSwiftMetadata const*, unsigned char&, long) ()
#68 0x00000001b9d6ee24 in AGGraphGetValue ()
#69 0x00000001ccf5a544 in ___lldb_unnamed_symbol202298 ()
#70 0x00000001cc34d4cc in ___lldb_unnamed_symbol112381 ()
#71 0x00000001b9d4f5c4 in AG::Graph::UpdateStack::update() ()
#72 0x00000001b9d4fd54 in AG::Graph::update_attribute(AG::data::ptr<AG::Node>, unsigned int) ()
#73 0x00000001b9d57d2c in AG::Graph::input_value_ref_slow(AG::data::ptr<AG::Node>, AG::AttributeID, unsigned int, unsigned int, AGSwiftMetadata const*, unsigned char&, long) ()
#74 0x00000001b9d6ee24 in AGGraphGetValue ()
#75 0x00000001ccf5a544 in ___lldb_unnamed_symbol202298 ()
#76 0x00000001cc34d4cc in ___lldb_unnamed_symbol112381 ()
#77 0x00000001b9d4f5c4 in AG::Graph::UpdateStack::update() ()
#78 0x00000001b9d4fd54 in AG::Graph::update_attribute(AG::data::ptr<AG::Node>, unsigned int) ()
#79 0x00000001b9d57d2c in AG::Graph::input_value_ref_slow(AG::data::ptr<AG::Node>, AG::AttributeID, unsigned int, unsigned int, AGSwiftMetadata const*, unsigned char&, long) ()
#80 0x00000001b9d6ee24 in AGGraphGetValue ()
#81 0x00000001cc7703bc in ___lldb_unnamed_symbol138636 ()
#82 0x00000001cc2697f4 in ___lldb_unnamed_symbol104313 ()
#83 0x00000001b9d4f5c4 in AG::Graph::UpdateStack::update() ()
#84 0x00000001b9d4fd54 in AG::Graph::update_attribute(AG::data::ptr<AG::Node>, unsigned int) ()
#85 0x00000001b9d57d2c in AG::Graph::input_value_ref_slow(AG::data::ptr<AG::Node>, AG::AttributeID, unsigned int, unsigned int, AGSwiftMetadata const*, unsigned char&, long) ()
#86 0x00000001b9d6ee24 in AGGraphGetValue ()
#87 0x00000001cc7703bc in ___lldb_unnamed_symbol138636 ()
#88 0x00000001cc2697f4 in ___lldb_unnamed_symbol104313 ()
#89 0x00000001b9d4f5c4 in AG::Graph::UpdateStack::update() ()
#90 0x00000001b9d4fd54 in AG::Graph::update_attribute(AG::data::ptr<AG::Node>, unsigned int) ()
#91 0x00000001b9d57d2c in AG::Graph::input_value_ref_slow(AG::data::ptr<AG::Node>, AG::AttributeID, unsigned int, unsigned int, AGSwiftMetadata const*, unsigned char&, long) ()
#92 0x00000001b9d6ee24 in AGGraphGetValue ()
#93 0x00000001cca3d554 in ___lldb_unnamed_symbol160344 ()
#94 0x00000001cc34d4cc in ___lldb_unnamed_symbol112381 ()
#95 0x00000001b9d4f5c4 in AG::Graph::UpdateStack::update() ()
#96 0x00000001b9d4fd54 in AG::Graph::update_attribute(AG::data::ptr<AG::Node>, unsigned int) ()
#97 0x00000001b9d57d2c in AG::Graph::input_value_ref_slow(AG::data::ptr<AG::Node>, AG::AttributeID, unsigned int, unsigned int, AGSwiftMetadata const*, unsigned char&, long) ()
#98 0x00000001b9d6ee24 in AGGraphGetValue ()
#99 0x00000001cca3d554 in ___lldb_unnamed_symbol160344 ()
#100 0x00000001cc34d4cc in ___lldb_unnamed_symbol112381 ()
#101 0x00000001b9d4f5c4 in AG::Graph::UpdateStack::update() ()
#102 0x00000001b9d4fd54 in AG::Graph::update_attribute(AG::data::ptr<AG::Node>, unsigned int) ()
#103 0x00000001b9d57388 in AG::Graph::value_ref(AG::AttributeID, unsigned int, AGSwiftMetadata const*, unsigned char&) ()
#104 0x00000001b9d6f114 in AGGraphGetWeakValue ()
#105 0x00000001cd42a04c in ___lldb_unnamed_symbol240785 ()
#106 0x00000001ccbf87dc in ___lldb_unnamed_symbol174599 ()
#107 0x00000001cd4d9e7c in ___lldb_unnamed_symbol246145 ()
#108 0x00000001cd4d995c in ___lldb_unnamed_symbol246144 ()
#109 0x00000001cd4d8108 in ___lldb_unnamed_symbol246036 ()
#110 0x00000001ccf092bc in ___lldb_unnamed_symbol199262 ()
#111 0x00000001ccf09164 in ___lldb_unnamed_symbol199260 ()
#112 0x00000001ccf09948 in ___lldb_unnamed_symbol199300 ()
#113 0x00000001ccf0b1a8 in ___lldb_unnamed_symbol199374 ()
#114 0x00000001cd4da128 in ___lldb_unnamed_symbol246145 ()
#115 0x00000001cd4d995c in ___lldb_unnamed_symbol246144 ()
#116 0x00000001cd4d8108 in ___lldb_unnamed_symbol246036 ()
#117 0x00000001cd5358b8 in ___lldb_unnamed_symbol249100 ()
#118 0x00000001cd535900 in ___lldb_unnamed_symbol249101 ()
#119 0x00000001858f566c in -[UIView(CALayerDelegate) layoutSublayersOfLayer:] ()
#120 0x000000018a1a7f70 in CA::Layer::layout_if_needed(CA::Transaction*) ()
#121 0x000000018a1b2d28 in CA::Layer::layout_and_display_if_needed(CA::Transaction*) ()
#122 0x000000018a0ebf54 in CA::Context::commit_transaction(CA::Transaction*, double, double*) ()
#123 0x000000018a11bcd0 in CA::Transaction::commit() ()
#124 0x000000018a11d1a4 in CA::Transaction::flush_as_runloop_observer(bool) ()
#125 0x000000018040ddf4 in __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ ()
#126 0x00000001804087f8 in __CFRunLoopDoObservers ()
#127 0x0000000180408cb0 in __CFRunLoopRun ()
#128 0x00000001804084d4 in CFRunLoopRunSpecific ()
#129 0x000000018ef2aae4 in GSEventRunModal ()
#130 0x00000001853d0a28 in -[UIApplication _run] ()
#131 0x00000001853d46b0 in UIApplicationMain ()
#132 0x00000001ccf100e4 in ___lldb_unnamed_symbol199689 ()
#133 0x00000001ccf0ff8c in ___lldb_unnamed_symbol199687 ()
#134 0x00000001ccbcd6d8 in static App.main() ()
#135 0x000000010482dc20 in static MyCartoGO.$main() ()
#136 0x000000010482e0dc in main at /Users/fadhlifirdaus/Desktop/mycartogo-ios/MyCartoGO.swift:15

I understand it is regarding the overlays but I have already tried many hacks, including resetting the overlays, removing the overlays on back click, instantiating new overlay object etc, but to no avail.

Here are other steps I have taken : 

This is part of my code generally : 

struct TopographyMapView: View {

    @ObservedObject var model:TopographyModel = .shared

    @ObservedObject var locationManager:LocationManager = .shared

    

    var body: some View {

        GeometryReader{ geoReader in

            ZStack{

                MapViewReader { mapReader in

                    ArcGIS.MapView(

                        map: model.map,

                        viewpoint: model.viewPoint,

                        graphicsOverlays: isShowing ? model.getOverlays():[])

                    .onSpatialReferenceChanged(perform: { model.currentSpatialReference = $0 })

                    .onUnitsPerPointChanged { model.unitsPerPoint = $0 }

                    .onRotationChanged(perform: { model.userRotation = $0 })

                    .onScaleChanged(perform: { model.userScale = $0 })

                    .onVisibleAreaChanged(perform: { model.currentVisible = $0 })

                    .onViewpointChanged(

                        kind: .centerAndScale,

                        perform: { model.viewPoint = $0 }

                    )

                    .onSingleTapGesture(perform: { tapPoint, mapPoint in

                        if(model.currentMapMode != .OfflineMap){

                            model.handleMapTap(tapPoint: tapPoint, point: mapPoint)

                        }

                    })

                    .callout(placement: $model.elevationCallout.animation(.default.speed(2))) { _ in

                        if(model.currentMapMode != .OfflineMap){

                            VStack(alignment: .leading) {

                                Text("Elevation")

                                    .font(.headline)

                                (Text(

                                    CoordinateFormatter.latitudeLongitudeString(

                                        from: model.mapPoint!,

                                        format: .decimalDegrees,

                                        decimalPlaces: 4

                                    )) + Text(" ") +  Text(String(format: "%.0f", model.lastElevation)) + Text("h")

                                )

                                .font(.callout)

                            }

                            .padding(5)

                        }

                    }

                    .task {

                        do {

                            try await model.initializeOfflineMapTask()

                        } catch {

                            print(error)

                        }

                    }

                    .onChange(of: locationManager.currentUserLocation?.coordinate.latitude ?? 0.0) { oldValue, newValue in

                        model.userLat = newValue

                        model.setUserLocationIndicator()

                    }

                    .onChange(of: locationManager.currentUserLocation?.coordinate.longitude ?? 0.0) { oldValue, newValue in

                        model.userLong = newValue

                        model.setUserLocationIndicator()

                    }

                    .task (id: "\(model.searchCoordinates.x)-\(model.searchCoordinates.y)", {

                        if(!(model.searchCoordinates.x == 0.0 && model.searchCoordinates.y == 0.0)){

                            model.setSearchLocationIndicator(

                                lat: model.searchCoordinates.x,

                                long: model.searchCoordinates.y

                            )

                            await mapReader.setViewpointCenter(Point(latitude: model.searchCoordinates.x, longitude: model.searchCoordinates.y), scale: model.userScale)

                        }

                    })

                    .task(id: networkManager.isConnected) {

                        if(networkManager.isConnected){

                            model.setUserLocationIndicator()

                        }

                    }

                    .onAppear {

                        model.currentMapReader = mapReader

                        model.appearMethod(locationManager: locationManager, mapReader: mapReader)

                        model.setUserLocationIndicator()

                        ArcGISEnvironment.authenticationManager.arcGISAuthenticationChallengeHandler = ArcGISAuthManager()

                    }

                }

The code related to basemap  :

 

    func setNewBasemap(newBasemap:BasemapEnum){

        d(currentSpatialReference)

        userBasemapMode = newBasemap

 

        switch newBasemap {

            

        case .PhysicalRelief, .Administrative, .HeightFeaturesSpot:

            //wkid = 4742

            let layer = ArcGISTiledLayer(url: newBasemap.getURL())

            map = Map(spatialReference: SpatialReference(wkid: WKID(rawValue: 4742)!))

            map.basemap = Basemap(baseLayer: layer)

            if(newBasemap == .PhysicalRelief){

                map.maxScale = 50_500

            }

        case .ArcGISImagery, .ArcGISNavigation, .OSM:

            //wkid = 3857

            map = Map(spatialReference: SpatialReference(wkid: WKID(rawValue: 3857)!))

            map.basemap = Basemap(style: newBasemap.getStyle()!)

        }

        

        map.initialViewpoint = viewPoint

    }

Here are what I have tried : 

- Making the map optional 
- Making two instances of Map, one with wkid 3857 and another 4742, and toggling between the two (still crash)

- Just instantiating Map() once and then changing basemaps with map.basemap directly (just shows one wkid without another, I have to Map() again to show the other wkid map).

- conditional overlay

I'm not sure what to do here, please share some insights. I'll provide more code if necessary. I have put a lot of hours just debugging and making a workaround for this. I have read several posts on this but most did not help.

 

Thanks

0 Kudos
2 Replies
CalebRasmussen
Esri Contributor

Hi @FadhliFirdausSulaiman,

Thank you for reaching out! In the ArcGIS Maps SDK, some objects cannot be reused more than once (e.g., you can't add the same layer object to the map twice). Otherwise, the error you saw is thrown (see ObjectAlreadyInUseError). Basemaps, Graphics, and GraphicsOverlays are some of those objects.

It is hard to tell what is being reused, but the setNewBasemap(newBasemap:)  code you provided doesn’t seem to be the issue. I would agree that it is possibly related to the overlays. Something like the same overlay is being used more than once in the array being passed to the MapView or a graphic being added to an overlay more than once. If you provide more implementation details on how the overlays are created/handled, I might be able to help further. Let me know if this helps or if you have more questions!

0 Kudos
FadhliFirdausSulaiman
New Contributor

Hi Caleb, thanks for the response!! I definitely thought it was the Map or Basemap object, I'll try to debug the overlays. 

Currently I try to implement the best practice in overlay as said in the docs, which is to return all graphic as a single layer. I might have misimplemented. Thanks though!! Hope you would help if I stump myself again 

0 Kudos