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

render_to_texture example crashes with other texture sizes #4127

Closed
dtaralla opened this issue Mar 7, 2022 · 3 comments
Closed

render_to_texture example crashes with other texture sizes #4127

dtaralla opened this issue Mar 7, 2022 · 3 comments
Labels
A-Rendering Drawing game state to the screen C-Bug An unexpected or incorrect behavior

Comments

@dtaralla
Copy link
Contributor

dtaralla commented Mar 7, 2022

Bevy version

main branch, rev b6a647cc

Operating system & version

Windows 11

What you did

  1. Run render_to_texture.rs; notice it works correctly.
  2. Modify render_to_texture.rs by modifying the size in setup():
    ...
    let size = Extent3d {
        width: 60, 
        height: 60,
        // or 128x128, or 32x32, or 100x100,...
        ..default()
    };
    ...
  1. Run render_to_texture.rs

What you expected to happen

It should not have crashed and just use another texture size.

What actually happened

It crashes after step 3 as soon as the app starts with this error/callstack:

thread 'main' panicked at 'assertion failed: self.axis_slices.x * self.axis_slices.y * self.axis_slices.z <= 4096', C:\Users\david\.cargo\git\checkouts\bevy-f7ffde730c324c74\b6a647c\crates\bevy_pbr\src\light.rs:257:9
stack backtrace:
  ... panic stuff ...
  15:     0x7ff733486f8c - core::panicking::panic
                               at /rustc/3b348d932aa5c9884310d025cf7c516023fd0d9a\/library\core\src\panicking.rs:48
  16:     0x7ff731e8d288 - bevy_pbr::light::Clusters::update
                               at C:\Users\david\.cargo\git\checkouts\bevy-f7ffde730c324c74\b6a647c\crates\bevy_pbr\src\light.rs:257
  17:     0x7ff731e8cbbb - bevy_pbr::light::Clusters::new
                               at C:\Users\david\.cargo\git\checkouts\bevy-f7ffde730c324c74\b6a647c\crates\bevy_pbr\src\light.rs:232
  18:     0x7ff731e8cf03 - bevy_pbr::light::Clusters::from_screen_size_and_z_slices
                               at C:\Users\david\.cargo\git\checkouts\bevy-f7ffde730c324c74\b6a647c\crates\bevy_pbr\src\light.rs:246
  19:     0x7ff731e8fece - bevy_pbr::light::add_clusters
                               at C:\Users\david\.cargo\git\checkouts\bevy-f7ffde730c324c74\b6a647c\crates\bevy_pbr\src\light.rs:365
  20:     0x7ff731e01229 - core::ops::function::FnMut::call_mut<void (*)(bevy_ecs::system::commands::Commands,bevy_ecs::system::system_param::Res<bevy_window::windows::Windows>,bevy_ecs::system::system_param::Res<bevy_asset::assets::Assets<bevy_render::texture::image::Image> >,bevy
                               at /rustc/3b348d932aa5c9884310d025cf7c516023fd0d9a\library\core\src\ops\function.rs:150
  21:     0x7ff731e9bdbb - core::ops::function::impls::impl$3::call_mut<tuple$<bevy_ecs::system::commands::Commands,bevy_ecs::system::system_param::Res<bevy_window::windows::Windows>,bevy_ecs::system::system_param::Res<bevy_asset::assets::Assets<bevy_render::texture::image::Image> 
                               at /rustc/3b348d932aa5c9884310d025cf7c516023fd0d9a\library\core\src\ops\function.rs:269
  22:     0x7ff731e47283 - bevy_ecs::system::function_system::impl$14::run::call_inner<tuple$<>,bevy_ecs::system::commands::Commands,bevy_ecs::system::system_param::Res<bevy_window::windows::Windows>,bevy_ecs::system::system_param::Res<bevy_asset::assets::Assets<bevy_render::textur
                               at C:\Users\david\.cargo\git\checkouts\bevy-f7ffde730c324c74\b6a647c\crates\bevy_ecs\src\system\function_system.rs:537
  23:     0x7ff731ea16c2 - bevy_ecs::system::function_system::impl$14::run<tuple$<>,void (*)(bevy_ecs::system::commands::Commands,bevy_ecs::system::system_param::Res<bevy_window::windows::Windows>,bevy_ecs::system::system_param::Res<bevy_asset::assets::Assets<bevy_render::texture::
                               at C:\Users\david\.cargo\git\checkouts\bevy-f7ffde730c324c74\b6a647c\crates\bevy_ecs\src\system\function_system.rs:540
  24:     0x7ff731e42d8a - bevy_ecs::system::function_system::impl$5::run_unsafe<tuple$<>,tuple$<>,tuple$<bevy_ecs::system::commands::Commands,bevy_ecs::system::system_param::Res<bevy_window::windows::Windows>,bevy_ecs::system::system_param::Res<bevy_asset::assets::Assets<bevy_rend
                               at C:\Users\david\.cargo\git\checkouts\bevy-f7ffde730c324c74\b6a647c\crates\bevy_ecs\src\system\function_system.rs:468
  25:     0x7ff731e45b23 - bevy_ecs::system::system::System::run<bevy_ecs::system::function_system::FunctionSystem<tuple$<>,tuple$<>,tuple$<bevy_ecs::system::commands::Commands,bevy_ecs::system::system_param::Res<bevy_window::windows::Windows>,bevy_ecs::system::system_param::Res<be
                               at C:\Users\david\.cargo\git\checkouts\bevy-f7ffde730c324c74\b6a647c\crates\bevy_ecs\src\system\system.rs:53
  26:     0x7ff7332b2e05 - bevy_ecs::system::exclusive_system::impl$2::run
                               at C:\Users\david\.cargo\git\checkouts\bevy-f7ffde730c324c74\b6a647c\crates\bevy_ecs\src\system\exclusive_system.rs:91
  27:     0x7ff7332b1c1a - bevy_ecs::schedule::stage::impl$1::run
                               at C:\Users\david\.cargo\git\checkouts\bevy-f7ffde730c324c74\b6a647c\crates\bevy_ecs\src\schedule\stage.rs:845
  28:     0x7ff73327a1ba - bevy_ecs::schedule::Schedule::run_once
                               at C:\Users\david\.cargo\git\checkouts\bevy-f7ffde730c324c74\b6a647c\crates\bevy_ecs\src\schedule\mod.rs:343
  29:     0x7ff73327a225 - bevy_ecs::schedule::impl$1::run
                               at C:\Users\david\.cargo\git\checkouts\bevy-f7ffde730c324c74\b6a647c\crates\bevy_ecs\src\schedule\mod.rs:361
  30:     0x7ff733223c56 - bevy_app::app::App::update
                               at C:\Users\david\.cargo\git\checkouts\bevy-f7ffde730c324c74\b6a647c\crates\bevy_app\src\app.rs:115
  31:     0x7ff73178dc68 - bevy_winit::winit_runner_with::closure$1
                               at C:\Users\david\.cargo\git\checkouts\bevy-f7ffde730c324c74\b6a647c\crates\bevy_winit\src\lib.rs:512
  32:     0x7ff7317e1b91 - winit::platform_impl::platform::event_loop::impl$2::run_return::closure$0<tuple$<>,bevy_winit::winit_runner_with::closure_env$1>
                               at C:\Users\david\.cargo\registry\src\github.com-1ecc6299db9ec823\winit-0.26.1\src\platform_impl\windows\event_loop.rs:206
  33:     0x7ff731836d14 - alloc::boxed::impl$45::call_mut<tuple$<enum$<winit::event::Event<tuple$<> > >,ref_mut$<enum$<winit::event_loop::ControlFlow> > >,dyn$<core::ops::function::FnMut<tuple$<enum$<winit::event::Event<tuple$<> > >,ref_mut$<enum$<winit::event_loop::ControlFlow> >
                               at /rustc/3b348d932aa5c9884310d025cf7c516023fd0d9a\library\alloc\src\boxed.rs:1861
  34:     0x7ff73183eb73 - winit::platform_impl::platform::event_loop::runner::impl$3::call_event_handler::closure$0<tuple$<> >
                               at C:\Users\david\.cargo\registry\src\github.com-1ecc6299db9ec823\winit-0.26.1\src\platform_impl\windows\event_loop\runner.rs:245
  35:     0x7ff731822314 - core::panic::unwind_safe::impl$23::call_once<tuple$<>,winit::platform_impl::platform::event_loop::runner::impl$3::call_event_handler::closure_env$0<tuple$<> > >
                               at /rustc/3b348d932aa5c9884310d025cf7c516023fd0d9a\library\core\src\panic\unwind_safe.rs:271
  36:     0x7ff731838851 - std::panicking::try::do_call<core::panic::unwind_safe::AssertUnwindSafe<winit::platform_impl::platform::event_loop::runner::impl$3::call_event_handler::closure_env$0<tuple$<> > >,tuple$<> >
                               at /rustc/3b348d932aa5c9884310d025cf7c516023fd0d9a\library\std\src\panicking.rs:492
  37:     0x7ff731838b43 - std::panicking::panicking
  38:     0x7ff73183874b - std::panicking::try<tuple$<>,core::panic::unwind_safe::AssertUnwindSafe<winit::platform_impl::platform::event_loop::runner::impl$3::call_event_handler::closure_env$0<tuple$<> > > >
                               at /rustc/3b348d932aa5c9884310d025cf7c516023fd0d9a\library\std\src\panicking.rs:456
  39:     0x7ff731810c04 - std::panic::catch_unwind<core::panic::unwind_safe::AssertUnwindSafe<winit::platform_impl::platform::event_loop::runner::impl$3::call_event_handler::closure_env$0<tuple$<> > >,tuple$<> >
                               at /rustc/3b348d932aa5c9884310d025cf7c516023fd0d9a\library\std\src\panic.rs:137
  40:     0x7ff73183dc72 - winit::platform_impl::platform::event_loop::runner::EventLoopRunner<tuple$<> >::catch_unwind<tuple$<>,tuple$<>,winit::platform_impl::platform::event_loop::runner::impl$3::call_event_handler::closure_env$0<tuple$<> > >
                               at C:\Users\david\.cargo\registry\src\github.com-1ecc6299db9ec823\winit-0.26.1\src\platform_impl\windows\event_loop\runner.rs:152
  41:     0x7ff73183e903 - winit::platform_impl::platform::event_loop::runner::EventLoopRunner<tuple$<> >::call_event_handler<tuple$<> >
                               at C:\Users\david\.cargo\registry\src\github.com-1ecc6299db9ec823\winit-0.26.1\src\platform_impl\windows\event_loop\runner.rs:239
  42:     0x7ff73183f27c - winit::platform_impl::platform::event_loop::runner::EventLoopRunner<tuple$<> >::move_state_to<tuple$<> >
                               at C:\Users\david\.cargo\registry\src\github.com-1ecc6299db9ec823\winit-0.26.1\src\platform_impl\windows\event_loop\runner.rs:341
  43:     0x7ff73183e897 - winit::platform_impl::platform::event_loop::runner::EventLoopRunner<tuple$<> >::main_events_cleared<tuple$<> >
                               at C:\Users\david\.cargo\registry\src\github.com-1ecc6299db9ec823\winit-0.26.1\src\platform_impl\windows\event_loop\runner.rs:227
  44:     0x7ff73183266d - winit::platform_impl::platform::event_loop::flush_paint_messages<tuple$<> >
                               at C:\Users\david\.cargo\registry\src\github.com-1ecc6299db9ec823\winit-0.26.1\src\platform_impl\windows\event_loop.rs:726
  45:     0x7ff7317e92ed - winit::platform_impl::platform::event_loop::public_window_callback_inner::closure$0<tuple$<> >
                               at C:\Users\david\.cargo\registry\src\github.com-1ecc6299db9ec823\winit-0.26.1\src\platform_impl\windows\event_loop.rs:941
  46:     0x7ff7317b6427 - core::ops::function::FnOnce::call_once<winit::platform_impl::platform::event_loop::public_window_callback_inner::closure_env$0<tuple$<> >,tuple$<> >
                               at /rustc/3b348d932aa5c9884310d025cf7c516023fd0d9a\library\core\src\ops\function.rs:227
  47:     0x7ff7317aa041 - core::panic::unwind_safe::impl$23::call_once<isize,winit::platform_impl::platform::event_loop::public_window_callback_inner::closure_env$0<tuple$<> > >
                               at /rustc/3b348d932aa5c9884310d025cf7c516023fd0d9a\library\core\src\panic\unwind_safe.rs:271
  48:     0x7ff7317d9b90 - std::panicking::try::do_call<core::panic::unwind_safe::AssertUnwindSafe<winit::platform_impl::platform::event_loop::public_window_callback_inner::closure_env$0<tuple$<> > >,isize>
                               at /rustc/3b348d932aa5c9884310d025cf7c516023fd0d9a\library\std\src\panicking.rs:492
  49:     0x7ff7317d9e73 - std::sync::mpsc::SendError::constructor$0<enum$<core::result::Result<tuple$<>,enum$<winit::error::ExternalError, 1, 18446744073709551615, Os> > > >
  50:     0x7ff7317d993c - std::panicking::try<isize,core::panic::unwind_safe::AssertUnwindSafe<winit::platform_impl::platform::event_loop::public_window_callback_inner::closure_env$0<tuple$<> > > >
                               at /rustc/3b348d932aa5c9884310d025cf7c516023fd0d9a\library\std\src\panicking.rs:456
  51:     0x7ff7317a5eed - std::panic::catch_unwind<core::panic::unwind_safe::AssertUnwindSafe<winit::platform_impl::platform::event_loop::public_window_callback_inner::closure_env$0<tuple$<> > >,isize>
                               at /rustc/3b348d932aa5c9884310d025cf7c516023fd0d9a\library\std\src\panic.rs:137
  52:     0x7ff7317eabdc - winit::platform_impl::platform::event_loop::runner::EventLoopRunner<tuple$<> >::catch_unwind<tuple$<>,isize,winit::platform_impl::platform::event_loop::public_window_callback_inner::closure_env$0<tuple$<> > >
                               at C:\Users\david\.cargo\registry\src\github.com-1ecc6299db9ec823\winit-0.26.1\src\platform_impl\windows\event_loop\runner.rs:152
  53:     0x7ff7317e378c - winit::platform_impl::platform::event_loop::public_window_callback_inner<tuple$<> >
                               at C:\Users\david\.cargo\registry\src\github.com-1ecc6299db9ec823\winit-0.26.1\src\platform_impl\windows\event_loop.rs:2030
  54:     0x7ff7317e348d - winit::platform_impl::platform::event_loop::public_window_callback<tuple$<> >
                               at C:\Users\david\.cargo\registry\src\github.com-1ecc6299db9ec823\winit-0.26.1\src\platform_impl\windows\event_loop.rs:846
  55:     0x7ffa4b751c4c - CallWindowProcW
  56:     0x7ffa4b75179c - EnumChildWindows
  57:     0x7ffa4b764b4d - IsIconic
  58:     0x7ffa4c8e76a4 - KiUserCallbackDispatcher
  59:     0x7ffa4a2719b4 - NtUserDispatchMessage
  60:     0x7ffa4b750edd - DispatchMessageW
  61:     0x7ff7317e18b0 - winit::platform_impl::platform::event_loop::EventLoop<tuple$<> >::run_return<tuple$<>,bevy_winit::winit_runner_with::closure_env$1>
                               at C:\Users\david\.cargo\registry\src\github.com-1ecc6299db9ec823\winit-0.26.1\src\platform_impl\windows\event_loop.rs:221
  62:     0x7ff7317e16af - winit::platform_impl::platform::event_loop::EventLoop<tuple$<> >::run<tuple$<>,bevy_winit::winit_runner_with::closure_env$1>
                               at C:\Users\david\.cargo\registry\src\github.com-1ecc6299db9ec823\winit-0.26.1\src\platform_impl\windows\event_loop.rs:191
  63:     0x7ff7317cbba5 - winit::event_loop::EventLoop<tuple$<> >::run<tuple$<>,bevy_winit::winit_runner_with::closure_env$1>
                               at C:\Users\david\.cargo\registry\src\github.com-1ecc6299db9ec823\winit-0.26.1\src\event_loop.rs:154
  64:     0x7ff73178d275 - bevy_winit::run<bevy_winit::winit_runner_with::closure_env$1>
                               at C:\Users\david\.cargo\git\checkouts\bevy-f7ffde730c324c74\b6a647c\crates\bevy_winit\src\lib.rs:176
  65:     0x7ff73178d854 - bevy_winit::winit_runner_with
                               at C:\Users\david\.cargo\git\checkouts\bevy-f7ffde730c324c74\b6a647c\crates\bevy_winit\src\lib.rs:521
  66:     0x7ff73178d2e4 - bevy_winit::winit_runner
                               at C:\Users\david\.cargo\git\checkouts\bevy-f7ffde730c324c74\b6a647c\crates\bevy_winit\src\lib.rs:216
  67:     0x7ff7317b5dd3 - core::ops::function::Fn::call<void (*)(bevy_app::app::App),tuple$<bevy_app::app::App> >
                               at /rustc/3b348d932aa5c9884310d025cf7c516023fd0d9a\library\core\src\ops\function.rs:70
  68:     0x7ff733228cba - alloc::boxed::impl$46::call<tuple$<bevy_app::app::App>,dyn$<core::ops::function::Fn<tuple$<bevy_app::app::App>,assoc$<Output,tuple$<> > > >,alloc::alloc::Global>
                               at /rustc/3b348d932aa5c9884310d025cf7c516023fd0d9a\library\alloc\src\boxed.rs:1868
  69:     0x7ff733223e05 - bevy_app::app::App::run
                               at C:\Users\david\.cargo\git\checkouts\bevy-f7ffde730c324c74\b6a647c\crates\bevy_app\src\app.rs:133
  70:     0x7ff731779209 - render_to_texture::main
                               at E:\Dev\Rust\project_spacelift\examples\render_to_texture.rs:60
  71:     0x7ff73177f3ab - core::ops::function::FnOnce::call_once<void (*)(),tuple$<> >
                               at /rustc/3b348d932aa5c9884310d025cf7c516023fd0d9a\library\core\src\ops\function.rs:227
  72:     0x7ff7317764ab - std::sys_common::backtrace::__rust_begin_short_backtrace<void (*)(),tuple$<> >
                               at /rustc/3b348d932aa5c9884310d025cf7c516023fd0d9a\library\std\src\sys_common\backtrace.rs:122
  73:     0x7ff73177d961 - std::rt::lang_start::closure$0<tuple$<> >
                               at /rustc/3b348d932aa5c9884310d025cf7c516023fd0d9a\library\std\src\rt.rs:145
  74:     0x7ff733462bdf - core::ops::function::impls::impl$2::call_once
                               at /rustc/3b348d932aa5c9884310d025cf7c516023fd0d9a\library\core\src\ops\function.rs:259
  75:     0x7ff733462bdf - std::panicking::try::do_call
                               at /rustc/3b348d932aa5c9884310d025cf7c516023fd0d9a\/library\std\src\panicking.rs:492
  76:     0x7ff733462bdf - std::panicking::try
                               at /rustc/3b348d932aa5c9884310d025cf7c516023fd0d9a\/library\std\src\panicking.rs:456
  77:     0x7ff733462bdf - std::panic::catch_unwind
                               at /rustc/3b348d932aa5c9884310d025cf7c516023fd0d9a\/library\std\src\panic.rs:137
  78:     0x7ff733462bdf - std::rt::lang_start_internal::closure$2
                               at /rustc/3b348d932aa5c9884310d025cf7c516023fd0d9a\/library\std\src\rt.rs:128
  79:     0x7ff733462bdf - std::panicking::try::do_call
                               at /rustc/3b348d932aa5c9884310d025cf7c516023fd0d9a\/library\std\src\panicking.rs:492
  80:     0x7ff733462bdf - std::panicking::try
                               at /rustc/3b348d932aa5c9884310d025cf7c516023fd0d9a\/library\std\src\panicking.rs:456
  81:     0x7ff733462bdf - std::panic::catch_unwind
                               at /rustc/3b348d932aa5c9884310d025cf7c516023fd0d9a\/library\std\src\panic.rs:137
  82:     0x7ff733462bdf - std::rt::lang_start_internal
                               at /rustc/3b348d932aa5c9884310d025cf7c516023fd0d9a\/library\std\src\rt.rs:128
  83:     0x7ff73177d92f - std::rt::lang_start<tuple$<> >
                               at /rustc/3b348d932aa5c9884310d025cf7c516023fd0d9a\library\std\src\rt.rs:144
  84:     0x7ff73177bd76 - main
  85:     0x7ff733485200 - invoke_main
                               at d:\a01\_work\20\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:78
  86:     0x7ff733485200 - __scrt_common_main_seh
                               at d:\a01\_work\20\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288
  87:     0x7ffa4b9054e0 - BaseThreadInitThunk
  88:     0x7ffa4c84485b - RtlUserThreadStart
error: process didn't exit successfully: `target\debug\examples\render_to_texture.exe` (exit code: 101)

Additional information

You can try with other sizes, it happens very often. I found 64x64 was working without crashing, as well as 500x500 for some reason.

@dtaralla dtaralla added C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled labels Mar 7, 2022
@rparrett
Copy link
Contributor

rparrett commented Mar 7, 2022

The new example from #3597 also seems to cause this panic. Also the example from #3399. (but not the same issue as 3399)

@rparrett
Copy link
Contributor

rparrett commented Mar 7, 2022

Actually, this is the same panic from #3596

@HackerFoo
Copy link
Contributor

I have a fix in my branch, I'll try to get it in shape for a PR: HackerFoo@2e5d1a0

@HackerFoo HackerFoo self-assigned this Mar 7, 2022
@alice-i-cecile alice-i-cecile added A-Rendering Drawing game state to the screen and removed S-Needs-Triage This issue needs to be labelled labels Mar 7, 2022
@HackerFoo HackerFoo removed their assignment Mar 8, 2022
@bors bors bot closed this as completed in 5af7464 Mar 10, 2022
aevyrie pushed a commit to aevyrie/bevy that referenced this issue Jun 7, 2022
# Objective

fix cluster tilesize and tilecount calculations.
Fixes bevyengine#4127 & bevyengine#3596

## Solution

- calculate tilesize as smallest integers such that dimensions.xy() tiles will cover the screen
- calculate final dimensions as smallest integers such that final dimensions * tilesize will cover the screen

there is more cleanup that could be done in these functions. a future PR will likely remove the tilesize completely, so this is just a minimal change set to fix the current bug at small screen sizes

Co-authored-by: Carter Anderson <mcanders1@gmail.com>
ItsDoot pushed a commit to ItsDoot/bevy that referenced this issue Feb 1, 2023
# Objective

fix cluster tilesize and tilecount calculations.
Fixes bevyengine#4127 & bevyengine#3596

## Solution

- calculate tilesize as smallest integers such that dimensions.xy() tiles will cover the screen
- calculate final dimensions as smallest integers such that final dimensions * tilesize will cover the screen

there is more cleanup that could be done in these functions. a future PR will likely remove the tilesize completely, so this is just a minimal change set to fix the current bug at small screen sizes

Co-authored-by: Carter Anderson <mcanders1@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Rendering Drawing game state to the screen C-Bug An unexpected or incorrect behavior
Projects
None yet
4 participants