[PR #5600] [MERGED] Retry a recreated window surface whose configure failed instead of panicking #6379

Closed
opened 2026-11-03 06:19:30 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/5600
Author: @rdbtCVS
Created: 11/1/2026
Status: ✅ Merged
Merged: 11/1/2026
Merged by: @ludovic111

Base: main ← Head: fix/5353-unconfigured-surface


📝 Commits (1)

  • 59f391f Retry a recreated window surface whose configure failed

📊 Changes

1 file changed (+94 additions, -52 deletions)

View changed files

📝 crates/horizon-client-render/src/gfx.rs (+94 -52)

📄 Description

🤖 Opened by rdbtCVS's AI agent (Claude Code, Claude Opus 5.5), not by rdbtCVS personally.

Fixes #5353.

Cause. wgpu 30 gives a Surface its error sink only when Surface::configure succeeds (wgpu_core.rs CoreSurface::configure). A surface without one doesn't return CurrentSurfaceTexture::Validation when acquiring fails. It goes to handle_error_fatal and panics with "Surface is not configured for presentation". Renderer::recreate_surface (taken on Lost, and on a repeated Validation) configured the new surface without checking the result and stored it anyway, so the next draw_frame panicked.

A configure that fails with a validation error would have panicked inside configure, since the game installs no uncaptured-error handler. The report shows no such panic and nothing logged, which points to a lost device. wgpu-core reports a configure on a lost device as ErrorType::DeviceLost and drops it without a word: no error scope sees it.

Fix (crates/horizon-client-render/src/gfx.rs):

  • Renderer::configure returns a Result. It catches validation and out-of-memory errors in error scopes, and checks a new device_lost flag that the device's lost callback sets (shared with replacement renderers on the same device).
  • When recreate_surface configures a surface and that fails, the renderer logs it and marks the surface surface_unconfigured. Before acquiring, draw_frame configures that surface again and skips the frame until it works. If the device is lost, draw_frame returns an error ("the graphics device was lost") instead of panicking in wgpu.
  • The other reconfigure sites (resize, present mode, Outdated, Suboptimal, the first Validation) go through configure_surface, which logs a failure. Those surfaces were configured before, so acquiring from them still reports Validation and the existing recovery handles it.

This isn't vanilla parity: it's renderer robustness, and vanilla has no counterpart.

Tests

  • python3 tools/pr_ready.py --quick (before rebasing onto origin/main): Python tests 498 passed, rustfmt ok, horizon-client-render tests 726 passed, doc tests ok. Its clippy step failed on audio.rs (missing fields in Audio::share). This branch doesn't touch that file, and current main already fixes it.
  • After rebasing onto origin/main: cargo clippy --workspace --all-targets -- -D warnings and cargo clippy -p horizon-client --all-targets --no-default-features -- -D warnings both pass.
  • No unit test: the path needs a real window surface whose configure fails. I haven't reproduced the crash at runtime.

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/horizon-rust/horizon/pull/5600 **Author:** [@rdbtCVS](https://github.com/rdbtCVS) **Created:** 11/1/2026 **Status:** ✅ Merged **Merged:** 11/1/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `fix/5353-unconfigured-surface` --- ### 📝 Commits (1) - [`59f391f`](https://github.com/horizon-rust/horizon/commit/59f391f8dfb61a53c1548d2bce1214895aba9b1c) Retry a recreated window surface whose configure failed ### 📊 Changes **1 file changed** (+94 additions, -52 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client-render/src/gfx.rs` (+94 -52) </details> ### 📄 Description > 🤖 Opened by rdbtCVS's AI agent (Claude Code, Claude Opus 5.5), not by rdbtCVS personally. Fixes #5353. **Cause.** wgpu 30 gives a `Surface` its error sink only when `Surface::configure` succeeds (`wgpu_core.rs` `CoreSurface::configure`). A surface without one doesn't return `CurrentSurfaceTexture::Validation` when acquiring fails. It goes to `handle_error_fatal` and panics with "Surface is not configured for presentation". `Renderer::recreate_surface` (taken on `Lost`, and on a repeated `Validation`) configured the new surface without checking the result and stored it anyway, so the next `draw_frame` panicked. A configure that fails with a validation error would have panicked inside `configure`, since the game installs no uncaptured-error handler. The report shows no such panic and nothing logged, which points to a lost device. wgpu-core reports a configure on a lost device as `ErrorType::DeviceLost` and drops it without a word: no error scope sees it. **Fix** (`crates/horizon-client-render/src/gfx.rs`): - `Renderer::configure` returns a `Result`. It catches validation and out-of-memory errors in error scopes, and checks a new `device_lost` flag that the device's lost callback sets (shared with replacement renderers on the same device). - When `recreate_surface` configures a surface and that fails, the renderer logs it and marks the surface `surface_unconfigured`. Before acquiring, `draw_frame` configures that surface again and skips the frame until it works. If the device is lost, `draw_frame` returns an error ("the graphics device was lost") instead of panicking in wgpu. - The other reconfigure sites (resize, present mode, Outdated, Suboptimal, the first Validation) go through `configure_surface`, which logs a failure. Those surfaces were configured before, so acquiring from them still reports `Validation` and the existing recovery handles it. This isn't vanilla parity: it's renderer robustness, and vanilla has no counterpart. **Tests** - `python3 tools/pr_ready.py --quick` (before rebasing onto origin/main): Python tests 498 passed, rustfmt ok, `horizon-client-render` tests 726 passed, doc tests ok. Its clippy step failed on `audio.rs` (missing fields in `Audio::share`). This branch doesn't touch that file, and current main already fixes it. - After rebasing onto origin/main: `cargo clippy --workspace --all-targets -- -D warnings` and `cargo clippy -p horizon-client --all-targets --no-default-features -- -D warnings` both pass. - No unit test: the path needs a real window surface whose configure fails. I haven't reproduced the crash at runtime. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 06:19:30 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
horizon-rust/horizon#6379
No description provided.