flibitijibibo / FNA-MGHistory

FNA - Accuracy-focused XNA4 reimplementation for open platforms
http://fna-xna.github.io/
246 stars 37 forks source link

Null reference when disposing sound effect after checking sound device exists #329

Closed jorisdormans closed 9 years ago

jorisdormans commented 9 years ago

I have a bug where FNA throws a null reference exception when FNA tries to dispose the SoundEffect I tried to create in order to test whether a sound device is present on the computer. The NoAudio exception is caught (although the no sound enabled message is displayed nonetheless). So I can disable other sounds, but as soon as the garbage collector kicks in the game crashes... Bit of a catch 22 here.

Any ideas? Is there a work around for this issue?

I've tried forcing the the NoAudio exception in another way, but I couldn't find any where no SoundEffect is created.

jorisdormans commented 9 years ago

Just a quick update. For now I fixed the issue by inserting the following if statement before line 223 in SoundEffect.cs:

                if (AudioDevice.ALDevice!=null)
                    AudioDevice.ALDevice.DeleteBuffer(INTERNAL_buffer);
flibitijibibo commented 9 years ago

Ah, so it just needs an if check? That works for me:

https://github.com/flibitijibibo/FNA/commit/ec780d50c1132b2928a42076e7a38a23ac554f6a

Note that we're still throwing an Exception here; this just describes the error a little less vaguely. Buffers get generated at the constructor so objects technically shouldn't be generated at all...? Or is it INTERNAL_buffer that's null maybe?

flibitijibibo commented 9 years ago

This probably works better and skips a function call:

https://github.com/flibitijibibo/FNA/commit/a058234e7a20c4437533f74640af1e73145c29f0

flibitijibibo commented 9 years ago

Checking on this at the 3-day mark. Anything new happen with the above changes?

flibitijibibo commented 9 years ago

Closing due to old age, but I'm pretty sure I fixed this with the above commits anyway...