Missing graph blocks other animation events non-deterministically

Aperta Adatta ai principianti
#26,637 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
72/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
rust
Ambito
game-dev

Direzione di ricerca

Il bug si trova in trigger_untargeted_animation_events in crates/bevy_animation/src/lib.rs, dove un return all'interno del ciclo per player esce anticipatamente quando manca un graph. Esegui la riproduzione indicata nell'issue per vedere come cambia il numero di ping del player sano quando si aggiunge un player difettoso. Sostituire quel return con continue dovrebbe risolvere il problema, e il test di regressione dovrebbe verificare che un graph mancante non sopprima gli eventi root degli altri player.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
Rust
Stelle
49.8k
Fork
5.1k
Merge medio
3g 4h
PR unite (30g)
136

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di bevyengine/bevy

Tutte le issue di bevyengine/bevy

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.