My game is about ready for release (your basic space shooter) and I’ve spent the better part of the last 2-3 weeks trying to find my memory leaks.
Today just on a whim, I turned off my sound effects and I can play my game for levels without seeing a blip of a leak.
Now my audio isn’t that complex.
I have my own playSound function
local function playSound(sound)
if soundOn then
audio.play( sound )
end
end
which just wraps a check around audio.play so I will return if the player has turned off effects. All of these sounds are loaded at the beginning via handle = audio.loadSound(“sound.wav”) at the end of my main.lua file before firing up any event listeners and calling my starting function.
I load up about 15 sounds this way (booms, weapons firing, shields getting hit). Many of these fire every round and I don’t leak. But when I die or kill a boss, if I have my sound effects on, I get 512 byte leaks coming from the Audio Mixer.
Just before I load up my sounds, I call this block of code:
audio.reserveChannels(5)
local masterVolume = audio.getVolume()
-- print("volume " .. masterVolume)
audio.setVolume(0.80, { channel = 1 }) -- music track
audio.setVolume(0.66, { channel = 2 }) -- boss sound
audio.setVolume(1.0, { channel = 3 }) -- voice overs
audio.setVolume(1.0, { channel = 4 }) -- alien voice
audio.setVolume(0.25, { channel = 5 }) -- weak explosion
I use audio.loadStream() to load in one of 4 sound tracks that I rotate each level and play on reserved channel 1. Initially I thought this could be the source of my leak, but I let players turn sound and music off separately and while testing it, I don’t leak while music is playing, only with sound effects are.
While the boss is on the screen, I loop some evil mood music. I commented it out and it didn’t have any effect on the leaks.
Like my playSound() function, I have a playVoice() which plays audio handles (preloaded like the SFX) but on a specific channel so I can tweek the volume of the sounds.
Channel 4 is currently not being used. The alien voice tracks added a lot of weight to the package and really didn’t add to the game.
Channel 5 is there to take one of my explosion sounds and make it be much quieter. I should find another sound I know. But I commented it out too.
I eventually got down to a point of only commenting out the audio.play function in the playSound() function above. When its not commented out, I leak. When its commented out or I have my sfx turned off, I don’t leak.
The weird thing is I fire off a lot of sounds each round and it only seems to leak after a level change and then I get spotty leaks afterwards.
Has anyone else seen leaks coming from the Audio subssytem (and I get a leak while I’m still loading which I got without my main.lua file empty that is charged to the Audio Mixer)
There has to be something in my code but when commenting out audio.play stops the leaks… I would think that others would be reporting these leaks if it were in Corona SDK (build 484).
Thoughts? I really want to release the game this week, but I’m afraid that Apple won’t approve it with these rampant leaks.
Thanks
Rob
[import]uid: 19626 topic_id: 9783 reply_id: 309783[/import]