Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Null Reference Exception Playing SoundStream #22

Open
Eightvo opened this issue Jun 10, 2021 · 2 comments
Open

Null Reference Exception Playing SoundStream #22

Eightvo opened this issue Jun 10, 2021 · 2 comments

Comments

@Eightvo
Copy link

Eightvo commented Jun 10, 2021

        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
Copy link
Author

Eightvo commented Jun 10, 2021

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.

@feliwir
Copy link
Owner

feliwir commented Jan 24, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants