Skip to content

A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.

fix(sdk): pooled audio nodes don't cross-route or NaN the panner

esenginea00c38a3ff68
diff --git a/sdk/src/audio/AudioPool.ts b/sdk/src/audio/AudioPool.ts
index e5f1a6499..59786fa39 100644
--- a/sdk/src/audio/AudioPool.ts
+++ b/sdk/src/audio/AudioPool.ts
@@ -58,6 +58,11 @@ export class AudioPool {
node.source.disconnect();
node.source = null;
}
+ // The panner is re-connected to a bus on every play; without disconnecting
+ // it here, reusing this pooled node on a DIFFERENT bus leaves the old
+ // panner→bus edge live, so the sound feeds both buses (doubled + wrong
+ // volume/ducking). WebAudio dedups same-target connects, not different ones.
+ node.panner.disconnect();
node.inUse = false;
this.activeCount_--;
}
diff --git a/sdk/src/audio/SpatialAudio.ts b/sdk/src/audio/SpatialAudio.ts
index 358d3e56a..e90365cf1 100644
--- a/sdk/src/audio/SpatialAudio.ts
+++ b/sdk/src/audio/SpatialAudio.ts
@@ -56,5 +56,6 @@ export function calculatePanning(
maxDistance: number
): number {
const dx = sourceX - listenerX;
- return Math.max(-1, Math.min(1, dx / maxDistance));
+ // Guard maxDistance: 0 would yield NaN, which StereoPannerNode.pan throws on.
+ return Math.max(-1, Math.min(1, dx / Math.max(maxDistance, 1e-3)));
}