{"record":{"id":"d659374b941db5c6","repo":"stride3d/stride","slug":"failed-to-create-celt-decoder","errorCode":null,"errorMessage":"Failed to create Celt decoder.","messagePattern":"Failed to create Celt decoder\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Audio/Native/Celt.AVFoundation.cs","lineNumber":51,"sourceCode":"        public int Channels { get; set; }\n\n        private IntPtr mode;\n        private IntPtr decoder;\n        private IntPtr encoder;\n\n        public Celt(int sampleRate, int bufferSize, int channels, bool decoderOnly)\n        {\n            SampleRate = sampleRate;\n            BufferSize = bufferSize;\n            Channels = channels;\n\n            mode = opus_custom_mode_create(sampleRate, bufferSize, IntPtr.Zero);\n            if (mode == IntPtr.Zero)\n                throw new Exception(\"Failed to create Celt custom mode.\");\n\n            decoder = opus_custom_decoder_create(mode, channels, IntPtr.Zero);\n            if (decoder == IntPtr.Zero)\n                throw new Exception(\"Failed to create Celt decoder.\");\n\n            if (!decoderOnly)\n            {\n                encoder = opus_custom_encoder_create(mode, channels, IntPtr.Zero);\n                if (encoder == IntPtr.Zero)\n                    throw new Exception(\"Failed to create Celt encoder.\");\n            }\n        }\n\n        public void Dispose()\n        {\n            if (encoder != IntPtr.Zero) { opus_custom_encoder_destroy(encoder); encoder = IntPtr.Zero; }\n            if (decoder != IntPtr.Zero) { opus_custom_decoder_destroy(decoder); decoder = IntPtr.Zero; }\n            if (mode != IntPtr.Zero) { opus_custom_mode_destroy(mode); mode = IntPtr.Zero; }\n        }\n\n        public unsafe int Decode(byte[] inputBuffer, int inputBufferSize, short[] outputSamples)\n        {","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Audio/Native/Celt.AVFoundation.cs#L33-L69","documentation":"Thrown from the Celt constructor when opus_custom_decoder_create returns NULL after the custom mode was created successfully. The native codec could not allocate or configure a decoder for the given channel count. Encoding-only or decoding-only paths may still be affected at construction time because the decoder is always created.","triggerScenarios":"Constructing Celt with an unsupported channel count or when native decoder allocation fails (memory, bad native library build) on the AVFoundation/iOS path.","commonSituations":"Passing more channels than the codec supports; shipping a mismatched or stripped native opus/celt binary; low-memory conditions on mobile devices.","solutions":["Verify the channel count is supported by the Celt decoder (typically 1 or 2).","Ensure the correct native celt/opus library is bundled and loadable for the target platform.","Free memory or reduce concurrent codec instances if native allocation is failing under pressure.","Update Stride / native dependencies to a matching version."],"exampleFix":"// before\nvar celt = new Celt(48000, 256, inputChannels /* e.g. 6 */, true);\n// after\nvar channels = Math.Min(inputChannels, 2);\nvar celt = new Celt(48000, 256, channels, true); // downmix before encoding","handlingStrategy":"try-catch","validationCode":"public static bool IsSupportedChannelCount(int channels) => channels is 1 or 2;","typeGuard":null,"tryCatchPattern":"try\n{\n    var celt = new Celt(48000, bufferSize, channels, decoderOnly);\n}\ncatch (Exception ex) when (ex.Message.Contains(\"Failed to create Celt decoder\"))\n{\n    logger.Error(\"Celt decoder creation failed; check channels and native lib.\");\n    celt = null;\n}","preventionTips":["Clamp channel counts to 1-2 (downmix multichannel input before encoding).","Ensure native codec binaries match the managed wrapper version.","Monitor native memory on mobile devices with many concurrent codecs.","Verify decoder availability even when only encoding is planned, since the constructor always creates it."],"tags":["audio","celt","native","codec","decoder"],"backgroundTag":"module-init-failed","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"}