bevy icon indicating copy to clipboard operation
bevy copied to clipboard

Headless renderer example has been added

Open bugsweeper opened this issue 1 year ago • 5 comments
trafficstars

Objective

Fixes #11457.

Solution

Based on another headless application


Changelog

bugsweeper avatar Apr 17 '24 11:04 bugsweeper

@alice-i-cecile May I ask you for a review?

bugsweeper avatar Apr 17 '24 12:04 bugsweeper

@IceSentry , may I ask you for a rereview?

bugsweeper avatar Apr 25 '24 09:04 bugsweeper

could you add objects to the scene, so that it doesn't render just a black picture?

the example panics for me:


Adding CaptureFramePlugin
Saving image to: "bevy/test_images"
thread 'Compute Task Pool (3)' panicked at examples/app/headless_renderer.rs:300:22:
Failed to send data to main world: "SendError(..)"
stack backtrace:
   0: rust_begin_unwind
             at /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04/library/std/src/panicking.rs:647:5
   1: core::panicking::panic_fmt
             at /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04/library/core/src/panicking.rs:72:14
   2: core::result::unwrap_failed
             at /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04/library/core/src/result.rs:1649:5
   3: core::result::Result<T,E>::expect
             at /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04/library/core/src/result.rs:1030:23
   4: headless_renderer::frame_capture::image_copy::receive_image_from_buffer
             at ./examples/app/headless_renderer.rs:298:17
   5: core::ops::function::FnMut::call_mut
             at /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04/library/core/src/ops/function.rs:166:5
   6: core::ops::function::impls::<impl core::ops::function::FnMut<A> for &mut F>::call_mut
             at /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04/library/core/src/ops/function.rs:294:13
   7: <Func as bevy_ecs::system::function_system::SystemParamFunction<fn(F0,F1,F2) .> Out>>::run::call_inner
             at ./crates/bevy_ecs/src/system/function_system.rs:665:21
   8: <Func as bevy_ecs::system::function_system::SystemParamFunction<fn(F0,F1,F2) .> Out>>::run
             at ./crates/bevy_ecs/src/system/function_system.rs:668:17
   9: <bevy_ecs::system::function_system::FunctionSystem<Marker,F> as bevy_ecs::system::system::System>::run_unsafe
             at ./crates/bevy_ecs/src/system/function_system.rs:507:19
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
Encountered a panic in system `headless_renderer::frame_capture::image_copy::receive_image_from_buffer`!

Is it possible to not surface that panic?

mockersf avatar Apr 27 '24 13:04 mockersf

thread 'Compute Task Pool (3)' panicked at examples/app/headless_renderer.rs:300:22: Failed to send data to main world: "SendError(..)" Is it possible to not surface that panic?

The reason of this panic is attempt to send image data to nonexistent receiver, because MainWorld destroyed while RenderWorld still renders. For such case I left comment // This could fail on app exit, if Main world clears resources while Render world still renders Simple solution is ignoring Result of that send (there is .expect("...") now), more complex solution is to notify RenderWorld that an exit event has emitted, may be via some Atomic<bool>.

bugsweeper avatar Apr 29 '24 09:04 bugsweeper

@mockersf May I ask you for a rereview?

bugsweeper avatar Apr 29 '24 16:04 bugsweeper

@alice-i-cecile Looks like no one dares to approve, but there are no more changes requested left. We are stuck. Can you invite some one else?

bugsweeper avatar May 05 '24 18:05 bugsweeper

Yeah, I'll ask around :) There's been a long history of subtle challenges with headless rendering, so I suspect that's driving the difficulty.

alice-i-cecile avatar May 05 '24 19:05 alice-i-cecile

@bugsweeper those suggestions look solid, but once CI is green I'll merge this in either way :)

alice-i-cecile avatar May 05 '24 21:05 alice-i-cecile

@mockersf May I ask you for a rereview?

bugsweeper avatar May 06 '24 04:05 bugsweeper

@alice-i-cecile Ci is green now

bugsweeper avatar May 06 '24 07:05 bugsweeper