{"record":{"id":"1e560ac6dbb04d60","repo":"stride3d/stride","slug":"this","errorCode":null,"errorMessage":"this","messagePattern":"this","errorType":"exception","errorClass":"ObjectDisposedException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Audio/SoundBase.cs","lineNumber":93,"sourceCode":"        internal void Attach(AudioEngine engine)\n        {\n            AttachEngine(engine);\n\n            Name = \"Sound Effect \" + Interlocked.Add(ref soundEffectCreationCount, 1);\n\n            // register the sound to the AudioEngine so that it will be properly freed if AudioEngine is disposed before this.\n            AudioEngine.RegisterSound(this);\n        }\n\n        public int GetCountChannels()\n        {\n            return Channels;\n        }\n\n        internal void CheckNotDisposed()\n        {\n            if (IsDisposed)\n                throw new ObjectDisposedException(\"this\");\n        }\n\n        /// <summary>\n        /// Stop all registered instances of the <see cref=\"SoundBase\"/>.\n        /// </summary>\n        internal void StopAllInstances()\n        {\n            foreach (var instance in Instances)\n                instance.Stop();\n        }\n\n        /// <summary>\n        /// Stop all registered instances different from the provided main instance\n        /// </summary>\n        /// <param name=\"mainInstance\">The main instance of the sound effect</param>\n        internal void StopConcurrentInstances(SoundInstance mainInstance)\n        {\n            foreach (var instance in Instances)","sourceCodeStart":75,"sourceCodeEnd":111,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Audio/SoundBase.cs#L75-L111","documentation":"SoundBase.CheckNotDisposed throws ObjectDisposedException with the literal name \"this\" once the sound asset (SoundBase) has been disposed. It guards internal operations (e.g. querying Channels or creating instances) against use of a disposed sound. The cryptic objectName \"this\" is a library quirk; the semantic is 'the sound object was disposed'.","triggerScenarios":"Calling instance-creating or property APIs (e.g. CreateInstance, Channel-related access) on a SoundInstance's Sound after sound.Dispose() was called, e.g. during scene teardown order issues.","commonSituations":"Disposing a SoundInstance or audio asset while other code still references the parent sound and tries to spawn new instances; game shutdown racing with gameplay code still requesting sounds.","solutions":["Stop using the sound after Dispose; guard call sites with IsDisposed checks.","Fix object lifetimes so the sound outlives all code that can create instances from it.","In game-shutdown paths, stop audio system updates before disposing audio assets."],"exampleFix":"// before\nvar instance = sound.CreateInstance();\n// after\nif (!sound.IsDisposed)\n{\n    var instance = sound.CreateInstance();\n}\nelse\n{\n    logger.Warn(\"Attempted to use disposed sound\");\n}","handlingStrategy":"type-guard","validationCode":"public static bool CanUseSound(SoundBase sound) => sound != null && !sound.IsDisposed;","typeGuard":"public static bool IsUsable(SoundBase? sound) => sound is { IsDisposed: false };","tryCatchPattern":"try\n{\n    var instance = sound.CreateInstance();\n}\ncatch (ObjectDisposedException)\n{\n    logger.Warn(\"Sound already disposed; skipping instance creation.\");\n}","preventionTips":["Check IsDisposed before any use of a sound that may have been disposed.","Establish clear ownership so assets are disposed only after all consumers stop using them.","Stop gameplay/audio updates before disposing audio assets during shutdown.","Avoid caching SoundInstance references across scene unload boundaries."],"tags":["audio","disposed","lifecycle","objectdisposedexception"],"backgroundTag":"invalid-state-transition","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"}