{"record":{"id":"adccc8a8b449a72e","repo":"stride3d/stride","slug":"the-provided-listener-was-not-present-in-the-audio-system","errorCode":null,"errorMessage":"The provided listener was not present in the Audio System.","messagePattern":"The provided listener was not present in the Audio System\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Engine/Audio/AudioSystem.cs","lineNumber":104,"sourceCode":"        /// </summary>\n        /// <param name=\"listener\">The listener to add to the audio system.</param>\n        /// <remarks>Adding a listener already added as no effects.</remarks>\n        internal void AddListener(AudioListenerComponent listener)\n        {\n            if (!Listeners.ContainsKey(listener))\n                Listeners[listener] = null;\n        }\n\n        /// <summary>\n        /// Remove a <see cref=\"AudioListenerComponent\" /> from the Audio System.\n        /// After this call sounds played via <see cref=\"AudioEmitterSoundController\" />s will not be heard by this listener anymore.\n        /// </summary>\n        /// <param name=\"listener\">The listener to remove from the audio system.</param>\n        /// <exception cref=\"System.ArgumentException\">The provided listener was not present in the Audio System.</exception>\n        internal void RemoveListener(AudioListenerComponent listener)\n        {\n            if (!Listeners.ContainsKey(listener))\n                throw new ArgumentException(\"The provided listener was not present in the Audio System.\");\n\n            Listeners.Remove(listener);\n        }\n\n        public override void Update(GameTime gameTime)\n        {\n            AudioEngine?.Update();\n        }\n\n        // called on dispose\n        protected override void Destroy()\n        {\n            Game.Activated -= OnActivated;\n            Game.Deactivated -= OnDeactivated;\n\n            base.Destroy();\n\n            lock (AudioEngineStaticLock)","sourceCodeStart":86,"sourceCodeEnd":122,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Engine/Audio/AudioSystem.cs#L86-L122","documentation":"AudioSystem.RemoveListener removes a registered AudioListenerComponent from the Listeners dictionary. If the listener was never added (or was already removed), the ContainsKey check fails and an ArgumentException is thrown, as documented by the method's exception attribute. It protects the audio engine's listener bookkeeping from inconsistent updates.","triggerScenarios":"Calling RemoveListener (internal, invoked via AudioListenerComponent destruction/Dispose paths) with a listener not present in AudioSystem.Listeners — e.g. removing the same listener twice, or removing a listener that was never registered with AddListener, at AudioSystem.cs:104.","commonSituations":"An AudioListenerComponent being destroyed twice (double Dispose during scene teardown); removing a listener entity from a scene it was never added to; component lifecycle ordering issues where the audio system already dropped the listener.","solutions":["Ensure RemoveListener is only called for listeners previously added via AddListener (i.e. on live AudioListenerComponents).","Fix double-destroy: guard component teardown so Dispose/removal runs only once.","Check the audio system isn't already removed/dropping listeners before scene teardown removes them.","If calling manually, check AudioSystem.Listeners.ContainsKey(listener) (or a public equivalent) before removal."],"exampleFix":"// before\naudioSystem.RemoveListener(listener); // may throw if not registered\n\n// after\nif (audioSystem.Listeners.ContainsKey(listener))\n    audioSystem.RemoveListener(listener);","handlingStrategy":"try-catch","validationCode":"// Only remove listeners that are still registered\nif (audioSystem.Listeners.ContainsKey(listener))\n    audioSystem.RemoveListener(listener);","typeGuard":null,"tryCatchPattern":"try { audioSystem.RemoveListener(listener); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"not present in the Audio System\")) { /* already removed; ignore */ }","preventionTips":["Let AudioListenerComponent's own lifecycle remove listeners; avoid manual removal","Make component Dispose idempotent to prevent double-removal","Never remove a listener from a different AudioSystem instance than the one that registered it"],"tags":["audio","listener","argument","lifecycle"],"backgroundTag":"record-not-found","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}