SharpAudio icon indicating copy to clipboard operation
SharpAudio copied to clipboard

Null Reference Exception Playing SoundStream

Open Eightvo opened this issue 4 years ago • 2 comments

        private bool doEmitSound(PlaySFX req, GameState state, Instant instant)
        {
            if (!allowSFX)
                return true;
            state.Messages.EmitMsg(new ConsoleInput($"Playing {req.Resource}"));
            if (!soundboard.ContainsKey(req.Resource))
                soundboard.Add(req.Resource, new SoundStream(AssetManager.FindFileStream(req.Resource), sfxEngine));
            soundboard[req.Resource].Volume = (currentVolume * req.Volume);//Should be at most 1*1.
            soundboard[req.Resource].Play();
            return true;
        }

This code plays the sound as expected the first time, but fails with a null reference exception when the volume property is modified or the play method is called. the second time regardless of being a new SoundStream or an existing SoundStream.

Eightvo avatar Jun 10 '21 03:06 Eightvo

Even the following is throwing the same null reference exception on second execution:


            var ss = new SoundStream(AssetManager.FindFileStream(req.Resource), new SoundSink(sfxEngine, null), false);
            ss.Volume = (currentVolume * req.Volume);
            ss.Play();
            return true;

Are there threading implications between the SoundEngine and SoundStream? For example, I am creating the AudioEngine on the primary thread, but this logic is being executed by an non primary thread.

Eightvo avatar Jun 10 '21 13:06 Eightvo

This might be fixed on Windows already. Can you check please?

feliwir avatar Jan 24 '22 14:01 feliwir