-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Fix AnimationTargetId collisions
#22876
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 AnimationTargetId collisions
#22876
Conversation
…matches the original suggestion.
| } | ||
| } | ||
|
|
||
| // Test that `from_iter` is equivalent to `from_names`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test might not be justified. I originally added it because from_iter and from_names had different implementations. But later on I refactored them to share the same implementation.
|
instead of |
I think that would be less safe, although only slightly. It's difficult to construct a |
Objective
Fixes #22842. TLDR:
AnimationTargetId::from_iterwrongly returns the same id for["ab"]and["a", "b"].Solution
As suggested in the issue, add the length of each string to the hash. The original suggestion used
to_be_bytes, but I usedto_le_byteson the assumption that most users are targeting LE and this will be more efficient.0xffu8after each string instead of the length.AnimationTargetId::from_namesto reuseAnimationTargetId::from_iter.Testing
cargo test -p bevy_animation cargo run --example animated_mesh cargo run --example animated_mesh_events cargo run --example animation_masks