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

index out of bounds : for animation_player, irregular bug #6204

Closed
pinkponk opened this issue Oct 8, 2022 · 5 comments
Closed

index out of bounds : for animation_player, irregular bug #6204

pinkponk opened this issue Oct 8, 2022 · 5 comments
Labels
A-Animation Make things move and change over time C-Bug An unexpected or incorrect behavior

Comments

@pinkponk
Copy link

pinkponk commented Oct 8, 2022

Bevy version

stable 0.8.0 release

AdapterInfo { name: "NVIDIA GeForce GTX 1080 Ti", vendor: 4318, device: 6918, device_type: DiscreteGpu, backend: Vulkan }

What you did

Running a bunch of gltf animations. I change speed, animation clip very often.

What went wrong

I get the panic error at random but after a while of running my game.

One of my animations is 111 long but the error have occurred on other animations as well.

Error:

thread 'Compute Task Pool (4)' panicked at 'index out of bounds: the len is 111 but the index is 111', /home/pinkponk/.cargo/registry/src/github.com-1ecc6299db9ec823/bevy_animation-0.8.1/src/lib.rs:252:38
thread 'main' panicked at 'task has failed', /home/pinkponk/.cargo/registry/src/github.com-1ecc6299db9ec823/async-task-4.3.0/src/task.rs:426:45

Additional information

Bevy code, animation_player

                        // Find the current keyframe
                        // PERF: finding the current keyframe can be optimised
                        let step_start = match curve
                            .keyframe_timestamps
                            .binary_search_by(|probe| probe.partial_cmp(&elapsed).unwrap())  <--- Problem probably here
                        {
                            Ok(i) => i, <-------------------------------------------------------------------------------- And here
                            Err(0) => continue, // this curve isn't started yet
                            Err(n) if n > curve.keyframe_timestamps.len() - 1 => continue, // this curve is finished
                            Err(i) => i - 1,
                        };
                        let ts_start = curve.keyframe_timestamps[step_start];
                        let ts_end = curve.keyframe_timestamps[step_start + 1]; <--------------------- Error here
                        let lerp = (elapsed - ts_start) / (ts_end - ts_start);

discord help thread: https://discord.com/channels/691052431525675048/1019697973933899910/threads/1026824382418522162

@pinkponk pinkponk added C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled labels Oct 8, 2022
@mockersf
Copy link
Member

mockersf commented Oct 8, 2022

would you have code to reproduce? maybe with the example many_foxes?

@mockersf mockersf added A-Animation Make things move and change over time and removed S-Needs-Triage This issue needs to be labelled labels Oct 8, 2022
@pinkponk
Copy link
Author

pinkponk commented Oct 8, 2022

This bug is irregular and does not always happen. I don't know how to exactly trigger it so I don't have code to reproduce. I can stop in the debugger automatically when the panic happens in vs code with lldb but I'm too noob to understand how to go up in the call stack and retrieve the variables such as the timestamps. I tried "rerun frame" in the debugger but the game just continues and stops at the break point without the error.

@pinkponk
Copy link
Author

pinkponk commented Oct 8, 2022

I tried to use the many_fox example and play around with but wasn't successful in recreating the bug there. I played around with the set_elapsed and even used my own model but to no avail.

@thebluefish
Copy link
Contributor

thebluefish commented Oct 9, 2022

I am able to reliably reproduce this bug in the animated_fox example with this replacement function:

fn keyboard_animation_control(
    keyboard_input: Res<Input<KeyCode>>,
    anims: Res<Animations>,
    time: Res<Time>,
    animations: Res<Assets<AnimationClip>>,
    mut animation_player: Query<&mut AnimationPlayer>,
) {
    if let Ok(mut player) = animation_player.get_single_mut() {
        // Trigger the bug
        if keyboard_input.just_pressed(KeyCode::Return) {
            player.play(anims.0[0].clone_weak());
            let duration = animations.get(&anims.0[0]).unwrap().duration();
            let elapsed = duration - time.delta_seconds() * player.speed(); // align the planets
            println!("duration {duration}, elapsed {elapsed}");
            player.set_elapsed(elapsed);
        }
    }
}

My understanding is that this can randomly occur, but it would be extremely rare.

Notably, this requires repeat to be false, otherwise it would modulo to 0 before this occurs.

@pinkponk
Copy link
Author

pinkponk commented Oct 9, 2022

Great and awesome! I now see that I forgot to turn off the repeat() when I tried to reproduce this.

@bors bors bot closed this as completed in c6e0da4 Oct 17, 2022
james7132 pushed a commit to james7132/bevy that referenced this issue Oct 19, 2022
# Objective

Fixes bevyengine#6204

## Solution

Added another branch to handle end-of-animation special case
james7132 pushed a commit to james7132/bevy that referenced this issue Oct 28, 2022
# Objective

Fixes bevyengine#6204

## Solution

Added another branch to handle end-of-animation special case
Pietrek14 pushed a commit to Pietrek14/bevy that referenced this issue Dec 17, 2022
# Objective

Fixes bevyengine#6204

## Solution

Added another branch to handle end-of-animation special case
ItsDoot pushed a commit to ItsDoot/bevy that referenced this issue Feb 1, 2023
# Objective

Fixes bevyengine#6204

## Solution

Added another branch to handle end-of-animation special case
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Animation Make things move and change over time C-Bug An unexpected or incorrect behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants