@@ -391,7 +391,7 @@ export async function CreateV2Runner(manifest: V2Manifest, opts: V2RunnerOptions
391391 toolkit :
392392 enable . toolkit ??
393393 ( ( autoProbe &&
394- ( / \b B A B Y L O N \. T o o l k i t \. S c e n e M a n a g e r \. I n i t i a l i z e P l a y g r o u n d \b / . test ( allSource ) ||
394+ ( / T O O L K I T \. S c e n e M a n a g e r / u . test ( allSource ) ||
395395 / \b S M \. I n i t i a l i z e P l a y g r o u n d \b / . test ( allSource ) ||
396396 location . href . includes ( "BabylonToolkit" ) ||
397397 ( ( ) : boolean => {
@@ -411,7 +411,7 @@ export async function CreateV2Runner(manifest: V2Manifest, opts: V2RunnerOptions
411411 toolkit : "https://cdn.jsdelivr.net/gh/BabylonJS/BabylonToolkit@master/Runtime/babylon.toolkit.js" ,
412412 } ;
413413
414- async function initRuntime ( engine : ThinEngine ) {
414+ async function initRuntime ( ) : Promise < void > {
415415 // AMMO
416416 if ( want . ammo ) {
417417 const hasFactory = typeof ( window as any ) . Ammo === "function" ;
@@ -451,23 +451,6 @@ export async function CreateV2Runner(manifest: V2Manifest, opts: V2RunnerOptions
451451 }
452452 }
453453
454- // SOUND
455- if ( want . sound ) {
456- try {
457- const anyB = ( window as any ) . BABYLON as any ;
458- const opts = ( engine as any ) . getCreationOptions ?.( ) ;
459- if ( ! opts || opts . audioEngine !== false ) {
460- anyB . AbstractEngine . audioEngine = anyB . AbstractEngine . AudioEngineFactory (
461- engine . getRenderingCanvas ( ) ,
462- engine . getAudioContext ?.( ) ,
463- engine . getAudioDestination ?.( )
464- ) ;
465- }
466- } catch {
467- /* ignore */
468- }
469- }
470-
471454 // TOOLKIT
472455 if ( want . toolkit ) {
473456 await loadScriptOnce ( urls . toolkit || defaults . toolkit ) ;
@@ -486,6 +469,7 @@ export async function CreateV2Runner(manifest: V2Manifest, opts: V2RunnerOptions
486469 return await import ( /* webpackIgnore: true */ s ) ;
487470 } ) ;
488471 const entrySpec = specKey ( entryPath ) ;
472+ await initRuntime ( ) ;
489473 const mod = await importFn ( entrySpec ) ;
490474 let engine : ThinEngine | null = null ;
491475 if ( typeof mod . createEngine === "function" ) {
@@ -505,8 +489,23 @@ export async function CreateV2Runner(manifest: V2Manifest, opts: V2RunnerOptions
505489 if ( ! engine ) {
506490 throw new Error ( "Failed to create engine." ) ;
507491 }
492+ // Sound post-creation init
493+ if ( want . sound ) {
494+ try {
495+ const anyB = ( window as any ) . BABYLON as any ;
496+ const opts = ( engine as any ) . getCreationOptions ?.( ) ;
497+ if ( ! opts || opts . audioEngine !== false ) {
498+ anyB . AbstractEngine . audioEngine = anyB . AbstractEngine . AudioEngineFactory (
499+ engine . getRenderingCanvas ( ) ,
500+ engine . getAudioContext ?.( ) ,
501+ engine . getAudioDestination ?.( )
502+ ) ;
503+ }
504+ } catch {
505+ /* ignore */
506+ }
507+ }
508508 ( window as any ) . engine = engine ;
509- await initRuntime ( engine ) ;
510509
511510 let createScene : any = null ;
512511 if ( mod . default ?. CreateScene ) {
0 commit comments