SceneView / sceneview-android

SceneView is a 3D and AR Android Composable and View with Google Filament and ARCore. This is a Sceneform replacement in Kotlin
Apache License 2.0
758 stars 151 forks source link

Crash when dragging a node #431

Closed hshapley closed 4 weeks ago

hshapley commented 4 months ago

When dragging a Node in ARSceneView 2.0.3, it can crash with the exception java.util.NoSuchElementException: Collection contains no element matching the predicate. This is because in Node.kt on line 873 (in onMove), it uses first instead of firstOrNull. If it used the latter, then the null check would work, but since it just uses first, it throws an exception instead. In PoseNode line 27, it uses firstOrNull, so no issue there. I'm also not sure whether the logic is correct for the predicate - checking it.node == parent seems a little strange. Wouldn't it be better to check it.node == this, or checking both conditions?

ThomasGorisse commented 4 weeks ago

The hit testing on parent in made in case of non AR move. Imagine you have the follow parenting: anchor node (editable) > plane node (not editable) > model node (editable): If you want the model node to move on its parent plane, you will look at the hit test position in the parent so the model node can move into its parent plane without moving the anchor. If the plane is touched then the move will be transfered to its parent anchor so everything will move at the same time.

The null pointer fix is included in v2.2.1