fix: make soundtrack loading terminal

This commit is contained in:
2026-09-04 16:25:29 +03:00
parent 5172b5bc4b
commit 1431e65768
2 changed files with 28 additions and 10 deletions

View File

@@ -387,7 +387,9 @@ export function createSoundtrackEngine(
mainSource = main;
mainSchedule = schedule;
attachMainEnded(main);
for (const source of introSourceNodes) {
const committedIntroSources = introSourceNodes;
introSourceNodes = [];
for (const source of committedIntroSources) {
source.stopAt(transitionTime + EXIT_CROSSFADE_SECONDS);
}
loadedIntroBuffer = null;
@@ -456,22 +458,24 @@ export function createSoundtrackEngine(
void mainPromise.catch(() => undefined);
if (activatedFromStart) {
loadedIntroBuffer = await dependencies.loadBuffer(context, sources.intro, signal);
const [introBuffer, mainBuffer] = await Promise.all([
dependencies.loadBuffer(context, sources.intro, signal),
mainPromise,
]);
if (closed || signal.aborted) throw abortError();
loadedIntroBuffer = introBuffer;
if (latestChapter.atStart) {
transportStarted = true;
startIntro(loadedIntroBuffer, context.currentTime + SOURCE_LEAD_SECONDS);
return;
}
transportStarted = true;
startDirectMain(mainBuffer);
return;
}
const mainBuffer = await mainPromise;
if (closed || signal.aborted) throw abortError();
if (activatedFromStart && latestChapter.atStart && loadedIntroBuffer !== null) {
transportStarted = true;
startIntro(loadedIntroBuffer, context.currentTime + SOURCE_LEAD_SECONDS);
return;
}
transportStarted = true;
startDirectMain(mainBuffer);
};
@@ -514,6 +518,16 @@ export function createSoundtrackEngine(
mixer.dispose();
for (const source of [...ownedSources]) source.cancel();
ownedSources.clear();
pendingIntroExit = null;
introSourceNodes = [];
introProgramGain = null;
mainSource = null;
driveLiftSource = null;
afterglowSource = null;
mainSchedule = null;
mainBufferPromise = null;
loadPromise = null;
exitLoadRequest = null;
context.removeEventListener('statechange', onStateChange);
stateListeners.clear();
outputGain.disconnect();