stride3d/stride · error · Exception

Failed to create an AudioLayer Source

Error message

Failed to create an AudioLayer Source

What it means

SoundInstanceStreamedBuffer creates a native AudioLayer source for a streamed sound buffer; when AudioLayer.SourceCreate returns IntPtr.Zero the source could not be allocated and playback is impossible, so the constructor throws. The cause is almost always an unusable or overloaded audio device.

Solutions

  1. Ensure an audio output device is present and the AudioEngine is healthy; reinitialize the engine after device changes.
  2. Limit concurrent streamed buffers and dispose completed instances to free native sources.
  3. Retry with spatialized: false and useHrtf: false to rule out unsupported features.
  4. Guard creation with try-catch and provide a silent fallback.

Example fix

// before
var streamed = new SoundInstanceStreamedBuffer(listener, soundStreamedBuffer, spatialized: true, useHrtf: true);
// after
SoundInstanceStreamedBuffer streamed = null;
try { streamed = new SoundInstanceStreamedBuffer(listener, soundStreamedBuffer, spatialized: false, useHrtf: false); }
catch (Exception) { streamed = null; /* audio unavailable */ }
Defensive patterns

Strategy: try-catch

Validate before calling

if (audioEngine.State == AudioEngineState.Invalidated)
    return null; // skip streamed playback
if (liveStreamedBuffers >= MaxConcurrentStreams)
    return null;

Type guard

bool CanStreamAudio(AudioEngine engine) => engine != null && engine.State == AudioEngineState.Initialized;

Try / catch

SoundInstanceStreamedBuffer buffer = null;
try
{
    buffer = new SoundInstanceStreamedBuffer(listener, soundStreamedBuffer, spatialized: false, useHrtf: false);
}
catch (Exception ex) when (ex.Message.Contains("AudioLayer Source"))
{
    Log.Warning("Streamed audio source allocation failed: {0}", ex.Message);
}

Prevention

When it happens

Trigger: Creating a SoundInstanceStreamedBuffer (streamed media playback, e.g. through SoundInstance/ media system) when the backend returns a zero source pointer: missing audio device, too many live sources, or unsupported spatialized/HRTF/directional configuration.

Common situations: Streaming music/video on devices without an active audio output, VMs or remote desktops without audio redirection, mobile apps exceeding the platform source cap with many simultaneous streams, requesting spatialized HRTF playback on unsupported backends.

Related errors


AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14). Data as JSON: /api/errors/7b14879124cda51e. Report an issue: GitHub.

Appendix: source

Thrown at sources/engine/Stride.Audio/SoundInstanceStreamedBuffer.cs:49

        {
            this.scheduler = scheduler;
            Listener = listener;
            engine = soundStreamedBuffer.AudioEngine;
            sound = soundStreamedBuffer;
            spatialized = soundStreamedBuffer.Spatialized;

            if (engine.State == AudioEngineState.Invalidated)
                return;

            //We first create the soundSource so that it gets initialized and can give us sampleRate and Channels info
            soundSource = streamedSource = new StreamedBufferSoundSource(this, this.scheduler, mediaDataUrl, startPosition, length);

            //Create the AudioLayer source
            Source = AudioLayer.SourceCreate(listener.Listener, soundStreamedBuffer.SampleRate, streamedSource.MaxNumberOfBuffers, 
                soundStreamedBuffer.Channels == 1, spatialized, true, useHrtf, directionalFactor, environment);

            if (Source.Ptr == IntPtr.Zero)
                throw new Exception("Failed to create an AudioLayer Source");

            ResetStateToDefault();
        }

        public void Seek(TimeSpan mediaTime)
        {
            streamedSource.Seek(mediaTime);
        }

        public bool ReachedEndOfMedia()
        {
            return streamedSource.ReachedEndOfMedia();
        }

        public bool SeekRequestCompleted()
        {
            return streamedSource.SeekRequestCompleted();
        }

View on GitHub (pinned to 96fad776d2)