Skip to content

Commit e5367f1

Browse files
committed
Fix: Ensure node name is always included in onPanEnd and onRotationEnd callbacks
- Fixed serializeLocalTransformation to always include node name (non-optional) - Changed transform array from [Float?] to [Float] to prevent nil values - Added guard clause to prevent crashes when node is nil - Store node reference before clearing panningNode to prevent race conditions - Fixes issue where Dart code couldn't access node name from call.arguments["name"]
1 parent 964ddc2 commit e5367f1

4 files changed

Lines changed: 131 additions & 4 deletions

File tree

auto_fork_and_pr.sh

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#!/bin/bash
2+
set -e
3+
4+
REPO="hlefe/ar_flutter_plugin_2"
5+
BRANCH="fix/pan-rotation-end-node-name"
6+
GITHUB_USER="Nikkon" # From git config
7+
8+
echo "🚀 Automating PR creation for $REPO"
9+
echo ""
10+
11+
# Try to fork using GitHub API if token is available
12+
if [ -n "$GITHUB_TOKEN" ]; then
13+
echo "🔑 GitHub token found, attempting to fork..."
14+
FORK_RESPONSE=$(curl -s -X POST \
15+
-H "Authorization: token $GITHUB_TOKEN" \
16+
-H "Accept: application/vnd.github.v3+json" \
17+
"https://api.github.com/repos/$REPO/forks" 2>&1)
18+
19+
if echo "$FORK_RESPONSE" | grep -q '"full_name"'; then
20+
echo "✅ Fork created successfully!"
21+
sleep 2 # Wait for GitHub to propagate
22+
else
23+
echo "⚠️ Fork may already exist or error occurred"
24+
echo "$FORK_RESPONSE" | head -5
25+
fi
26+
else
27+
echo "ℹ️ No GITHUB_TOKEN found. Please fork manually at:"
28+
echo " https://github.com/$REPO/fork"
29+
echo ""
30+
echo "Or set GITHUB_TOKEN environment variable and run again."
31+
echo ""
32+
read -p "Press Enter after forking..." -r
33+
fi
34+
35+
# Add fork remote and push
36+
FORK_URL="https://github.com/$GITHUB_USER/ar_flutter_plugin_2.git"
37+
echo ""
38+
echo "📤 Adding fork remote and pushing branch..."
39+
git remote add fork "$FORK_URL" 2>/dev/null || git remote set-url fork "$FORK_URL"
40+
41+
# Try to push
42+
if git push -u fork "$BRANCH" 2>&1; then
43+
echo ""
44+
echo "✅ Success! Branch pushed to your fork."
45+
echo ""
46+
echo "🔗 Create PR here:"
47+
echo " https://github.com/$REPO/compare/main...$GITHUB_USER:ar_flutter_plugin_2:$BRANCH"
48+
echo ""
49+
echo "PR Title: Fix: Ensure node name is included in onPanEnd and onRotationEnd callbacks"
50+
echo ""
51+
echo "PR Description:"
52+
echo "This PR fixes a bug where onPanEnd and onRotationEnd callbacks were failing"
53+
echo "because the node name was not being properly included in the arguments."
54+
echo ""
55+
echo "Changes:"
56+
echo "- Fixed serializeLocalTransformation to handle nil nodes gracefully"
57+
echo "- Changed transform array from optional to non-optional Float array"
58+
echo "- Changed node name from optional to non-optional String"
59+
echo "- Store node reference before clearing panningNode to prevent nil access"
60+
echo "- Only invoke onPanEnd/onRotationEnd if node exists"
61+
else
62+
echo ""
63+
echo "❌ Push failed. Please check:"
64+
echo " 1. Fork exists at: https://github.com/$GITHUB_USER/ar_flutter_plugin_2"
65+
echo " 2. You have push access to your fork"
66+
echo " 3. Your git credentials are configured"
67+
fi

create_pr.sh

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/bin/bash
2+
set -e
3+
4+
REPO="hlefe/ar_flutter_plugin_2"
5+
BRANCH="fix/pan-rotation-end-node-name"
6+
7+
echo "🚀 Creating PR for $REPO"
8+
echo ""
9+
10+
# Get GitHub username from git config
11+
GITHUB_USER=$(git config --global user.name 2>/dev/null || echo "")
12+
if [ -z "$GITHUB_USER" ]; then
13+
echo "❌ Could not determine GitHub username from git config"
14+
echo "Please provide your GitHub username:"
15+
read -r GITHUB_USER
16+
fi
17+
18+
echo "📋 Using GitHub username: $GITHUB_USER"
19+
echo ""
20+
21+
# Check if fork exists
22+
echo "🔍 Checking if fork exists..."
23+
FORK_URL="https://github.com/$GITHUB_USER/ar_flutter_plugin_2.git"
24+
25+
if git ls-remote --exit-code "$FORK_URL" &>/dev/null; then
26+
echo "✅ Fork found!"
27+
git remote add fork "$FORK_URL" 2>/dev/null || git remote set-url fork "$FORK_URL"
28+
else
29+
echo "❌ Fork not found. Please fork the repository first:"
30+
echo " https://github.com/$REPO/fork"
31+
echo ""
32+
echo "Press Enter after forking..."
33+
read -r
34+
git remote add fork "$FORK_URL" 2>/dev/null || git remote set-url fork "$FORK_URL"
35+
fi
36+
37+
echo ""
38+
echo "📤 Pushing branch to your fork..."
39+
git push -u fork "$BRANCH"
40+
41+
echo ""
42+
echo "✅ Branch pushed successfully!"
43+
echo ""
44+
echo "🔗 Create PR using this link:"
45+
echo " https://github.com/$REPO/compare/main...$GITHUB_USER:ar_flutter_plugin_2:$BRANCH"
46+
echo ""
47+
echo "Or go to: https://github.com/$REPO/compare and select your fork/branch"

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)