Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 16 additions & 10 deletions android/src/main/kotlin/com/uhg0/ar_flutter_plugin_2/ArView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -247,11 +247,14 @@ class ArView(
override fun onMoveEnd(detector: MoveGestureDetector, e: MotionEvent) {
if (handlePans) {
super.onMoveEnd(detector, e)
val transformMap = mapOf(
"name" to name,
"transform" to transform.toFloatArray().toList()
)
objectChannel.invokeMethod("onPanEnd", transformMap)
// Only invoke callback if name exists (defensive check)
name?.let { nodeName ->
val transformMap = mapOf(
"name" to nodeName,
"transform" to transform.toFloatArray().toList()
)
objectChannel.invokeMethod("onPanEnd", transformMap)
}
}
}

Expand All @@ -276,11 +279,14 @@ class ArView(
override fun onRotateEnd(detector: RotateGestureDetector, e: MotionEvent) {
if (handleRotation) {
super.onRotateEnd(detector, e)
val transformMap = mapOf(
"name" to name,
"transform" to transform.toFloatArray().toList()
)
objectChannel.invokeMethod("onRotationEnd", transformMap)
// Only invoke callback if name exists (defensive check)
name?.let { nodeName ->
val transformMap = mapOf(
"name" to nodeName,
"transform" to transform.toFloatArray().toList()
)
objectChannel.invokeMethod("onRotationEnd", transformMap)
}
}
}
}.apply {
Expand Down
12 changes: 10 additions & 2 deletions ios/Classes/IosARView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -626,10 +626,14 @@ class IosARView: NSObject, FlutterPlatformView, ARSCNViewDelegate, UIGestureReco
// State Ended
if(recognizer.state == UIGestureRecognizer.State.ended)
{
// Store node reference before clearing it
let nodeToSerialize = panningNode
// kill variables
panStartLocation = nil
panCurrentLocation = nil
DispatchQueue.main.async {self.objectManagerChannel.invokeMethod("onPanEnd", arguments: serializeLocalTransformation(node: self.panningNode))}
if let node = nodeToSerialize {
DispatchQueue.main.async {self.objectManagerChannel.invokeMethod("onPanEnd", arguments: serializeLocalTransformation(node: node))}
}
Comment on lines +634 to +636

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

With serializeLocalTransformation updated to return an optional dictionary, we should safely unwrap the serialized transformation dictionary before invoking the platform channel method. This prevents sending nil arguments to Flutter, which would otherwise trigger a NoSuchMethodError when Dart tries to access keys on a null arguments object.

Suggested change
if let node = nodeToSerialize {
DispatchQueue.main.async {self.objectManagerChannel.invokeMethod("onPanEnd", arguments: serializeLocalTransformation(node: node))}
}
if let node = nodeToSerialize, let transformDict = serializeLocalTransformation(node: node) {
DispatchQueue.main.async {self.objectManagerChannel.invokeMethod("onPanEnd", arguments: transformDict)}
}

panningNode = nil
}
}
Expand Down Expand Up @@ -688,10 +692,14 @@ class IosARView: NSObject, FlutterPlatformView, ARSCNViewDelegate, UIGestureReco
// State Ended
if(recognizer.state == UIGestureRecognizer.State.ended)
{
// Store node reference before clearing it
let nodeToSerialize = panningNode
// kill variables
rotation = nil
rotationVelocity = nil
DispatchQueue.main.async {self.objectManagerChannel.invokeMethod("onRotationEnd", arguments: serializeLocalTransformation(node: self.panningNode))}
if let node = nodeToSerialize {
DispatchQueue.main.async {self.objectManagerChannel.invokeMethod("onRotationEnd", arguments: serializeLocalTransformation(node: node))}
}
Comment on lines +700 to +702

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Similarly to onPanEnd, we should safely unwrap the serialized transformation dictionary returned by serializeLocalTransformation before invoking onRotationEnd to avoid sending nil arguments and causing a crash on the Flutter side.

Suggested change
if let node = nodeToSerialize {
DispatchQueue.main.async {self.objectManagerChannel.invokeMethod("onRotationEnd", arguments: serializeLocalTransformation(node: node))}
}
if let node = nodeToSerialize, let transformDict = serializeLocalTransformation(node: node) {
DispatchQueue.main.async {self.objectManagerChannel.invokeMethod("onRotationEnd", arguments: transformDict)}
}

panningNode = nil
}

Expand Down
9 changes: 7 additions & 2 deletions ios/Classes/Serialization/Serializers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,14 @@ func serializeAnchor(anchor: ARAnchor, anchorNode: SCNNode?, ganchor: GARAnchor,
func serializeLocalTransformation(node: SCNNode?) -> Dictionary<String, Any?> {
var serializedLocalTransformation = Dictionary<String, Any?>()

let transform: [Float?] = [node?.transform.m11, node?.transform.m12, node?.transform.m13, node?.transform.m14, node?.transform.m21, node?.transform.m22, node?.transform.m23, node?.transform.m24, node?.transform.m31, node?.transform.m32, node?.transform.m33, node?.transform.m34, node?.transform.m41, node?.transform.m42, node?.transform.m43, node?.transform.m44]
guard let node = node else {
// Return empty dictionary if node is nil to prevent crashes
return serializedLocalTransformation
}

let transform: [Float] = [node.transform.m11, node.transform.m12, node.transform.m13, node.transform.m14, node.transform.m21, node.transform.m22, node.transform.m23, node.transform.m24, node.transform.m31, node.transform.m32, node.transform.m33, node.transform.m34, node.transform.m41, node.transform.m42, node.transform.m43, node.transform.m44]

serializedLocalTransformation["name"] = node?.name
serializedLocalTransformation["name"] = node.name
serializedLocalTransformation["transform"] = transform

return serializedLocalTransformation
Expand Down