Skip to content

Commit 9449e0a

Browse files
committed
Fix: Ensure node name is included in onPanEnd and onRotationEnd callbacks
- Fixed serializeLocalTransformation to handle nil nodes gracefully - Changed transform array from optional to non-optional Float array - Changed node name from optional to non-optional String - Store node reference before clearing panningNode to prevent nil access - Only invoke onPanEnd/onRotationEnd if node exists This fixes the issue where call.arguments["name"] was nil, causing the Dart callback handler to fail silently in the catch block.
1 parent 7e5fd59 commit 9449e0a

2 files changed

Lines changed: 17 additions & 4 deletions

File tree

ios/Classes/IosARView.swift

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -626,10 +626,14 @@ class IosARView: NSObject, FlutterPlatformView, ARSCNViewDelegate, UIGestureReco
626626
// State Ended
627627
if(recognizer.state == UIGestureRecognizer.State.ended)
628628
{
629+
// Store node reference before clearing it
630+
let nodeToSerialize = panningNode
629631
// kill variables
630632
panStartLocation = nil
631633
panCurrentLocation = nil
632-
DispatchQueue.main.async {self.objectManagerChannel.invokeMethod("onPanEnd", arguments: serializeLocalTransformation(node: self.panningNode))}
634+
if let node = nodeToSerialize {
635+
DispatchQueue.main.async {self.objectManagerChannel.invokeMethod("onPanEnd", arguments: serializeLocalTransformation(node: node))}
636+
}
633637
panningNode = nil
634638
}
635639
}
@@ -688,10 +692,14 @@ class IosARView: NSObject, FlutterPlatformView, ARSCNViewDelegate, UIGestureReco
688692
// State Ended
689693
if(recognizer.state == UIGestureRecognizer.State.ended)
690694
{
695+
// Store node reference before clearing it
696+
let nodeToSerialize = panningNode
691697
// kill variables
692698
rotation = nil
693699
rotationVelocity = nil
694-
DispatchQueue.main.async {self.objectManagerChannel.invokeMethod("onRotationEnd", arguments: serializeLocalTransformation(node: self.panningNode))}
700+
if let node = nodeToSerialize {
701+
DispatchQueue.main.async {self.objectManagerChannel.invokeMethod("onRotationEnd", arguments: serializeLocalTransformation(node: node))}
702+
}
695703
panningNode = nil
696704
}
697705

ios/Classes/Serialization/Serializers.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,14 @@ func serializeAnchor(anchor: ARAnchor, anchorNode: SCNNode?, ganchor: GARAnchor,
4242
func serializeLocalTransformation(node: SCNNode?) -> Dictionary<String, Any?> {
4343
var serializedLocalTransformation = Dictionary<String, Any?>()
4444

45-
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]
45+
guard let node = node else {
46+
// Return empty dictionary if node is nil to prevent crashes
47+
return serializedLocalTransformation
48+
}
49+
50+
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]
4651

47-
serializedLocalTransformation["name"] = node?.name
52+
serializedLocalTransformation["name"] = node.name
4853
serializedLocalTransformation["transform"] = transform
4954

5055
return serializedLocalTransformation

0 commit comments

Comments
 (0)