Sudden app crash! x(

I formated the iPod touch 4G, synced it again and copied my game, same behavior. As soon as the game starts, it gets low memory warning and then quits after a like 1-2 seconds.

And also Mail and is getting closed with Signal code 9.

I don’t know what else to do.

This may be related to audio because if I don’t interact with the game, it won’t quit but if I do, and that causes sound effect playback, it will soon crash.

I simply playback audio with audio.play, do I have to clean afterwards or something?

I’m testing the game on several other devices and it has only this problem on one of deices that is iOS 5.1.1. Is there any known Corona bugs with this version?

Tell us a bit more about your iPod?  What generation?  How much memory does it have?  How much memory is your app using?  Are you trying to handle low memory warnings?

Thanks Rob for the reply.

My iPod is a 4th generation 8Gb iPod Touch. I honestly don’t know about it’s memory because I think they are all the same between iPods and they only differ on their storage, correct me if I’m wrong.

I’m not sure about how much memory my app is using, I tried the profiler from spriteloq and it showed it’s using more than 100mb! I honestly have absolutely no idea what causing so much memory because my game is very simple. Maybe that profiler is wrong.

You asked about how I handle low memory warning, I honestly don’t know how I can get these warnings and how to handle them.

Let me know how I can help to help you further.

Thanks again, much appreciated.

For the low memory situation, see:

http://docs.coronalabs.com/api/event/memoryWarning/index.html

100MB is a lot for an older device.  But let’s get some real information instead of depending on profilers and such. 

local function memoryWarning(event)     print("\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*")     print("")     print("\* lowMemory warning - texture memory in use: ", system.getInfo("textureMemoryUsed")/(1024\*1024) .. "MB", " lua memory: " .. collectgarbage("count") .. "KB")     print("")     print("\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*")     return true end   Runtime:addEventListener("memoryWarning", memoryWarning)

When you get the memory warning, the memory information will print in your console log.

Thanks for the comprehensive reply, Rob.

Yep, problem is the memory usage:

Jul 3 13:52:54 Aidin-Zolghadrs-iPod SuperHungryMonsters\_rob[1357] \<Warning\>: \*lowMemory warning - texture memory in use: 108.265625MB lua memory: 363.8388671875KB Jul 3 13:52:54 Aidin-Zolghadrs-iPod SuperHungryMonsters\_rob[1357] \<Warning\>: \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

But what’s strange is why texture memory is over 100MB. I have two big objects that each have 9 frame animations, I have like 10 small objects that each have 3 frame animations, 3 backgrounds, and some small graphics for combo’s. That’s all.

How can I further track down the bug?

Finally some hope at the end of the tunnel.

Hi Aidin,

What is the overall canvas size of these “big objects” you mention? Are you using dynamic image selection to pick smaller versions for device(s) with smaller screens? Texture memory can get out of control really fast if you’re not careful…

Brent

To add to Brent’s post, what is your config.lua like?

Can you post some of your display.newImageRect() calls?  Are you using sprites/image sheets?  How big are they?

What size are the images you are loading.   Keep in mind that a 1030 x 1030px image is really 2048x2048x4 in memory or 16MB just for that one image.  If your image is bigger than 2048 on each side, say 2050x2050, just for fun, then it’s really a 4096x4096x4 sized memory or 64MB.  It doesn’t take much for those images to blow out the memory on older devices.

One of the reasons why we suggest using the @2x and@4x graphics is that for older devices, you can use smaller images to conserve memory.  Loading in an @4x sized graphic and scaling it down to an appropriate graphic for a smaller screen eats up memory and processing time.

Thanks Ron and Brent for the replies.

I checked that line Rob posted after each chunk that I load images and I can see that problem lies with those big images, each of those calls takes about 53MB of Texture Memory ™.

I do use ImageRect and specify multiple resolution with @ identifier. ( I just do @2x for now but will do the @4x for Retina devices as well).

Each of those big objects are in fact 3 image sheets that I load and turn them visible and invisible with “isVisible” flag, due to different gameplay circumstances.

Here is the section I load them:

function M.new(monsterType, xPos, yPos) -- Creating monsters local newMonster = display.newGroup() local sheetData = { width = 105, height = 430, numFrames = 9, -- The params below are optional; used for dynamic resolution support sheetContentWidth = 945, -- width of original 1x size of entire sheet sheetContentHeight = 430 -- height of original 1x size of entire sheet } local animationSequenceData = { { name = "idle", frames = { 1, 2, 3, 3 }, time = 1000, loopCount = 0 }, -- { name = "chew", frames = { 4, 5, 6, 7, 8, 8 }, time = 400, loopCount = 1 }, -- { name = "chew", frames = { 4, 7, 8, 8 }, time = 200, loopCount = 1 }, -- { name = "chew", frames = { 4, 6, 8, 8 }, time = 200, loopCount = 1 }, { name = "chew", frames = { 8, 9, 8, 9, 8, 8 }, time = 500, loopCount = 1 }, -- { name = "chew", frames = { 8, 8 }, time = 200, loopCount = 1 }, } if "Purple" == monsterType then local mySheet --============================== Phase 1 ============================== -- -- phase1:Sprite mySheet = graphics.newImageSheet("monster\_purple\_phase\_1.png", sheetData ); newMonster.phase1 = display.newSprite(mySheet, animationSequenceData) newMonster:insert(newMonster.phase1) -- Adding body part to the display group. -- phase1:Offset newMonster.phase1:setReferencePoint(display.TopLeftReferencePoint) newMonster.phase1.x = newMonster.x newMonster.phase1.y = newMonster.y -- phase1:Animation newMonster.phase1:setSequence( "idle" ) newMonster.phase1:play() --============================== Phase 2 ============================== -- -- phase2:Sprite mySheet = graphics.newImageSheet("monster\_purple\_phase\_2.png", sheetData ); newMonster.phase2 = display.newSprite(mySheet, animationSequenceData) newMonster:insert(newMonster.phase2) -- Adding body part to the display group. -- phase2:Offset newMonster.phase2:setReferencePoint(display.TopLeftReferencePoint) newMonster.phase2.x = newMonster.x newMonster.phase2.y = newMonster.y -- Making it invisible since we play phase 1 by default newMonster.phase2:setSequence( "idle" ) newMonster.phase2:play() -- newMonster.phase2.isVisible = false --============================== Phase 3 ============================== -- -- phase3:Sprite mySheet = graphics.newImageSheet("monster\_purple\_phase\_3.png", sheetData ); newMonster.phase3 = display.newSprite(mySheet, animationSequenceData) newMonster:insert(newMonster.phase3) -- Adding body part to the display group. -- phase1:Offset newMonster.phase3:setReferencePoint(display.TopLeftReferencePoint) newMonster.phase3.x = newMonster.x newMonster.phase3.y = newMonster.y -- Making it invisible since we play phase 1 by default newMonster.phase3:setSequence( "idle" ) newMonster.phase3:play() -- newMonster.phase3.isVisible = false

Please note that I’m showing 1x version here but that 53MB memory I mentioned earlier was from Corona simulator running the game for iPhone 4.

So my imagesheet is 945x430 in 1x and 1850x860 in 2x which I believe will take the 2048x2048 texture. (I’m not sure if it’s the case for iPod touch 4G as well, please correct me if I’m wrong.)

I can’t calculate precisely how much memory it will take but I think 2048*2048*4 which is about 16MB and since I load three of them for each monster, that is about that 53MB I reported.

So that’s the problem?

On the side note, I have another question as well, if this code is this bad, why iOS 6 won’t close my game and iOS 5 does?

I just saw that Rob asked for my config.lua file, here it is:

application = { content = { --xAlign = "center", --yAlign = "center", --xAlign = "left", --yAlign = "top", width = 320, height = 480, scale = "letterbox", fps = 60, imageSuffix = { ["@2x"] = 2, -- images with "@2x" appended will be used for iPad 3 } }, }

Actually on @2x devices, each of your three images are going to be 2048x1024x4.  Round each side up to the nearest power of two.

The problem with the iPod Touch 4 is that it has a retina display (640x960) so it wants to use your @2x graphics, but it only have 256M of memory as opposed to the iPhone 4 which has the same screen at 512M of memory.  Generally you can expect to have 25-50% of the memory available to you depending on the combination of memory size and operating system size.  I would think you probably are only going to have 50-75mb free on that device.

Those image sheets should be around 8MB each.  Do you have other images you are loading? Backgrounds? Multi-layer’ed backgrounds?  Audio?

Rob, why 8MB?

2048 x 2048 x 4 = 16.7MB and I load 6 of these which makes it 99.6MB and added with the background and other stuff I think it gets to that 106MB that I posted earlier, but you mentioned that each of these should take 8MB. Am I missing something? My best guess is that you referred to their 1x size.

So the only way I think to solve this is to not to load all these at the same time and just load one for each object and when they need, I load the new one and kill the previous one but since this happens like 20 times in a game session, wouldn’t it make the game hiccup or stutter?

And when I want to load the new image, should I load the file into the previous variable that held the previous image? Does that automatically make the previously loaded image deleted from memory or I should nullify it first?

Thanks.

You round each side up to the nearest power of two, so the 860px side rounds up to 1024 so you end up with a 2048x1024x4 texture (and the x4 is for the Red, Green, Blue and Alpha channels of the image)

Yes, that’s how I calculated in my last post.

Would you, or anyone else, please reply my two questions in my last post pelase?

Thanks.

How much audio are you using?  The three sprites are not taking up that much memory.  Perhaps its backgrounds or other items.   You probably could run into some delays particular on older devices. 

I would use the same variable and yes, you need to remove it/nil it out or else you’re not freeing up the memory.

I removed some space from height of my sprite sheet and it is now 1890x860 in 2x mode but the size they take is now around 50MB!

So since I removed space from height of my sprite, they should still use 2048x2048 because it’s the smallest power of 2 that is bigger than 1890x860 but it’s now almost half than before which was 1890x1720.

To rephrase my question, since both of the previous and the new size are in the 2048x2048 boundary, they should both consume same amount of texture memory, right? But I’m seeing that it uses less memory in the smaller texture case.

Does iPod touch 4G uses this “smallest power of 2 size” ? Apparently not, or I’m missing something here.

I think you are missing a key part of the math. You treat each side separately. 1890 rounds up to 2048 as does 1720 making it a 2048x2048 block. 1890 rounds up to 2048 but 860 only rounds up to 1024. 2048x1024x4 is 8mb.

Oh, you are absolutely right.

I think I assumed it as it was the case with fixed function graphic cards.

Thanks man.

Hi guys,

I’m having a problem at startup (Exited: Killed: 9) on my iPad 1 - and it’s preceded by a stack of Image size errors:

e.g. WARNING: Image size (2560,240) exceeds max texture dimension (2048). Image will be resized to fit.

This particular file is a spritesheet @2x.

Am I crashing because I exceeded the 2048 limit (9 times!), or am I crashing due to loading too much into memory?

i.e. If I reorganised the spritesheets to be less than 2048 in any one dimension, would I be OK, or do I need to work on reducing the size of the contents?

Thanks,

Nathan.