fix: arcade mode crash — kaplay go() defers scene init to next frame
CI / check (push) Failing after 7m34s
CI / check (push) Failing after 7m34s
k.go('arcade') schedules the scene callback on frameEnd, not synchronously.
start() was called before fighters existed, causing "Cannot read properties
of undefined (reading 'obj')". Fix: await a readiness promise that resolves
once the scene callback has created the fighters.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
32e6c19f72
commit
fb35075b01
@@ -151,12 +151,12 @@ async function initScene(): Promise<void> {
|
||||
comboTimer = setTimeout(() => { comboInfo.value = null }, 1200)
|
||||
})
|
||||
|
||||
// Start
|
||||
// Start (awaits scene readiness — kaplay defers scene init to next frame)
|
||||
showAnnouncement('ROUND 1', 1200)
|
||||
setTimeout(() => {
|
||||
showAnnouncement('FIGHT!', 800)
|
||||
}, 1300)
|
||||
scene.start()
|
||||
await scene.start()
|
||||
|
||||
// Start input polling
|
||||
inputPollId = requestAnimationFrame(pollInput)
|
||||
|
||||
@@ -156,6 +156,11 @@ export async function createArcadeScene(config: ArcadeConfig): Promise<ArcadeSce
|
||||
let fighter1: FighterInstance
|
||||
let fighter2: FighterInstance
|
||||
|
||||
// Scene readiness — k.go() defers the scene callback to the next frame end,
|
||||
// so we need to wait for fighters to be created before start() can run.
|
||||
let sceneReady: () => void
|
||||
const sceneReadyPromise = new Promise<void>(resolve => { sceneReady = resolve })
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════
|
||||
// Scene Setup
|
||||
// ═══════════════════════════════════════════════════════════════
|
||||
@@ -180,6 +185,9 @@ export async function createArcadeScene(config: ArcadeConfig): Promise<ArcadeSce
|
||||
fighter1 = createFighter('p1', P1_START_X, 1, player1.name)
|
||||
fighter2 = createFighter('p2', P2_START_X, 2, player2.name)
|
||||
|
||||
// Signal that the scene is ready (fighters exist)
|
||||
sceneReady()
|
||||
|
||||
// ═══════════════════════════════════════════════════════════
|
||||
// Main Game Loop
|
||||
// ═══════════════════════════════════════════════════════════
|
||||
@@ -489,7 +497,8 @@ export async function createArcadeScene(config: ArcadeConfig): Promise<ArcadeSce
|
||||
k.go('arcade')
|
||||
|
||||
return {
|
||||
start() {
|
||||
async start() {
|
||||
await sceneReadyPromise
|
||||
matchOver = false
|
||||
p1Wins = 0
|
||||
p2Wins = 0
|
||||
|
||||
@@ -97,7 +97,7 @@ export interface ArcadeCallbacks {
|
||||
}
|
||||
|
||||
export interface ArcadeSceneController {
|
||||
start: () => void
|
||||
start: () => Promise<void>
|
||||
pause: () => void
|
||||
resume: () => void
|
||||
destroy: () => void
|
||||
|
||||
Reference in New Issue
Block a user