Missing graph blocks other animation events non-deterministically

Open Beginner friendly
#26,637 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 2 days

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
72/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
rust
Domain
game-dev

Research direction

The bug is in trigger_untargeted_animation_events in crates/bevy_animation/src/lib.rs, where a return inside the per-player loop exits early when a graph is missing. Run the reproduction in the issue to see the healthy player's ping count change when a broken player is added. Switching that return to continue should fix it, and the regression test should check that one missing graph does not suppress other players' root events.

Written by the indexing model from the issue text.

Description

A-Animation AI-Assisted C-Bug D-Trivial S-Needs-Triage

Bevy version and features

0.20.1

[Optional] Relevant system information

osx, m1, msrv ...

Overview

crates/bevy_animation/src/lib.rs

in trigger_untargeted_animation_events, a missing graph causes an early return, causing animation events in other graphs to get skipped and lost.

    let Some(graph) = graphs.get(graph_id) else {
        return;   // exits the whole loop
    };
    ...```

This leads to circumstances where depending on the iteration order, for entities with graphs A, B, and C, if B is missing, C can get skipped... or for the order C, A, B, none get skipped. Hard to detect. 

Other functions in this file use `par_iter().for_each(|...|)` and return, which does NOT skip the following runs like a sequential loop does. 

Either switch iterators, or use `continue` instead of return. 
Potentially regression test this. 

## Reproduction

Short reproduction example 

```rust
//! One player whose graph isn't loaded stops *every* player's untargeted
//! (root) animation events, because `trigger_untargeted_animation_events`
//! uses `return` instead of `continue` when a graph is missing.

use std::time::Duration;

use bevy::{animation::AnimationEvent, prelude::*, time::TimeUpdateStrategy};

#[derive(AnimationEvent, Clone)]
struct Ping;

#[derive(Resource, Default)]
struct Pings(u32);

fn run(spawn_broken_player: bool) -> u32 {
    let mut app = App::new();
    app.add_plugins((MinimalPlugins, AssetPlugin::default(), AnimationPlugin))
        .insert_resource(TimeUpdateStrategy::ManualDuration(Duration::from_millis(50)))
        .init_resource::<Pings>()
        .add_observer(|_: On<Ping>, mut pings: ResMut<Pings>| pings.0 += 1);

    // A clip with one root event at 0.1s.
    let mut clip = AnimationClip::default();
    clip.set_duration(1.0);
    clip.add_event(0.1, Ping);
    let clip = app.world_mut().resource_mut::<Assets<AnimationClip>>().add(clip);
    let (graph, node) = AnimationGraph::from_clip(clip);
    let graph = app.world_mut().resource_mut::<Assets<AnimationGraph>>().add(graph);

    if spawn_broken_player {
        // A graph handle that points at nothing, like a graph still loading.
        app.world_mut()
            .spawn((AnimationPlayer::default(), AnimationGraphHandle(Handle::default())));
    }

    // A perfectly healthy player.
    let mut player = AnimationPlayer::default();
    player.play(node);
    app.world_mut().spawn((player, AnimationGraphHandle(graph)));

    // ~0.5s of playback: crosses the 0.1s event once.
    for _ in 0..10 {
        app.update();
    }
    app.world().resource::<Pings>().0
}

fn main() {
    let alone = run(false);
    let with_broken = run(true);
    println!("healthy player alone:              {alone} ping(s)");
    println!("healthy player + one broken player: {with_broken} ping(s)");
    if alone == with_broken {
        println!("OK: no bug.");
    } else {
        println!("BUG: the broken player suppressed the healthy player's events.");
        std::process::exit(1);
    }
}
AI Assisted

I used claude to find bugs in the animation library and write up a reproduction for this one.

Dominant language
Rust
Stars
49.8k
Forks
5.1k
Avg merge
3d 4h
Merged PRs (30d)
136

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from bevyengine/bevy

All issues in bevyengine/bevy

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.