{"record":{"id":"37de8e423329b757","repo":"BabylonJS/Babylon.js","slug":"connect-failed","errorCode":null,"errorMessage":"Connect failed","messagePattern":"Connect failed","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/dev/core/src/AudioV2/abstractAudio/abstractSoundSource.ts","lineNumber":106,"sourceCode":"        if (this._outBus) {\n            if (this._onOutBusDisposed) {\n                this._outBus.onDisposeObservable.removeCallback(this._onOutBusDisposed);\n                this._onOutBusDisposed = null;\n            }\n            if (!this._disconnect(this._outBus)) {\n                throw new Error(\"Disconnect failed\");\n            }\n        }\n\n        this._outBus = outBus;\n\n        if (this._outBus) {\n            this._onOutBusDisposed = () => {\n                this._outBus = null;\n            };\n            this._outBus.onDisposeObservable.add(this._onOutBusDisposed);\n            if (!this._connect(this._outBus)) {\n                throw new Error(\"Connect failed\");\n            }\n        }\n    }\n\n    /**\n     * The spatial audio features.\n     */\n    public get spatial(): AbstractSpatialAudio {\n        if (this._spatial) {\n            return this._spatial;\n        }\n        return this._initSpatialProperty();\n    }\n\n    /**\n     * The stereo features of the sound.\n     */\n    public abstract stereo: AbstractStereoAudio;","sourceCodeStart":88,"sourceCodeEnd":124,"githubUrl":"https://github.com/BabylonJS/Babylon.js/blob/0592b347b8a4ee0236089ea86a749cacfdb266d8/packages/dev/core/src/AudioV2/abstractAudio/abstractSoundSource.ts#L88-L124","documentation":"AbstractSoundSource.outBus setter throws \"Connect failed\" when the internal _connect(outBus) call returns false after subscribing to the bus's dispose observable. In Babylon.js Audio V2, a sound source must be attached to an output bus (e.g. the default main bus); _connect fails when the underlying audio engine cannot establish the node connection, typically because the engine is not ready/started or the connection target is invalid or already disposed.","triggerScenarios":"Assigning sound.outBus = someBus before AudioEngine is ready (engine not created/started), assigning a bus that has been disposed, or assigning a bus whose underlying node graph cannot accept a connection (e.g. destination bus in a broken state).","commonSituations":"Setting outBus immediately after creating the engine without awaiting engineInitAsync()/await engine start; capturing a bus that was disposed (its onDisposeObservable fires and clears references but stale handles are reused); migrating from AudioEngineV1 patterns where no readiness await was needed.","solutions":["Ensure the AudioEngine is initialized and started before setting outBus: await engineInitAsync (or AudioEngineV2 default engine init) before assignment.","Verify the target bus is not disposed: check it is still in engine.buses / you hold a live reference (e.g. CreateDefaultMainBus or a Bus you created).","Wrap the assignment in try/catch and retry the assignment once the engine is ready.","Update Babylon.js packages; earlier Audio V2 builds had connect timing bugs."],"exampleFix":"// before\nconst sound = await createSoundAsync(\"boom.mp3\");\nsound.outBus = bus; // throws if engine not ready\n\n// after\nawait AudioEngineV2.Listener.engine.initAsync(); // or await engine started\nconst bus = engine.buses.find((b) => b.name === \"SFX\") ?? new AudioBus(\"SFX\");\nsound.outBus = bus;","handlingStrategy":"validation","validationCode":"function canAssignOutBus(engine, bus) {\n  return !!engine && engine.state === 'started' /* or awaited initAsync */ && !!bus && !bus.isDisposed && engine.buses.includes(bus);\n}\nif (canAssignOutBus(engine, bus)) sound.outBus = bus;","typeGuard":"function isLiveBus(x) {\n  return x instanceof AudioBus && !x.isDisposed;\n}","tryCatchPattern":"try {\n  sound.outBus = bus;\n} catch (e) {\n  if (e.message === 'Connect failed') {\n    await engine.initAsync(); // or retry after engine ready\n    sound.outBus = bus;\n  } else throw e;\n}","preventionTips":["Always await audio engine init/start before touching Audio V2 graph APIs.","Never reuse bus references after disposing; null them out.","Keep buses created from the same engine instance.","Listen to onDisposeObservable of buses you share across modules."],"tags":["audio","webaudio","babylonjs","initialization-order"],"backgroundTag":"audio-node-connect-failed","analyzedSha":"0592b347b8a4ee0236089ea86a749cacfdb266d8","analyzedAt":"2026-08-30T15:11:20.442Z","schemaVersion":2},"datasetVersion":"2026-08-30T18:17:15.746Z"}