Texture Memory problem causing the game to crash on iPad

Hi Guys,

This has been driving me crazy, I been building new levels for a corona game that I am working on. To gain the aesthetic feel that I would like in the game, I have placed up to 8 different layers of parrallax and art for the game. The first time I tried to play the build on my iPad, it crashed, giving me an error which when I googled, said that I am using too much texture memory.

To solve that, I reused the first half of my background layer, and flipped it, to have a mirrored effect background, thus reducing the amount of textures memory. In the simulator, it showed me that I reduced the texture memory by half, to 300 mb. 

Again, I put it on device, and the level works halfway, before crashing the ipad again. Do I need to reduce the layers? Is there another way of fixing this without compromising the art and graphics? Here is a screengrab of the error from xcode when the game crashes and also the log 1421472_10153477413215150_653948825_n.jp

Thanks in advance guys! :smiley:

Hi @siddigie1234,

There are various methods and “tricks” to help reduce and manage texture memory. Have you read some of the tips in this document under “Conserving Texture Memory”?

http://docs.coronalabs.com/guide/basics/optimization/index.html#texturemem

The main thing is to manage how many textures you have loaded at once. If you can clean up and remove textures when they’re no longer needed, that will go a long way.

Also, note that the latest public release with Graphics 2.0 features many new graphical abilities, including the ability to fill shapes with smaller repeating textures (like a tiled wallpaper) and other things. Depending on your design, this may go a long way in reducing the need for really large textures.

Hope this helps somewhat,

Brent Sorrentino

Thanks for the help Brent, Ill try the above methods and hope it works! :smiley:

What are the guidelines for texture memory? I’ve gone from about 150M to now 205M and I don’t know what the consequences are.

Has anyone tried dynamic loading? How has that worked out? Can you load spritesheets, draw and unload them?

According to my tests, you can load and unload sprite sheets without a noticable memory leak (texture memory stays constant and memory usage doesn’t fluctuate) using 2048 squared textures.

            local sheetInfo = require(“images.sprites.p”…num)
            local con = “images/sprites/p”…num…".png"
            local myImageSheet = graphics.newImageSheet( con, sheetInfo:getSheet() )
            if sprite ~= nil then
                sprite:removeSelf()
                sprite = nil
            end
            sprite = display.newSprite( myImageSheet , {frames={sheetInfo:getFrameIndex((num*24)…“p”)}} )
            sprite:scale(0.3,0.3)
            group:insert(sprite)
            sprite.x = 100
            sprite.y = 100
            unrequire(“images.sprites.p”…num)
            myImageSheet = nil
 

So someone must have a class or be able to whip up a class to search for a texture, pull it, unload the texture making texture management a no-brainer. More importantly, why doesn’t corona do this automagically? I assume it’s thrashing the memory (I get that) but for many graphics, I rather just have a drawonce and not have to worry about my memory being eaten up by images that literally only get drawn once.

Hi @siddigie1234,

There are various methods and “tricks” to help reduce and manage texture memory. Have you read some of the tips in this document under “Conserving Texture Memory”?

http://docs.coronalabs.com/guide/basics/optimization/index.html#texturemem

The main thing is to manage how many textures you have loaded at once. If you can clean up and remove textures when they’re no longer needed, that will go a long way.

Also, note that the latest public release with Graphics 2.0 features many new graphical abilities, including the ability to fill shapes with smaller repeating textures (like a tiled wallpaper) and other things. Depending on your design, this may go a long way in reducing the need for really large textures.

Hope this helps somewhat,

Brent Sorrentino

Thanks for the help Brent, Ill try the above methods and hope it works! :smiley:

What are the guidelines for texture memory? I’ve gone from about 150M to now 205M and I don’t know what the consequences are.

Has anyone tried dynamic loading? How has that worked out? Can you load spritesheets, draw and unload them?

According to my tests, you can load and unload sprite sheets without a noticable memory leak (texture memory stays constant and memory usage doesn’t fluctuate) using 2048 squared textures.

            local sheetInfo = require(“images.sprites.p”…num)
            local con = “images/sprites/p”…num…".png"
            local myImageSheet = graphics.newImageSheet( con, sheetInfo:getSheet() )
            if sprite ~= nil then
                sprite:removeSelf()
                sprite = nil
            end
            sprite = display.newSprite( myImageSheet , {frames={sheetInfo:getFrameIndex((num*24)…“p”)}} )
            sprite:scale(0.3,0.3)
            group:insert(sprite)
            sprite.x = 100
            sprite.y = 100
            unrequire(“images.sprites.p”…num)
            myImageSheet = nil
 

So someone must have a class or be able to whip up a class to search for a texture, pull it, unload the texture making texture management a no-brainer. More importantly, why doesn’t corona do this automagically? I assume it’s thrashing the memory (I get that) but for many graphics, I rather just have a drawonce and not have to worry about my memory being eaten up by images that literally only get drawn once.