bevyengine / bevy

A refreshingly simple data-driven game engine built in Rust
https://bevyengine.org
Apache License 2.0
35.18k stars 3.47k forks source link

bevy_animation::animate_targets crashes with "subtract with overflow" if there is an empty curve on AnimationClip #14766

Open hukasu opened 1 month ago

hukasu commented 1 month ago

Bevy version

0.14.1

[Optional] Relevant system information

SystemInfo { os: "Linux 24.05 NixOS", kernel: "6.6.45", cpu: "Intel(R) Core(TM) i7-14700KF", core_count: "20", memory: "31.2 GiB" } AdapterInfo { name: "NVIDIA GeForce RTX 4060 Ti", vendor: 4318, device: 10243, device_type: DiscreteGpu, driver: "NVIDIA", driver_info: "550.78", backend: Vulkan }

What you did

Created an AnimationClip and added a curve to it with empty keyframe_timestamps and keyframes and attempted to play the clip.

What went wrong

Application crashed with "attempted to subtract with overflow", preferably it should warn that the VariableCurve was created with empty keyframe_timestamps and keyframes over crashing.

Additional information

Crash log, a bit mangled because there is multiple errors being printed in parallel

thread 'thread 'thread 'thread 'Compute Task Pool (16)Compute Task Pool (14)Compute Task Pool (15)Compute Task Pool (12)' panicked at ' panicked at ' panicked at ' panicked at /home/hukasu/.cargo/registry/src/index.crates.io-6f17d22bba15001f/bevy_animation-0.14.1/src/lib.rsthread 'thread '/home/hukasu/.cargo/registry/src/index.crates.io-6f17d22bba15001f/bevy_animation-0.14.1/src/lib.rs/home/hukasu/.cargo/registry/src/index.crates.io-6f17d22bba15001f/bevy_animation-0.14.1/src/lib.rs/home/hukasu/.cargo/registry/src/index.crates.io-6f17d22bba15001f/bevy_animation-0.14.1/src/lib.rs:Compute Task Pool (18)Compute Task Pool (10):::131thread '' panicked at Compute Task Pool (9)' panicked at 131131131:/home/hukasu/.cargo/registry/src/index.crates.io-6f17d22bba15001f/bevy_animation-0.14.1/src/lib.rs' panicked at /home/hukasu/.cargo/registry/src/index.crates.io-6f17d22bba15001f/bevy_animation-0.14.1/src/lib.rs:::/home/hukasu/.cargo/registry/src/index.crates.io-6f17d22bba15001f/bevy_animation-0.14.1/src/lib.rs:292929:131:
:
:
:131:attempt to subtract with overflow29131attempt to subtract with overflowattempt to subtract with overflow29:
:
:

29note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
:
attempt to subtract with overflow29:
attempt to subtract with overflow
:
attempt to subtract with overflow
attempt to subtract with overflow

Encountered a panic in system `bevy_animation::animate_targets`!
Encountered a panic in system `bevy_app::main_schedule::Main::run_main`!
thread '<unnamed>' panicked at /rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23/library/std/src/thread/local.rs:260:26:
cannot access a Thread Local Storage value during or after destruction: AccessError
fatal runtime error: failed to initiate panic, error 5
Aborted (core dumped)

Screenshot_20240815_162609

mweatherley commented 1 month ago

Theoretically fixed by #13105 if it gets merged.

hukasu commented 1 month ago

Just a little more info, I was migrating this code from 0.12 to 0.14.1 today, and this did not used to happen on 0.12, i pulled the version from before starting the migration and confirmed that in 0.12 this did not happen.

hukasu commented 2 weeks ago

I created a minimal test on both 0.14.1 and 0.15-dev and both panic with "subtract with overflow".

0.14.1 https://github.com/hukasu/bevy/blob/182872f2a2e497fe4c929fe0343e826e9f2b3e93/tests/empty_variable_curve.rs#L22-L103

0.15-dev https://github.com/hukasu/bevy/blob/9378ead1fd43c549f6dcc6114a6afda202732c5b/tests/empty_variable_curve.rs#L22-L103

hukasu commented 2 weeks ago

with @mweatherley 's pull request, the curve properly requests 2 or more samples

https://github.com/hukasu/bevy/blob/0f509e1af5ccc8c2a8f05e8aa590fc279dcfe203/tests/empty_variable_curve.rs#L22-L98