Skip to content

Reduce panics in rendering code to facilitate render recovery#23349

Merged
alice-i-cecile merged 4 commits intobevyengine:mainfrom
atlv24:ad/dont-panic
Mar 16, 2026
Merged

Reduce panics in rendering code to facilitate render recovery#23349
alice-i-cecile merged 4 commits intobevyengine:mainfrom
atlv24:ad/dont-panic

Conversation

@atlv24
Copy link
Copy Markdown
Contributor

@atlv24 atlv24 commented Mar 13, 2026

Objective

  • Reduce panics in bevy renderer
  • Continuation of Render Recovery efforts Render Recovery #22761 (can't reinitialize if we panic. I hit every single one of these on the device lost path.)

Solution

  • Use early outs and error!s instead of hard panics.
  • If the panics are needed to maintain some kind of invariant, that should be documented. I don't see any comment saying they do, so I am assuming they do not. Correct me if I am wrong.

Testing

  • CI

@IQuick143 IQuick143 added A-Rendering Drawing game state to the screen P-Crash A sudden unexpected crash D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Needs-Review Needs reviewer attention (from anyone!) to move forward S-Needs-Testing Testing must be done before this is safe to merge labels Mar 13, 2026
@github-project-automation github-project-automation bot moved this to Needs SME Triage in Rendering Mar 13, 2026
@IQuick143 IQuick143 self-requested a review March 13, 2026 08:45
Copy link
Copy Markdown
Contributor

@BrennanPaciorek BrennanPaciorek left a comment

Choose a reason for hiding this comment

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

First review on this repo, sorry if my comments do not reflect an understanding of the error cases of the code.

Some of these will silently fail now instead of crashing the application, I think we should replace the unwrap removals on Result's with error tracing of some sort.

This is a first pass, so I plan to pull the changes down and familiarize myself with them little more before revisiting my own review.

Co-authored-by: Brennan Paciorek <50780403+BrennanPaciorek@users.noreply.github.com>
@alice-i-cecile alice-i-cecile added S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward S-Needs-Testing Testing must be done before this is safe to merge labels Mar 16, 2026
Copy link
Copy Markdown
Contributor

@IceSentry IceSentry left a comment

Choose a reason for hiding this comment

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

Tiny nitpick but LGTM

@mockersf
Copy link
Copy Markdown
Member

mockersf commented Mar 16, 2026

I like keeping panics for things that are Bevy responsibility to enforce. If it panics it's a Bevy bug. Panics make it a lot easier to catch issues in our tests.
But panics for user are not great...

Should we keep panics in debug builds? Or should we make CI fail if there are error logs?

@mockersf
Copy link
Copy Markdown
Member

Also please rename the PR to make it easier to read in the git log. The first objective would be better :)

@github-actions
Copy link
Copy Markdown
Contributor

The generated examples/README.md is out of sync with the example metadata in Cargo.toml or the example readme template. Please run cargo run -p build-templated-pages -- update examples to update it, and commit the file change.

@alice-i-cecile alice-i-cecile changed the title dont panic Reduce panics in rendering code to facilitate render recovery Mar 16, 2026
@alice-i-cecile alice-i-cecile disabled auto-merge March 16, 2026 20:09
Co-authored-by: IceSentry <IceSentry@users.noreply.github.com>
@jasmine-nominal
Copy link
Copy Markdown
Contributor

I like keeping them as debug_asserts, imo.

@alice-i-cecile alice-i-cecile added this pull request to the merge queue Mar 16, 2026
@atlv24
Copy link
Copy Markdown
Contributor Author

atlv24 commented Mar 16, 2026

The issue is that these get hit in the recovery path. So we'd be panicking instead of recovering. I don't agree with making them error!, but okay.

Merged via the queue into bevyengine:main with commit b6fdc05 Mar 16, 2026
38 checks passed
@github-project-automation github-project-automation bot moved this from Needs SME Triage to Done in Rendering Mar 16, 2026
@IceSentry
Copy link
Copy Markdown
Contributor

Yeah, we shouldn't treat these errors as panics any more than users should. If we want to panic on those errors IMO it should be the job of the render recovery handler. If devs want it to panic then set the handler to panic.

github-merge-queue bot pushed a commit that referenced this pull request Mar 23, 2026
# Objective

- Completes goal and closes #23029
- Culmination of #22761, #23350, #23349, #23433, #23458, #23444, #23459,
#23461, #23463, #22714, #22759, #16481

## Solution

- Add a release note.
- Re-export a wgpu type that you need to match on to handle errors.

## Testing

- cargo run --example render_recovery with all the other PRs merged in.
Press 5 and then V, the app will not crash. Note that D for "destroy
device" will still crash: this is a WGPU problem resolved by
gfx-rs/wgpu#9281.

# Note

I opted not to change the default recovery behavior yet. I believe we
need testing in user projects and just general trodding of this code
path before committing to a new default. It works in a simple example,
it might not work in a complex project. We need to field test this and
likely iterate to really call this ready IMO.
splo pushed a commit to splo/bevy that referenced this pull request Mar 31, 2026
…gine#23349)

# Objective

- Reduce panics in bevy renderer
- Continuation of Render Recovery efforts bevyengine#22761 (can't reinitialize if
we panic. I hit every single one of these on the device lost path.)

## Solution

- Use early outs and error!s instead of hard panics.
- If the panics are needed to maintain some kind of invariant, that
should be documented. I don't see any comment saying they do, so I am
assuming they do not. Correct me if I am wrong.

## Testing

- CI

---------

Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
Co-authored-by: Brennan Paciorek <50780403+BrennanPaciorek@users.noreply.github.com>
Co-authored-by: IceSentry <IceSentry@users.noreply.github.com>
splo pushed a commit to splo/bevy that referenced this pull request Mar 31, 2026
# Objective

- Completes goal and closes bevyengine#23029
- Culmination of bevyengine#22761, bevyengine#23350, bevyengine#23349, bevyengine#23433, bevyengine#23458, bevyengine#23444, bevyengine#23459,
bevyengine#23461, bevyengine#23463, bevyengine#22714, bevyengine#22759, bevyengine#16481

## Solution

- Add a release note.
- Re-export a wgpu type that you need to match on to handle errors.

## Testing

- cargo run --example render_recovery with all the other PRs merged in.
Press 5 and then V, the app will not crash. Note that D for "destroy
device" will still crash: this is a WGPU problem resolved by
gfx-rs/wgpu#9281.

# Note

I opted not to change the default recovery behavior yet. I believe we
need testing in user projects and just general trodding of this code
path before committing to a new default. It works in a simple example,
it might not work in a complex project. We need to field test this and
likely iterate to really call this ready IMO.
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 D-Straightforward Simple bug fixes and API improvements, docs, test and examples P-Crash A sudden unexpected crash S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

7 participants