Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions _release-content/release-notes/render-recovery.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: "Render Recovery"
authors: ["@atlv24"]
pull_requests: [22761, 23350, 23349, 23433, 23458, 23444, 23459, 23461, 23463, 22714, 22759, 16481]
pull_requests: [22761, 23350, 23349, 23433, 23458, 23444, 23459, 23461, 23463, 22714, 22759, 16481, 24131]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm working on revising the release notes right now, and have pre-emptively included this PR. Please just accept those changes when resolving conflicts.

---

You can now recover from rendering errors such as device loss by reloading the renderer:
Expand All @@ -21,4 +21,4 @@ app.insert_resource(RenderErrorHandler(

NOTE: this is just an example showing the different errors and policies available, and not a recommendation for how to handle errors.

The default error handler behaves identically to how Bevy behaved before: validation errors are ignored, and other errors crash/hang the application.
The default error handler will quit the application on any RenderError.
Comment thread
kfc35 marked this conversation as resolved.
Outdated
17 changes: 14 additions & 3 deletions crates/bevy_render/src/error_handler.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use alloc::sync::Arc;
use bevy_app::AppExit;
use bevy_ecs::{
resource::Resource,
world::{Mut, World},
Expand Down Expand Up @@ -26,6 +27,8 @@ pub enum RenderErrorPolicy {
StopRendering,
/// Attempt renderer recovery with the given [`RenderCreation`].
Recover(RenderCreation),
/// Quits the app.
Comment thread
kfc35 marked this conversation as resolved.
Outdated
QuitApplication,
}

/// Determines what [`RenderErrorPolicy`] should be used to respond to a given [`RenderError`].
Expand All @@ -50,6 +53,9 @@ impl RenderErrorHandler {
RenderErrorPolicy::StopRendering => {
// do nothing
}
RenderErrorPolicy::QuitApplication => {
main_world.write_message(AppExit::error());
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ugh, we only get a u8 to embed error information.

}
Comment thread
kfc35 marked this conversation as resolved.
Outdated
RenderErrorPolicy::Recover(render_creation) => {
assert!(insert_future_resources(&render_creation, main_world));
render_world.insert_resource(RenderState::Reinitializing);
Expand All @@ -60,9 +66,14 @@ impl RenderErrorHandler {

impl Default for RenderErrorHandler {
fn default() -> Self {
// This is what we've always done historically,
// but we could choose a new default once recovery works better.
Self(|_, _, _| RenderErrorPolicy::Ignore)
// Quit the application for any `RenderError`.
// Especially for OOM's and Validation RenderErrors, ignoring the error
// and resuming render can cause a loop that can cause hazardous strobing effects.
// We can choose a new default once recovery works better.
Self(|error, _, _| {
bevy_log::error!("Quitting the application due to {:?} RenderError", error.ty);
RenderErrorPolicy::QuitApplication
Comment thread
kfc35 marked this conversation as resolved.
Outdated
})
}
}

Expand Down