0
\$\begingroup\$

Some users (but not all) are reporting a periodic crash in my XNA game. They say it's happening every 15 to 20 minutes. I am unable to replicate this myself, so I asked users to send me error logs. Here is the error log one user gave me which reported an access violation:

Exception: System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

at Microsoft.Xna.Framework.Audio.KernelSoundEffectInstance.SetVolume(KernelSoundEffectInstance* , Single volume)
at Microsoft.Xna.Framework.Audio.SoundEffectUnsafeNativeMethods.SetVolume(UInt32 soundEffectInstanceHandle, Single volume)
at Microsoft.Xna.Framework.Audio.SoundEffectInstance.set_Volume(Single value)
at Game.DynamicSong.Update()
at Game.DynamicMusicPlayer.Update()
at Game.Game1.Update(GameTime gameTime)
at Microsoft.Xna.Framework.Game.Tick()
at Microsoft.Xna.Framework.Game.HostIdle(Object sender, EventArgs e)
at Microsoft.Xna.Framework.GameHost.OnIdle()
at Microsoft.Xna.Framework.WindowsGameHost.RunOneFrame()
at Microsoft.Xna.Framework.WindowsGameHost.ApplicationIdle(Object sender, EventArgs e)
at System.Windows.Forms.Application.ThreadContext.System.Windows.Forms.UnsafeNativeMethods.IMsoComponent.FDoIdle(Int32 grfidlef)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at Microsoft.Xna.Framework.WindowsGameHost.Run()
at Microsoft.Xna.Framework.Game.RunGame(Boolean useBlockingRun)
at Microsoft.Xna.Framework.Game.Run()
at Game.Program.Main(String[] args)

Important note: My game dynamically fades music in and out depending on what you're doing and where you are. So I'm calling volume-related methods on looping music multiple times every update. I can't see how this could cause such an error though.

So do you think this is an error on my part or is it a bug with XNA?
How could I go about fixing this or getting around it?

Would it be safe (or even possible) to just not close the program when this exception is thrown? (probably not?)

Thanks in advance.

Update: Users are reporting that the log is identical for each crash. This means it's always happening in the KernelSoundEffectInstance class. Prior to this I was worried it may be happening in different places each time, like this person here: https://stackoverflow.com/questions/4074585/attempted-to-read-or-write-protected-memory-this-is-often-an-indication-that-ot

\$\endgroup\$
3
  • \$\begingroup\$ Are you using multithreading? My first guess would be a synchronization error. \$\endgroup\$ Apr 26, 2016 at 9:40
  • \$\begingroup\$ @JánosTuránszki I am multithreading for things like loading and saving but nothing related to sound or even the game logic. However, I'm pretty sure XNA's sound classes use threads to play sounds alongside whatever your program is doing. \$\endgroup\$ Apr 26, 2016 at 15:30
  • 1
    \$\begingroup\$ same here gamedev.stackexchange.com/questions/115176/… and here forums.terraria.org/index.php?threads/… \$\endgroup\$
    – EnemyArea
    Apr 27, 2016 at 20:27

0

You must log in to answer this question.

Browse other questions tagged .