Move render app init and extraction to separate plugin#22758
Open
kristoff3r wants to merge 7 commits intobevyengine:mainfrom
Open
Move render app init and extraction to separate plugin#22758kristoff3r wants to merge 7 commits intobevyengine:mainfrom
kristoff3r wants to merge 7 commits intobevyengine:mainfrom
Conversation
alice-i-cecile
approved these changes
Feb 5, 2026
Member
alice-i-cecile
left a comment
There was a problem hiding this comment.
I like separating these, and this appears to have been done correctly.
atlv24
reviewed
Feb 6, 2026
| /// We need both the main and render world to properly handle errors, so we wedge ourselves into [extract](bevy_app::SubApp::set_extract). | ||
| pub(crate) fn update_state(main_world: &mut World, render_world: &mut World) { | ||
| if let Some(error) = render_world.resource::<DeviceErrorHandler>().poll() { | ||
| if let Some(handler) = render_world.get_resource::<DeviceErrorHandler>() |
Contributor
There was a problem hiding this comment.
This is not quite right as it creates a possibility for a false default: removing the DeviceErrorHandler does not behave the same as DeviceErrorHandler::default(). Can you use .unwrap_or_default() instead, or better yet just not make this change and require the presence + init_resource?
atlv24
reviewed
Feb 6, 2026
Comment on lines
+106
to
+109
| /// The render recovery schedule. This schedule runs the [`Render`] schedule if | ||
| /// we are in [`RenderState::Ready`], and is otherwise hidden from users. | ||
| #[derive(ScheduleLabel, Debug, Hash, PartialEq, Eq, Clone)] | ||
| struct RenderRecovery; |
Contributor
There was a problem hiding this comment.
does this make sense to have in extract?
atlv24
reviewed
Feb 6, 2026
Comment on lines
+45
to
+65
| render_app.add_systems(RenderRecovery, move |world: &mut World| { | ||
| if matches!(world.resource::<RenderState>(), RenderState::Ready) { | ||
| world.run_schedule(Render); | ||
| } | ||
|
|
||
| // update the time and send it to the app world regardless of whether we render | ||
| let time_sender = world.resource::<TimeSender>(); | ||
| if let Err(error) = time_sender.0.try_send(Instant::now()) { | ||
| match error { | ||
| bevy_time::TrySendError::Full(_) => { | ||
| panic!( | ||
| "The TimeSender channel should always be empty during render. \ | ||
| You might need to add the bevy::core::time_system to your app." | ||
| ); | ||
| } | ||
| bevy_time::TrySendError::Disconnected(_) => { | ||
| // ignore disconnected errors, the main world probably just got dropped during shutdown | ||
| } | ||
| } | ||
| } | ||
| }); |
Contributor
There was a problem hiding this comment.
this doesn't feel like extract logic
atlv24
reviewed
Feb 6, 2026
| reset_render_asset_bytes_per_frame.in_set(RenderSystems::Cleanup), | ||
| ); | ||
| ), | ||
| ); |
Contributor
There was a problem hiding this comment.
Can you put the RenderRecovery init stuff here instead?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Objective
Currently in
bevy_renderthe renderer initialization (e.g. creating a surface, registering rendering systems) is very intertwined with setting up the extraction logic itself (e.g. how is data moved between the worlds, how are they kept in sync). This makes it harder to understand both things, and also makes it very hard to test the extraction logic, as you don't want to start the renderer in unit test.In the future this functionality might even be useful for the ECS outside
bevy_render, e.g. for custom renderers that want to use a render world, or for multi world setups.Solution
This PR splits out creation of the render subapp plus the extraction logic itself into
ExtractPlugin, and uses the new found flexibility to finally add a test for it.This is the first part in a series of PRs I plan to do to:
Testing
Added a test to show that extraction is working.
I also ran a bunch of examples requiring rendering and they still work.