Crashing due to out of memory, or schedule overload?
by BeyondtheTech · in iTorque 2D · 06/07/2009 (9:30 am) · 5 replies
I'm still in the middle of building my game, and I'm running into a few obstacles when testing it out on the iPhone.
- the game used to inconsistently crash when loading a new level/scene. In my method, I would simply reload the same level so I could reset all the objects. I used the schedule method so that it wasn't instantaneous. I reduced this issue by creating a SimGroup and simply calling the entire group to delete, however...
- the game will eventually crash after several minutes of gameplay. There's no crash log for my game, but I did get crash logs on the iPhone with the prefix "LowMemory*.log"
-as the game progresses, I notice that the scheduling seems to get out of whack. I have an onGameTimer function that would schedule itself at every second to perform various tasks, one of which is a countdown to the end of the level. After a while, the countdown would really fun fast, showing that the schedule(1000,0,"onGameTimer"); is being called quicker than one second each.
It's leaking somewhere, or something's gone awry and it doesn't happen on the desktop, probably cause it can handle a lot more before crashing. Am I going about this wrong? Perhaps I should not be scheduling itself inside the function? Kinda lost.
- the game used to inconsistently crash when loading a new level/scene. In my method, I would simply reload the same level so I could reset all the objects. I used the schedule method so that it wasn't instantaneous. I reduced this issue by creating a SimGroup and simply calling the entire group to delete, however...
- the game will eventually crash after several minutes of gameplay. There's no crash log for my game, but I did get crash logs on the iPhone with the prefix "LowMemory*.log"
-as the game progresses, I notice that the scheduling seems to get out of whack. I have an onGameTimer function that would schedule itself at every second to perform various tasks, one of which is a countdown to the end of the level. After a while, the countdown would really fun fast, showing that the schedule(1000,0,"onGameTimer"); is being called quicker than one second each.
It's leaking somewhere, or something's gone awry and it doesn't happen on the desktop, probably cause it can handle a lot more before crashing. Am I going about this wrong? Perhaps I should not be scheduling itself inside the function? Kinda lost.
#2
A thing to note with my experience is that it will almost always run when I start it through xcode (but usually crashes with error 101 after playing for a while) but when I start it from the device itself, it will always crash. Sometimes I see my level show up for a second before it crashes. That happens 100% on iphone 3G. It is much less often on the 1st-gen iphone and hardly ever on the ipod touch.
06/10/2009 (4:43 pm)
Just wanted to add that I am encountering similar issues which hopefully others can help out with.A thing to note with my experience is that it will almost always run when I start it through xcode (but usually crashes with error 101 after playing for a while) but when I start it from the device itself, it will always crash. Sometimes I see my level show up for a second before it crashes. That happens 100% on iphone 3G. It is much less often on the 1st-gen iphone and hardly ever on the ipod touch.
#3
I'm adding a boolean $gameInProgress and will set it to false once the game level or the game itself is over.
06/10/2009 (7:07 pm)
I figured it out with almost a slap to the forehead. In staring at the code long enough, I realized that the function never stops repeating itself, and if it ever gets called out of sequence or manually again, another repeating chedule of this function will end up running along the first one.I'm adding a boolean $gameInProgress and will set it to false once the game level or the game itself is over.
if ($gameInProgress) schedule(1000,0,"onGameTimer");
#4
06/11/2009 (5:51 am)
Well, I removed duplicate scheduling, but it still manages to crash itself after several minutes of gameplay. Something else is up and I can't find it, and my game is really not that complex in design.
#5
08/26/2009 (9:51 am)
Did you figure this out in the end?
Torque Owner BeyondtheTech
Default Studio Name
Just out of curiosity, the following should be OK, yes?
function onGameTimer() { ... (do scheduled tasks) ... schedule(1000,0,"onGameTimer"); }I use safeDelete and setLifetime on all required objects, and as I stated earlier, all objects I create during the level are placed in a SimGroup, then I call to delete the entire group and recreate it upon the start of the next level.
The only thing of note is my audio playback. I use the sample code provided here to simply call a playSE("bullet_fired",1); and it goes to create a new audio profile on the fly if there isn't one. Considering I have over a 100 sound effects, I'm trying to downsample to 22K to see if that does anything.
Otherwise, I'm scratching my head.