Harden worker page rendering: error/timeout recovery and awaited flip prewarm
Two robustness gaps from the worker migration, both raised in review: - The raster worker had no failure recovery: a thrown createImageBitmap/font error or a dropped message would leave the draw promise pending forever, stalling the serialized draw chain and hanging prepare/playback. Added worker.onerror and a per-job timeout; both settle the in-flight draw to a logged miss (texture-worker-error / -timeout) so the pipeline degrades to last-good per the spec instead of hanging. A single settleRasterization path clears the timer and resolves. - prepareSpreadTextureRecordsForFlip() called drawSpread() without awaiting it. That was safe when drawSpread was synchronous, but now that it is async (worker) the flip could race ahead of the worker draw and miss the resident texture. prewarmFlipTextures now awaits both spread draws before the resident-texture lookup. Suite 168 (added assertions for worker error/timeout recovery and the awaited prewarm). Normal draw path is behaviorally unchanged from the verified worker commit. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -2442,8 +2442,10 @@ async function prewarmFlipTextures(direction, targetSpread = null) {
|
||||
const nextSpread = Number.isFinite(Number(targetSpread))
|
||||
? Math.max(0, Math.round(Number(targetSpread)))
|
||||
: Math.max(0, currentSpread + Math.sign(Number(direction || 0)));
|
||||
prepareSpreadTextureRecordsForFlip(currentSpread);
|
||||
prepareSpreadTextureRecordsForFlip(nextSpread);
|
||||
// Await the (now async, worker-backed) draws so the spreads are resident before the cache
|
||||
// lookup below — otherwise the flip can race ahead and find a missing texture.
|
||||
await prepareSpreadTextureRecordsForFlip(currentSpread);
|
||||
await prepareSpreadTextureRecordsForFlip(nextSpread);
|
||||
const windowMap = await prewarmNavigationTextureWindow('flip-prewarm', { targetSpread: nextSpread });
|
||||
const current = windowMap?.[currentSpread] || await prewarmSpreadTextures(currentSpread);
|
||||
const next = windowMap?.[nextSpread] || await prewarmSpreadTextures(nextSpread);
|
||||
@@ -2453,11 +2455,11 @@ async function prewarmFlipTextures(direction, targetSpread = null) {
|
||||
};
|
||||
}
|
||||
|
||||
function prepareSpreadTextureRecordsForFlip(spreadIndex) {
|
||||
async function prepareSpreadTextureRecordsForFlip(spreadIndex) {
|
||||
const spread = getPaginationSpread(spreadIndex);
|
||||
if (!spread || typeof window.BookTextureRenderer?.drawSpread !== 'function') return false;
|
||||
if (spreadTextureRecordsReady(spread)) return true;
|
||||
window.BookTextureRenderer.drawSpread(spread, ['left', 'right'], {
|
||||
await window.BookTextureRenderer.drawSpread(spread, ['left', 'right'], {
|
||||
phase: 'prepare'
|
||||
});
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user