Sunday, June 27, 2010

It's 3am, do you know where all your threads are?

If you're using the MediaPlayer framework, it turns out that no you don't. Moreover, you can't know. It looks like every time a play action is triggered (this includes a looping Song looping or changing songs) two new threads are created. And they never get disposed.

I discovered this when I hit a memory exception after four hours of playing and had 1147 threads open. The MediaPlayer interface is convenient, but I can't use it if it has a memory leak. Problem is that crashes in any form are grounds for a XBLIG failing in review.

So I have some alternatives:
Manually trigger sound effects, basically roll my own framework. Then I *ought* to handle the user playing their own music. Also, sound effects don't get compressed.
Use the XACT framework. It's a real pain to work with, and all I really gain is compression over just using sound effects.
Try to kill the rouge threads. As nears as I can tell, this is impossible. Yay managed code.
Or, (and this is the one I like) just stop playing music when memory gets close to full. It's easy to implement, and the few players that run the game that long will probably just think it's a small bug.


So this leads me right into why I was playing the game for four hours. The game is playable start to finish. I have to work on a credits sequence and revise saving/loading code, but the game is there, I played it start to finish.

Well, when I say play, the AI controlled all my characters. It's literally 1 line of code to enable, and it makes debugging victory screens and other things so much easier. I wanted to get a good number for how long the game actually was. The AI is a lot faster than a player, but it took about three hours for the AI to beat the game. I'd expect another hour just for user input, more if you didn't know where you were going, and more if you lost more frequently. I think 4-5 hours to beat the game is a very safe gameplay estimate.

I'm also a bit more confident about the difficulty now. The AI is a bit brute force, so if it can manage, I think a player will be able to. This doesn't let me test the learning curve though. That is what testers are for.

It looked like I actually did get the difficulty curve about where I wanted. For about the first half of the game you can sort of bumble about. Even with a bad mix of characters you can still win. The second half requires some thought, as do the optional battles. The last three were challenging, but not impossible. If anything, the last fight was a little too easy.

Anyway, enough rambling, have a screenshot of the character select screen after I made some improvements earlier this week:

No comments:

Post a Comment