fix: KAPLAY scene init robustness — wait for layout, catch errors

- FightViewer: wrap createFightScene in try/catch so scene failures
  don't crash every subsequent playRound call
- FightViewer: wait for container to have non-zero dimensions before
  creating canvas (prevents 0x0 canvas causing sprite load failures)
- FightViewer: graceful log-only fallback when scene init fails
- FightPage: same dimension-wait and try/catch for initLiveScene
- Fallback canvas dimensions (800x500) when container not yet laid out

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Dorian
2026-03-08 00:46:50 +00:00
co-authored by Claude Opus 4.6
parent a254a77151
commit 6b139a076a
2 changed files with 24 additions and 10 deletions
+7 -2
View File
@@ -112,12 +112,17 @@ async function initScene() {
const container = canvasContainer.value
if (!container) return
// Wait for container to have dimensions (layout may not be complete yet)
for (let i = 0; i < 10 && (!container.clientWidth || !container.clientHeight); i++) {
await new Promise(r => requestAnimationFrame(r))
}
// Replace canvas element so Kaplay gets a fresh context
const oldCanvas = canvasRef.value
const newCanvas = document.createElement('canvas')
newCanvas.className = 'w-full h-full block'
newCanvas.width = container.clientWidth
newCanvas.height = container.clientHeight
newCanvas.width = container.clientWidth || 800
newCanvas.height = container.clientHeight || 500
if (oldCanvas) {
oldCanvas.replaceWith(newCanvas)
} else {