Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix BoneAttachment3D signal connection #81695

Merged
merged 1 commit into from
Sep 26, 2023

Conversation

bitsawer
Copy link
Member

@bitsawer bitsawer commented Sep 15, 2023

Previous attempt PR (#75907) was never merged as the issue became a bit harder to repro, but it can still happen in normal editor use, including in repro project #69614 (comment) by switching tabs and reloading the project. The code snippet in #81552 can repro this 100% of the time.

The problem is that bound variable which is used to track if the BoneAttachment3D is attached to a Skeleton3D and connected to its bone_pose_changed signal is set immediately, but the connection is made using a deferred call. This leaves one frame of time where the state can get messed up in various ways.

Looks like the deferred connection trick is a pretty rarely used pattern in Godot code base, after a quick search I could only find 4 similar uses, all in editor specific UI code. It was added in #51368 and replaced a more direct call bind_child_node_to_bone(). There might be a real reason why it creates the connection using a deferred call, but currently it's wrong because if BoneAttachment3D or any of its parent node is reparented or moved in a tree during the same frame the connection tracking (bound variable) will end out of sync with the real connection state.

I tested this with some models+MRP and couldn't notice any regressions, but skeleton related interactions can be pretty complex and subtle. Testing this more for example by importing and re-importing complex models which create BoneAttachment3Ds during import is recommended.

@bitsawer bitsawer added this to the 4.2 milestone Sep 15, 2023
@bitsawer bitsawer requested a review from a team as a code owner September 15, 2023 14:42
@bitsawer bitsawer requested a review from a team September 15, 2023 15:07
@YuriSizov YuriSizov requested a review from a team September 15, 2023 16:29
@A-Hugh-Mann
Copy link

this appears to remove errors about bone signals when adding/removing BoneAttachment3D to/from the scene tree.

@akien-mga akien-mga merged commit 571792c into godotengine:master Sep 26, 2023
15 checks passed
@akien-mga
Copy link
Member

Thanks!

@bitsawer bitsawer deleted the fix_bone_attachment_signal branch October 4, 2023 10:51
@akien-mga akien-mga added the cherrypick:4.1 Considered for cherry-picking into a future 4.1.x release label Oct 6, 2023
@YuriSizov YuriSizov removed the cherrypick:4.1 Considered for cherry-picking into a future 4.1.x release label Oct 24, 2023
@YuriSizov
Copy link
Contributor

Cherry-picked for 4.1.3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Signal connection issues when opening a project using BoneAttachment3D but it isn't the last scene tab
4 participants