Posts Tagged ‘XNA’

XNA Studio 3.1 Cures the Audio Memory Leak!

Friday, July 17th, 2009

Well, I finally upgraded to XNA Studio 3.1 and the audio-related memory leak appears to be gone now!

That was easy…

Just goes to show you that even in managed environments, you still have to pay attention and know what you are doing when it comes to managing resources…

XNA Audio Troubles…

Sunday, July 12th, 2009

So as I am adding sound effects to the game, I noticed that over time it would consume more and more memory and start to slow down. Another thing that would happen is that the audio would drag out and get sloooooooooooooooooow.

Now, I consider myself a pretty decent developer and I took steps to ensure that objects are reused where possible, instead of being new-ed up over and over again (.NET may be an environment that takes care of a lot of the dirty work of managing memory, but you still need to remember that it is a limited resource and code accordingly).

I should have taken the slowed sounds as a hint, but I went down the path of tracking objects and Garbage Collections to make sure that the object caches were healthy and the few objects that are destroyed and recreated are cleaned up in an orderly fashion as well.

After going though all that, I realized that the XACT-related classes are the culprits. If I turn off the sound, memory usage remains stable, even after running the game (in its attract mode) for more than 12 hours. It normally started to get slow after 45 minutes or so.

Looking up memory-related issues with audio in XNA, I read that other people have a similar problem, but only if they are not calling Update(…) in the Audio Engine during each frame. However, I AM calling Update(…) and am still having the problem. I even added additional calls to Update(…) from other locations in the code, but to no avail.

I even tried manually managing each Cue instance by storing them in a collection when they are played and then Dispose()-ing them when they are done playing. No difference.

I have temporarily resolved the issue by manually cleaning up and reallocating the Audio Engine at certain times during the game — between the end of a level and the start of a new one, and whenever the Title Screen transitions to the next screen when the game is in attract mode. Kludgy? Yep! But it works, and until an updated version of the XNA Framework is available that possibly fixes this bug, it will have to do.

Oh, and I used The GIMP to create a starburst graphic and am briefly displaying it as a “superluminal flash” (the warp equivlent of a sonic boom) when the player’s ship goes to warp. It looks sweet, even if I do say so myself! 🙂

XNA Wonderfulness

Monday, June 29th, 2009

So having some extra time on my hands, I have started playing around with XNA Game Studio again (version 3.0 this time). I picked up a shooter tutorial created by PHStudios which gives you a functional, but very simple game.

I started about the shooter that I have always wanted to write. It was going to look and behave much like an old arcade shooter. I wanted the details of the game to be just like an arcade game. For example, when it first starts, it will show a garbage screen quickly followed by an alphanumeric test (with some sprites in there), grids and colors, and ROM and RAM test (with successful results, of course), and then jump into attract mode waiting for someone to coin it up.

I have started this dream by taking the shooter tutorial and making extensive changes to it. I have since extended it by adding the following features:

  • Background Stars with multiple behaviors and effects (stopped, moving, warp, etc.)
  • Improved collision detection (only objects “near” each other are checked, and multiple collision rectangles are used for better checks)
  • Multiple enemies, including mini-bosses and bosses
  • Bonus items that “fall” that give you health, weapons, points, etc.
  • Additional weapon types
  • “Buddy” ships that dock to your ship for additional firepower
  • Auto-pilot/behavior for the enemy ships (i.e. what they do when the come on screen)
  • A “story” manager that manages each game level (i.e. what ships appear when and what their behavior is, also handles “waves” of attacks)
  • Explosions
  • Sound
  • A console that you can enter commands on to change/adjust the game’s behavior
  • And more!

Some of the features could be useful to others (like the background star, console, input manager) and I will release them free-for-use once I am done.

I am starting to think that I may be able to actually sell it once it is complete. I think that the retro arcade behavior of the game may appeal to some, and I hope that I can make it fun and challenging enough to get people interested.

Oh, and before I forget, there is a really nice free tool called (sfxr ) that can create sound effects. I am using it for the retro-like sounds in the game. I have also created a bunch of different types of sounds that I will likely also release free just as a time-saver to others.