PDA

View Full Version : Help With LUA And OGGs



DimensionT
October 17th, 2007, 03:10
Ok, here's the deal...

I have a menu before my game starts with a song playing. Then I have my game with a different song playing (with gamestates seperating the two).

When you select "Start Game" in the menu, it stops the title song and loads one for the game before changing gamestates. If you're in the game and press start to select "Return To Menu", it stops the game song and reloads the title music... Then changes gamestates again.

My problem is around 50% of the time, it freezes when changing between gamestates that load music. The "Paused" gamestate works perfectly fine because it plays the same music as the game (untill you tell it to return to the menu).

I took out every function that has to do with playing/loading OGG files, and I didn't have any problems what-so-ever. So I know the issue is with playing or loading the music.

Any help would be appreciated!!!

yaustar
October 17th, 2007, 10:19
Are you streaming the music or loading it into memory first?

DimensionT
October 17th, 2007, 10:31
Well, I do Ogg.load() to load it, then Ogg.play() when I want to play it... But it seems like it's streaming it anyway. There's no load time and the memory card light is constantly flashing.

dangee
October 17th, 2007, 15:19
if you have enough free memory , try loading both Oggs during initialisation
rather than during gameplay.
Otherwise, making the garbage collector more aggressive may help.

DimensionT
October 17th, 2007, 19:48
I don't load them during gameplay at all. I load the song for the actual game right after you press X on "Start Game" in the menu.

It wouldn't matter either way though, because it's aparently streaming them. I could put Ogg.load() in the game code 20 times and it wouldn't slow down at all.

It's working perfectly with .XM files, but I'd much rather use .OGG if it's possible.

dangee
October 21st, 2007, 10:44
well, it looks like the streaming ogg's overloading lua then.
theres a few things you can try:

song = song or ogg:load(songFile) --to avoid memory leak
Change all locals to globals to reduce pressure on the stack.
When gamestate changes, song = nil , immediately followed by a full garbage collection cycle
Reduce the framerate
Add a System.sleep() into your main loop to give the streaming more CPU.
Increase CPU speed

Ultimately tho, you'll avoid no end of hassles by using a non-streaming format.