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

Randomly hitting crash on exit with bevy 0.13 #57

Closed
martinlindhe opened this issue Mar 19, 2024 · 4 comments · Fixed by #58
Closed

Randomly hitting crash on exit with bevy 0.13 #57

martinlindhe opened this issue Mar 19, 2024 · 4 comments · Fixed by #58
Labels
bug Something isn't working

Comments

@martinlindhe
Copy link

martinlindhe commented Mar 19, 2024

Backgrond

I am using bevy_pancam 0.11 with bevy 0.13 on a project that I have recently been updating from bevy 0.12 and bevy_pancam 0.10.

Error description

After the update, I start to randomly see this error upon exiting, it seems to occur about half of the time when I exit the app:

thread 'Compute Task Pool (17)' panicked at /home/m/.cargo/registry/src/index.crates.io-6f17d22bba15001f/bevy_pancam-0.11.0/src/lib.rs:187:33:
called `Result::unwrap()` on an `Err` value: NoEntities("bevy_ecs::query::state::QueryState<&bevy_window::window::Window, bevy_ecs::query::filter::With<bevy_window::window::PrimaryWindow>>")
stack backtrace:
   0: rust_begin_unwind
             at /rustc/3c85e56249b0b1942339a6a989a971bf6f1c9e0f/library/std/src/panicking.rs:645:5
   1: core::panicking::panic_fmt
             at /rustc/3c85e56249b0b1942339a6a989a971bf6f1c9e0f/library/core/src/panicking.rs:72:14
   2: core::result::unwrap_failed
             at /rustc/3c85e56249b0b1942339a6a989a971bf6f1c9e0f/library/core/src/result.rs:1654:5
   3: core::result::Result<T,E>::unwrap
             at /rustc/3c85e56249b0b1942339a6a989a971bf6f1c9e0f/library/core/src/result.rs:1077:23
   4: bevy_ecs::system::query::Query<D,F>::single
             at /home/m/.cargo/registry/src/index.crates.io-6f17d22bba15001f/bevy_ecs-0.13.1/src/system/query.rs:1307:9
   5: bevy_pancam::camera_movement
             at /home/m/.cargo/registry/src/index.crates.io-6f17d22bba15001f/bevy_pancam-0.11.0/src/lib.rs:187:18
   6: core::ops::function::FnMut::call_mut
             at /rustc/3c85e56249b0b1942339a6a989a971bf6f1c9e0f/library/core/src/ops/function.rs:166:5
   7: core::ops::function::impls::<impl core::ops::function::FnMut<A> for &mut F>::call_mut
             at /rustc/3c85e56249b0b1942339a6a989a971bf6f1c9e0f/library/core/src/ops/function.rs:294:13
   8: <Func as bevy_ecs::system::function_system::SystemParamFunction<fn(F0,F1,F2,F3) .> Out>>::run::call_inner
             at /home/m/.cargo/registry/src/index.crates.io-6f17d22bba15001f/bevy_ecs-0.13.1/src/system/function_system.rs:656:21
   9: <Func as bevy_ecs::system::function_system::SystemParamFunction<fn(F0,F1,F2,F3) .> Out>>::run
             at /home/m/.cargo/registry/src/index.crates.io-6f17d22bba15001f/bevy_ecs-0.13.1/src/system/function_system.rs:659:17
  10: <bevy_ecs::system::function_system::FunctionSystem<Marker,F> as bevy_ecs::system::system::System>::run_unsafe
             at /home/m/.cargo/registry/src/index.crates.io-6f17d22bba15001f/bevy_ecs-0.13.1/src/system/function_system.rs:499:19
  11: bevy_ecs::schedule::executor::multi_threaded::MultiThreadedExecutor::spawn_system_task::{{closure}}::{{closure}}
             at /home/m/.cargo/registry/src/index.crates.io-6f17d22bba15001f/bevy_ecs-0.13.1/src/schedule/executor/multi_threaded.rs:534:26
  12: core::ops::function::FnOnce::call_once
             at /rustc/3c85e56249b0b1942339a6a989a971bf6f1c9e0f/library/core/src/ops/function.rs:250:5
  13: <core::panic::unwind_safe::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once
             at /rustc/3c85e56249b0b1942339a6a989a971bf6f1c9e0f/library/core/src/panic/unwind_safe.rs:272:9
  14: std::panicking::try::do_call
             at /rustc/3c85e56249b0b1942339a6a989a971bf6f1c9e0f/library/std/src/panicking.rs:552:40
  15: std::panicking::try
             at /rustc/3c85e56249b0b1942339a6a989a971bf6f1c9e0f/library/std/src/panicking.rs:516:19
  16: std::panic::catch_unwind
             at /rustc/3c85e56249b0b1942339a6a989a971bf6f1c9e0f/library/std/src/panic.rs:146:14
  17: bevy_ecs::schedule::executor::multi_threaded::MultiThreadedExecutor::spawn_system_task::{{closure}}
             at /home/m/.cargo/registry/src/index.crates.io-6f17d22bba15001f/bevy_ecs-0.13.1/src/schedule/executor/multi_threaded.rs:529:23
  18: <core::panic::unwind_safe::AssertUnwindSafe<F> as core::future::future::Future>::poll
             at /rustc/3c85e56249b0b1942339a6a989a971bf6f1c9e0f/library/core/src/panic/unwind_safe.rs:297:9
  19: <futures_lite::future::CatchUnwind<F> as core::future::future::Future>::poll::{{closure}}
             at /home/m/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-lite-2.3.0/src/future.rs:588:42
  20: <core::panic::unwind_safe::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once
             at /rustc/3c85e56249b0b1942339a6a989a971bf6f1c9e0f/library/core/src/panic/unwind_safe.rs:272:9
  21: std::panicking::try::do_call
             at /rustc/3c85e56249b0b1942339a6a989a971bf6f1c9e0f/library/std/src/panicking.rs:552:40
  22: std::panicking::try
             at /rustc/3c85e56249b0b1942339a6a989a971bf6f1c9e0f/library/std/src/panicking.rs:516:19
  23: std::panic::catch_unwind
             at /rustc/3c85e56249b0b1942339a6a989a971bf6f1c9e0f/library/std/src/panic.rs:146:14
  24: <futures_lite::future::CatchUnwind<F> as core::future::future::Future>::poll
             at /home/m/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-lite-2.3.0/src/future.rs:588:9
  25: async_executor::Executor::spawn::{{closure}}
             at /home/m/.cargo/registry/src/index.crates.io-6f17d22bba15001f/async-executor-1.8.0/src/lib.rs:158:20
  26: async_task::raw::RawTask<F,T,S,M>::run::{{closure}}
             at /home/m/.cargo/registry/src/index.crates.io-6f17d22bba15001f/async-task-4.7.0/src/raw.rs:550:21
  27: core::ops::function::FnOnce::call_once
             at /rustc/3c85e56249b0b1942339a6a989a971bf6f1c9e0f/library/core/src/ops/function.rs:250:5
  28: <core::panic::unwind_safe::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once
             at /rustc/3c85e56249b0b1942339a6a989a971bf6f1c9e0f/library/core/src/panic/unwind_safe.rs:272:9
  29: std::panicking::try::do_call
             at /rustc/3c85e56249b0b1942339a6a989a971bf6f1c9e0f/library/std/src/panicking.rs:552:40
  30: std::panicking::try
             at /rustc/3c85e56249b0b1942339a6a989a971bf6f1c9e0f/library/std/src/panicking.rs:516:19
  31: std::panic::catch_unwind
             at /rustc/3c85e56249b0b1942339a6a989a971bf6f1c9e0f/library/std/src/panic.rs:146:14
  32: async_task::raw::RawTask<F,T,S,M>::run
             at /home/m/.cargo/registry/src/index.crates.io-6f17d22bba15001f/async-task-4.7.0/src/raw.rs:549:23
  33: async_task::runnable::Runnable<M>::run
             at /home/m/.cargo/registry/src/index.crates.io-6f17d22bba15001f/async-task-4.7.0/src/runnable.rs:781:18
  34: async_executor::Executor::run::{{closure}}::{{closure}}
             at /home/m/.cargo/registry/src/index.crates.io-6f17d22bba15001f/async-executor-1.8.0/src/lib.rs:254:21
  35: <futures_lite::future::Or<F1,F2> as core::future::future::Future>::poll
             at /home/m/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-lite-2.3.0/src/future.rs:449:33
  36: async_executor::Executor::run::{{closure}}
             at /home/m/.cargo/registry/src/index.crates.io-6f17d22bba15001f/async-executor-1.8.0/src/lib.rs:261:32
  37: futures_lite::future::block_on::{{closure}}
             at /home/m/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-lite-2.3.0/src/future.rs:99:19
  38: std::thread::local::LocalKey<T>::try_with
             at /rustc/3c85e56249b0b1942339a6a989a971bf6f1c9e0f/library/std/src/thread/local.rs:284:16
  39: std::thread::local::LocalKey<T>::with
             at /rustc/3c85e56249b0b1942339a6a989a971bf6f1c9e0f/library/std/src/thread/local.rs:260:9
  40: futures_lite::future::block_on
             at /home/m/.cargo/registry/src/index.crates.io-6f17d22bba15001f/futures-lite-2.3.0/src/future.rs:78:11
  41: bevy_tasks::task_pool::TaskPool::new_internal::{{closure}}::{{closure}}::{{closure}}::{{closure}}
             at /home/m/.cargo/registry/src/index.crates.io-6f17d22bba15001f/bevy_tasks-0.13.1/src/task_pool.rs:180:37
  42: std::panicking::try::do_call
             at /rustc/3c85e56249b0b1942339a6a989a971bf6f1c9e0f/library/std/src/panicking.rs:552:40
  43: std::panicking::try
             at /rustc/3c85e56249b0b1942339a6a989a971bf6f1c9e0f/library/std/src/panicking.rs:516:19
  44: std::panic::catch_unwind
             at /rustc/3c85e56249b0b1942339a6a989a971bf6f1c9e0f/library/std/src/panic.rs:146:14
  45: bevy_tasks::task_pool::TaskPool::new_internal::{{closure}}::{{closure}}::{{closure}}
             at /home/m/.cargo/registry/src/index.crates.io-6f17d22bba15001f/bevy_tasks-0.13.1/src/task_pool.rs:174:43
  46: std::thread::local::LocalKey<T>::try_with
             at /rustc/3c85e56249b0b1942339a6a989a971bf6f1c9e0f/library/std/src/thread/local.rs:284:16
  47: std::thread::local::LocalKey<T>::with
             at /rustc/3c85e56249b0b1942339a6a989a971bf6f1c9e0f/library/std/src/thread/local.rs:260:9
  48: bevy_tasks::task_pool::TaskPool::new_internal::{{closure}}::{{closure}}
             at /home/m/.cargo/registry/src/index.crates.io-6f17d22bba15001f/bevy_tasks-0.13.1/src/task_pool.rs:167:50
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

