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 after disposing and re-initializing object #21

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

Comments

@Eightvo
Copy link

Eightvo commented Jun 10, 2021

if (!String.IsNullOrEmpty(_nextSongToPlay))
            {
                if (activeMusic!=null && activeMusic.State== SoundStreamState.Playing)
                {
                    activeMusic.Stop();
                    activeMusic.Dispose();
                }
                activeMusic = new SoundStream(System.IO.File.OpenRead(_nextSongToPlay), musicEngine);
                    System.Threading.Thread.Sleep(100);
                    activeMusic.Volume = currentVolume;
                        activeMusic.Play();
                _nextSongToPlay = null;
            }

It seems that there is some kind of race condition that is triggered by calling the activeMusic.Stop(); method... without putting a System.Threading.Thread.Sleep setting the volume on the activeMusic soundstream causes a null exception to be thrown.

This exception occurs if the activeMusic soundstream is or is not disposed, but only if it was not null before creating the New soundStream

@feliwir
Copy link
Owner

feliwir commented Jun 10, 2021

I created a TestCase like this and can't reproduce it:

        [BackendFact(AudioBackend.OpenAL, AudioBackend.XAudio2)]
        public void Reuse()
        {
            var mp3Stream = typeof(SoundStreams).Assembly.GetManifestResourceStream("SharpAudio.Tests.Assets.test.mp3");

            var engine = AudioEngine.CreateDefault();
            var soundStream = new SoundStream(mp3Stream, new SoundSink(engine));

            soundStream.Play();
            soundStream.Dispose();
            
            mp3Stream = typeof(SoundStreams).Assembly.GetManifestResourceStream("SharpAudio.Tests.Assets.test.mp3");
            soundStream = new SoundStream(mp3Stream, new SoundSink(engine));
            soundStream.Volume = 1.0f;
        }

Could you share which testfile you're using?

@Eightvo
Copy link
Author

Eightvo commented Jun 10, 2021 via email

@Eightvo
Copy link
Author

Eightvo commented Jun 10, 2021 via email

@Eightvo
Copy link
Author

Eightvo commented Jun 10, 2021 via email

@Eightvo
Copy link
Author

Eightvo commented Jun 10, 2021 via email

@Eightvo
Copy link
Author

Eightvo commented Jun 10, 2021 via email

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