fix(web): replay the surface after an attach-time compute device loss
a failed native surface attach only reports the boolean create result, so an injected (or real) COMPUTE_DEVICE_LOST during the attach draw reached the app as a generic CAPABILITY_MISSING and never matched the bounded auto-remount in failSurface. route the startup rejection through a failAttach that replays the surface through the same retrySurface path, and keep the rebind budget in a ref so the bound survives the effect re-run that the replay triggers. verified with ?computeFault=destroy-after-3: the first attach logs "Native WebGPU compute draw_command_generate: COMPUTE_DEVICE_LOST", the retry re-attaches (attach #2, detach #1), and the surface comes back with frame=1440x900, inputReady=true and a rendered viewport. a 3-minute fault run without the soak's web-tools/file-transfer panel clicks stays rendered; the full soak still blanks its main regions later, which correlates with those panel toggles after a replay and is recorded as a separate residual. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
@@ -40,6 +40,7 @@ export function WasmGPUCanvas({ client, active = true, playing = false, onApplie
|
||||
const [error, setError] = useState("");
|
||||
const [retry, setRetry] = useState(0), [retrying, setRetrying] = useState(false);
|
||||
const retrySurface = useRef<(() => Promise<void>) | null>(null);
|
||||
const computeRebinds = useRef(0);
|
||||
const [ready, setReady] = useState(false), [nativeAttached, setNativeAttached] = useState(false);
|
||||
const [fileSession, setFileSession] = useState('');
|
||||
const [filesOpen, setFilesOpen] = useState(false);
|
||||
@@ -274,13 +275,24 @@ export function WasmGPUCanvas({ client, active = true, playing = false, onApplie
|
||||
/* A lost WebGPU device leaves the native draw transaction incomplete; replaying
|
||||
* the frame in place hits a broken GL state. Rebuild the whole surface through
|
||||
* the manual-retry path instead, bounded so a persistent fault still surfaces. */
|
||||
let computeRebinds = 0;
|
||||
const failSurface = (reason: unknown) => {
|
||||
const detail = reason && typeof reason === 'object' && 'message' in reason
|
||||
? String((reason as { message?: unknown }).message) : String(reason);
|
||||
fail(reason);
|
||||
if (computeRebinds < 2 && detail.includes('COMPUTE_DEVICE_LOST')) {
|
||||
computeRebinds += 1;
|
||||
if (computeRebinds.current < 2 && detail.includes('COMPUTE_DEVICE_LOST')) {
|
||||
computeRebinds.current += 1;
|
||||
window.setTimeout(() => { if (!disposed) void retrySurface.current?.(); }, 400);
|
||||
}
|
||||
};
|
||||
/* A failed attach reports the native boolean create result, so a compute
|
||||
* device loss during attach arrives without its COMPUTE_DEVICE_LOST text.
|
||||
* Replay the surface through the same bounded path instead of stopping. */
|
||||
const failAttach = (reason: unknown) => {
|
||||
const detail = reason && typeof reason === 'object' && 'message' in reason
|
||||
? String((reason as { message?: unknown }).message) : String(reason);
|
||||
failSurface(reason);
|
||||
if (computeRebinds.current < 2 && !detail.includes('COMPUTE_DEVICE_LOST')) {
|
||||
computeRebinds.current += 1;
|
||||
window.setTimeout(() => { if (!disposed) void retrySurface.current?.(); }, 400);
|
||||
}
|
||||
};
|
||||
@@ -718,7 +730,7 @@ export function WasmGPUCanvas({ client, active = true, playing = false, onApplie
|
||||
const ownerReady = Boolean(result.displayAcknowledged && !ownerChanged && !result.inputDiscarded && !error && attached && !contextLost && !events.length);
|
||||
readyOwnerFrames = ownerReady ? readyOwnerFrames + 1 : 0;
|
||||
canvas.dataset.nativeInputReady = String(Boolean(!disposed && !stopped && ownerReady && readyOwnerFrames >= 2));
|
||||
if (!readyPublished && canvas.dataset.nativeInputReady === 'true') { readyPublished = true; computeRebinds = 0; setReady(true); onReady?.(true); }
|
||||
if (!readyPublished && canvas.dataset.nativeInputReady === 'true') { readyPublished = true; computeRebinds.current = 0; setReady(true); onReady?.(true); }
|
||||
const redrawPending = error?.code === 'CAPABILITY_MISSING' && (error.message.includes('Browser region requires redraw') || error.message.includes('Browser region draw buffer is unavailable'));
|
||||
if (result.inputDiscarded && !ownerChanged) {
|
||||
events = [];
|
||||
@@ -888,7 +900,7 @@ export function WasmGPUCanvas({ client, active = true, playing = false, onApplie
|
||||
if (document.activeElement === canvas) focus(7);
|
||||
else canvas.focus();
|
||||
frame = requestAnimationFrame(() => void draw());
|
||||
})(); void startup.catch(fail);
|
||||
})(); void startup.catch(failAttach);
|
||||
// Keep worker notifications within this canvas effect's lifecycle.
|
||||
const onWorkerMessage = (event: MessageEvent) => {
|
||||
const type = event.data?.type;
|
||||
|
||||
Reference in New Issue
Block a user