1 render surface guard and window safety
forgejo-actions edited this page 2026-07-11 12:38:13 +00:00

Render Surface Guard And Window Safety

The render surface guard protects Bevy rendering from invalid or temporarily unusable windows. It is especially important for minimized, hidden, occluded, or secondary windows where surface preparation can fail before the game logic has anything wrong with it.

Purpose

Use this page when debugging swapchain errors, black windows after minimize/restore, or tests that assert the renderer survives window visibility changes.

How It Works

RenderSurfaceGuardPlugin is registered during bootstrap. It observes window state and render-app ordering so surface preparation only proceeds when the target window can safely present. The goal is to treat a bad surface as a temporary window-state problem instead of a fatal runtime problem.

The guard is deliberately low-level. Gameplay, editor, and preview systems should not each add their own minimized-window special cases.

Window States

The guard is concerned with states that make a surface unsuitable for rendering: minimized size, hidden visibility, occlusion, destroyed secondary surfaces, and platform transitions during resize or restore. A valid state can become invalid for a few frames and then recover.

Do not interpret a skipped render frame as a lost world state. Simulation and UI state should continue to be owned by their normal systems.

RenderApp Ordering

Surface safety must run early enough that later render preparation sees a coherent target state. If a plugin changes render schedules or window extraction, re-run the bootstrap tests that assert guard installation and ordering.

Invariants

Only the guard should centralize surface availability decisions. Window restore must resume rendering without recreating gameplay state. Secondary windows must not be allowed to poison the primary runtime window. Guard decisions must be deterministic enough for tests to catch ordering drift.

Debugging Swapchain Failures

When a crash or blank frame mentions a surface or swapchain, check the window's size and visibility first. Then confirm the guard plugin is installed by the bootstrap path being used: editor, local playtest, standalone preview, or runtime app.

If the issue only happens in a special shell, compare that shell's plugin list with bootstrap/mod.rs.