XNA Sound API bug

Started by
4 comments, last by XXChester 12 years, 8 months ago
So I have been trynig to fix this for weeks in my game but to no avail can I figure out a solution so for the past few hours I have been searching goole with the exception and I found a couple articles and I think I found a solution but it does not sit well with me and I am wondering if there is another way to solve the problem.

Basically the problem is intermittent and only occurs in debug mode when you exit the game while a sound effect is playing. Originally I was just using the SoundEffect class to play sound effects and thought that the problem may be tryng to dispose of a SoundEffect while it was playing. So I wrote an SFXEngine into my engine that would properly dispose of sound effects by using SoundEffectInstance's and stopping them before calling .Dispose(). To my major dissatisfaction (although having the SFXEngine is much better in the long run) the problem continued to show up.

The error is below;
{"Attempted to read or write protected memory. This is often an indication that other memory is corrupt."}
at Microsoft.Xna.Framework.Audio.AudioCallbackDispatcher.IsEventRegistered(EventType type)
at Microsoft.Xna.Framework.Audio.AudioCallbackDispatcher.UnregisterEvent(EventType type)
at Microsoft.Xna.Framework.Audio.KernelMicrophone.ShutdownCaptureEngine()
at Microsoft.Xna.Framework.Audio.MicrophoneUnsafeNativeMethods.ShutdownCaptureEngine()
at Microsoft.Xna.Framework.Audio.AudioRendererShutdownHandler.AppExitingEventHandler(Object sender, EventArgs args)


So after searching for a couple of hours and trying things (and testing my game repeatadly sense it is intermittent) I found a solution that says do NOT call Dispose on your SoundEffects, let the content manager handle it by calling ContentManager.Unload() and ContentManager.Dispose(). From what I can tell this appears to fix the problem (I tried starting and shutting down about 30 times which I would usually see it once by then). The problem is this does not sit right with me. Coming from a raw API I know that you are always supposed to call dispose to clean up unmanaged resources, so not calling it directly and hoping the content manager cleans it up is not sitting well.

Basically from what I can see from googling the issue, is that this is a very known problem with the XNA framework but there doesn't seem to be any solutions (other than the ContentManager route...which I cannot confirm until I run the game many more times and don't see it) around. So I am asking if anyone here has run into this and how did they solve it or how do you handle playing and disposing of sound effects in your games.

Thanks.

Remember to mark someones post as helpful if you found it so.

Journal:

http://www.gamedev.net/blog/908-xxchesters-blog/

Portfolio:

http://www.BrandonMcCulligh.ca

Company:

www.gwnp.ca

Advertisement
I'm not aware of any reason you need to manually call Dispose() on a sound effect. Every XNA game I've seen or wrote code for has not done it. Do you have an abnormally large amount of sound effects and music files, such that you can't just load them all at game start?

I'm not aware of any reason you need to manually call Dispose() on a sound effect. Every XNA game I've seen or wrote code for has not done it. Do you have an abnormally large amount of sound effects and music files, such that you can't just load them all at game start?



In this particular game I am pre-loading everything at the start but I don't usually. I only have about 20 sound effects which I am loading at the start. It is just habbit coming from a raw API to always dispose of everything. I guess from the sounds of it I will just have to comment my dispose that there is a specific reason to not manually dispose of sound effects and just bite the bullet and let the content manager handle it.

Thanks for the reply.

I will keep monitoring this post for a couple days incase someone else would like to comment.

Remember to mark someones post as helpful if you found it so.

Journal:

http://www.gamedev.net/blog/908-xxchesters-blog/

Portfolio:

http://www.BrandonMcCulligh.ca

Company:

www.gwnp.ca


Coming from a raw API I know that you are always supposed to call dispose to clean up unmanaged resources, so not calling it directly and hoping the content manager cleans it up is not sitting well.

Ummm, you're not dealing with unmanaged resources though.

Former Microsoft XNA and Xbox MVP | Check out my blog for random ramblings on game development


[quote name='XXChester' timestamp='1311279562' post='4838620']
Coming from a raw API I know that you are always supposed to call dispose to clean up unmanaged resources, so not calling it directly and hoping the content manager cleans it up is not sitting well.

Ummm, you're not dealing with unmanaged resources though.
[/quote]
Well technically you are, but the content pipeline handles it for you. I need to just wrap my ahead around that and get used to it.

On a side note, letting the ContentManager handle the disposal of SoundEffectInstances did not correct this problem, it appears to have made it even more rare but it is still there. I was working on my game this weekend and I did get it to throw the exception once on exit. So I am still looking for how XNA developers handle the disposal of sound effects in there games.

Thanks.

Remember to mark someones post as helpful if you found it so.

Journal:

http://www.gamedev.net/blog/908-xxchesters-blog/

Portfolio:

http://www.BrandonMcCulligh.ca

Company:

www.gwnp.ca

No one wants to comment on how they handle playing sound effects and the disposal? I have tried just letting the ContentManager dispose of the sound effects on shut down but this does not clear up the accessviolationexception that the xna sound API is throwing in debug mode.

Remember to mark someones post as helpful if you found it so.

Journal:

http://www.gamedev.net/blog/908-xxchesters-blog/

Portfolio:

http://www.BrandonMcCulligh.ca

Company:

www.gwnp.ca

This topic is closed to new replies.

Advertisement