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 crash when inserting keyframes with empty properties array #99148

Merged
merged 1 commit into from
Nov 15, 2024

Conversation

TopherBriggs
Copy link
Contributor

@TopherBriggs TopherBriggs commented Nov 12, 2024

Fix crash when inserting keyframes with empty properties array

Bugsquad edit:

Description

When inserting rotation keyframes in the animation editor, clicking on the keyframe would cause the editor to crash due to an Array out-of-bound error. Upon further inspection using coredumpctl it seems to be crashing from a out-of-bounds index on editor_inspector.cpp:2727, with accessing F.properties[0] without checking if the properties array is empty could cause a crash. This is accessed to see if the property is in the favorites list. However, if an element such as AnimationTrackKeyEdit does not have any properties that can be favorited. This PR adds a safety check to prevent accessing an empty array.

Modified Files

  • editor/editor_inspector.cpp

Changes

The following changes prevent the crash by adding an empty check before accessing the properties array:

EditorProperty ***ep = Object::cast_to<EditorProperty>(F.property_editor);
- if (ep && current_favorites.has(F.properties[0])) {
+ if (ep && !F.properties.is_empty() && current_favorites.has(F.properties[0])) {
    ep->favorited = true;
    favorites_vbox->add_child(F.property_editor);
} else {
    current_vbox->add_child(F.property_editor);
}

Testing

Tested with the provided reproduction case:

  1. Imported the FBX model from the reproduction case
  2. Created a new inherited scene
  3. Added animation track as child to Skeleton3D
  4. Created new animation
  5. Added upper_arm.L and upper_arm.R rotation to track
  6. Successfully inserted keyframe without crash

Tested on:

  • Godot v4.4.dev
  • Arch Linux x86_64 GNOME 47.1 Kernel: 6.11.6-arch1-1
  • CPU: 12th Gen Intel i7-1260P (16) @ 4.700GHz
  • GPU: Intel Alder Lake-P GT2 [Iris Xe Graphics]

Notes

The crash occurred because the properties array could be empty when attempting to insert certain types of keyframes in the animation editor. This fix ensures we check for empty arrays before accessing their elements, following proper array bounds checking practices.

@TopherBriggs TopherBriggs requested a review from a team as a code owner November 12, 2024 21:50
@AThousandShips AThousandShips added this to the 4.4 milestone Nov 13, 2024
@AThousandShips AThousandShips added the cherrypick:4.3 Considered for cherry-picking into a future 4.3.x release label Nov 13, 2024
@TokageItLab
Copy link
Member

TokageItLab commented Nov 13, 2024

Can you provide a video capture of the detailed reproduction procedure for #98751 first? Since the crash does not occur in my environment.

Also, the code you are trying to fix has been no longer exist in master. So check again if the problem occurs on the latest master branch. Sorry I was watching a delayed brunch. In any case, #98751 is reported in 4.3 stable (It means that the code you are trying to fix does not exist in 4.3 stable, if this PR is valid, then the null check near there has been missing in 4.3?) and the bug does not occur in my environment.

@AThousandShips AThousandShips removed the cherrypick:4.3 Considered for cherry-picking into a future 4.3.x release label Nov 13, 2024
@YeldhamDev
Copy link
Member

@TokageItLab I'm able to reproduce it on my end, GNU/Linux. And PR's code fixes it.

Copy link
Member

@fire fire left a comment

Choose a reason for hiding this comment

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

The logic to check for empty properties to avoid the crash makes sense. Also, the crash has been confirmed. Thirdly, I don't see how it will break the code even if it's wrong, so the risk of merging is low and the benefit of fixing a crash is high.

@TopherBriggs
Copy link
Contributor Author

Here's the video capture of the crash reported by #98751 replicated on my machine:

Pre-change.mp4

With the change in this PR the crash no longer occurs:

Post-change.mp4

I also added the requested formatting change

@AThousandShips
Copy link
Member

Need to confirm that the 4.3 crash is related so unlocking the issue until we can confirm a dedicated 4.3 version fixes this as the code is different

Copy link
Member

@TokageItLab TokageItLab left a comment

Choose a reason for hiding this comment

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

I cannot reproduce the crash in my environment when I perform the same operation as in the video, so it may be an environment-dependent (Linux?) issue.

What I am concerned about is that this fix is not directly related to the animation, but is a check on the processing timing of the inspector plugin.

Considering that the inspector is displayed correctly after the fix, is it possible that the inspector plugin is being called multiple times and somewhere along the way null accesses are occurring? I think we need to take a closer look at why the property is missing there.

Well, as fire's comment says, it should be a safe change, so I think it's okay with merging it to prevent crashes for now.

@akien-mga akien-mga changed the title Fix crash when inserting keyframes with empty properties array Animation: Fix crash when inserting keyframes with empty properties array Nov 15, 2024
@akien-mga akien-mga changed the title Animation: Fix crash when inserting keyframes with empty properties array Fix crash when inserting keyframes with empty properties array Nov 15, 2024
@akien-mga
Copy link
Member

I think #98751 was wrongly flagged as being the issue this solves, though I need to see if I can reproduce it to confirm.

This seems to be solving a very recent regression in master which is tracked in #99249. This one is reproducible for me in latest master but not 4.4-dev4 or 4.3-stable, and fixed by this PR.

@akien-mga
Copy link
Member

Confirmed to be fixed a bug introduced by #97415 so it's not fixing #98751.

@Repiteo Repiteo merged commit a52e284 into godotengine:master Nov 15, 2024
20 checks passed
@Repiteo
Copy link
Contributor

Repiteo commented Nov 15, 2024

Thanks! Congratulations on your first contribution! 🎉

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.

Crash on clicking Animation track key.
7 participants