This is how I am exiting my bevy app:

fn menu_keys(
    kbd: Res<ButtonInput<KeyCode>>,
    mut app_exit_events: EventWriter<AppExit>,
) {
    if kbd.just_pressed(KeyCode::Escape) {
        app_exit_events.send(AppExit);
    }
}

I did not notice this error triggering with bevy 0.12 / bevy_pancam 0.10

@tomara-x
Copy link
Contributor

this used to also happen in bevy 0.12, but so much less frequent than it does in 0.13
i wanted to fix it for a while, but wasn't sure if this 1 is the best way to handle it, or if this needs to be addressed in bevy. like, is it normal that there is no window for a little while before the app exits?

Footnotes

  1. https://github.com/tomara-x/bevy_pancam/commit/a559b069afee87102489af22d91a48f5298976b8?diff=unified&w=1

@martinlindhe
Copy link
Author

martinlindhe commented Mar 20, 2024

this used to also happen in bevy 0.12, but so much less frequent than it does in 0.13 i wanted to fix it for a while, but wasn't sure if this 1 is the best way to handle it, or if this needs to be addressed in bevy. like, is it normal that there is no window for a little while before the app exits?

Footnotes

1. https://github.com/tomara-x/bevy_pancam/commit/a559b069afee87102489af22d91a48f5298976b8?diff=unified&w=1 [↩](#user-content-fnref-1-4e5f80201c35cd730fec38eb505f0592)

I don't know if its normal of bevy to exit like this now :-/
I didn't consider to try on other OS:es, I am currently hitting the issue on Linux with bevy/wayland feature.

Your patch fixes the issue fully for me!

EDIT: tried on macOS but I cannot reproduce this bug on macOS.

@tomara-x
Copy link
Contributor

interesting! i haven't thought about that. for me it happens on linux with x11

@tomara-x
Copy link
Contributor

got confirmation that we should use get_single, will open a pr

@johanhelsing johanhelsing added the bug Something isn't working label Mar 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants