Select to view content in your preferred language

Compose, Object Already Owned

640
4
12-21-2023 02:19 PM
LeighWoolley
Emerging Contributor

Hi, I'm trying to toggle between a Scene and Map using compose. I want to display the same Geodatabase feature table on the Scene or Map (2d)  when displayed. However on creating the feature layer I receive the Object already owned exception and I can't seem to free the table from the existing layers.

private suspend fun loadMobileScenePackage(tables: List<GeodatabaseFeatureTable>) {


// Load the Mil Symbols TODO: move to track manager
val dictionarySymbolStyle = DictionarySymbolStyle.createFromFile(styleFile)

// Load the symbols
dictionarySymbolStyle.load().onFailure { error ->
Log.e("Mapping", error.cause.toString() + ": " + styleFile)
}

mobileScenePackage.load().onSuccess {
// update the mutable state holder with the first scene from the MobileScenePackage
val scene = mobileScenePackage.scenes.first()

// Setup the scene with the renderer and geodb features

tables.forEach { ft ->
...
ft.load().onFailure { error ->
Log.e("SVC", error.cause.toString())
}
val featureLayer = FeatureLayer.createWithFeatureTable(ft)
featureLayer.load().onFailure { error ->
Log.e("SVC", error.cause.toString())
}
scene.operationalLayers.add(featureLayer)
...
}
_firstScene.update { scene }
}.onFailure { error ->
...
}

@Composable
fun createSceneViewInstance(lifecycleOwner: LifecycleOwner, sceneViewModel: SceneViewModel = hiltViewModel()): SceneView {
val sceneView = SceneView(LocalContext.current)
DisposableEffect(lifecycleOwner) {
lifecycleOwner.lifecycle.addObserver(sceneView)
onDispose {
lifecycleOwner.lifecycle.removeObserver(sceneView)
sceneView.onDestroy(lifecycleOwner)
}
}
return sceneView
}
 
Tags (1)
0 Kudos
4 Replies
RamaChintapalli
Esri Contributor

Hi,
If you have already instantiated a FeatureLayer with a feature table, that feature table cannot be used by another instance of Feature layer, that's when you will receive Object Already Owned exception.  You can always create a new instance.

Thanks
Rama

0 Kudos
LeighWoolley
Emerging Contributor

Thanks is there a correct method to destroy the feature layer or remove it from a Scene?

0 Kudos
RamaChintapalli
Esri Contributor

You can remove the featurelayer from the operational layers list of the geomodel (i.e map or scene) to be able to use the same instance of feature layer

dev4567
Emerging Contributor

Actually, the same issue with the Basemap -> one have to re-create Basemap from scratch or call Basemap.clone(). We need a better mechanism to release basemap from MapView

0 Kudos