App crashes with display.save

I don’t know if this is a crash or a security feature.

What I’m doing is generating about 100 mask/images and saving them with display.save at startup.

In the simulator everything is fine, but on device (iPad 2 iOS 8.3) I can save only 80 of them otherwise the app crashes. I have a timer and from what I’m seeing it requires about 8+ secs to save 80, so I suspect that somehow iOS closes my app when I try to go higher because of inactivity. Is this possible?

Any way for me to avoid or work around this?

Thanks everyone.

Hi @gianmichele,

Can you post some code around how you’re doing this? I don’t see why iOS would suspend your app if there is still activity occurring (things being saved). There may be some other issue involved.

Thanks,

Brent

P.S. - Please remember to surround your code with “lua” tags for clarity:

[lua] ... [/lua]

Sure! Here’s the simple module I’m using (I wanted to test this separately).

On my iPad 2 with this code it just crashes (Simulator is fine). With 80 it runs and requires 8+ seconds to complete.

[lua]

local M = {}

local cx = display.contentCenterX
local cy = display.contentCenterY
local mRand = math.random

M.init = function()
    
    local numOfMasks = 100
    local maskGroup = display.newGroup( )
    
    local endTime
    local myText

    – Black background
    local black = display.newRect( maskGroup, cx, cy, 768*2, 768*2 )
    black:setFillColor( 0, 0, 0 )

    local loading = display.newRect( cx, cy, 768, 1024 )
    loading:setFillColor( .2, 0, 0 )

    local startTime = system.getTimer( )

    for i=1, numOfMasks do
        local size = mRand( 512 )
        local rr = display.newRoundedRect( maskGroup, cx, cy, size, size, 20 )
        rr:setFillColor( 1, 1, 1 )
        display.save(maskGroup, “mask_” … i … “.jpg”)
        black:toFront()
    end

    endTime = system.getTimer( ) - startTime
    
    myText = display.newText( endTime, cx, cy, native.systemFont, 64 )
    myText:setFillColor( 1, 1, 1 )

end

return M

[/lua]

Hi @gianmichele,

May I ask the reason for saving so many images to local storage? This looks like a fairly intensive process (thus 8 seconds and a potential crash). However, I don’t know what your reasons are for needing so many saved images… these look to be fairly simple display groups consisting of just vector objects and text, correct? Couldn’t these just be generated when needed?

Brent

Hey @Brent, my main reason is to generate different masks based on level and screen resolution. This is an extreme case, as I’m not going to do it this way (I only need about 10-15 max) and I have already found a way to optimize the process.

It would be great to have the ability to use vector display objects directly as a mask (interfaces with rounded rectangles?).

Thanks again.

Hi @gianmichele,

I think somebody came up with a way to generate dynamic masks using vector objects or images. Perhaps this is the link… I haven’t watched the episode, but check it out, or search for similar results in the forum:

https://coronalabs.com/blog/tags/dynamic-masks/

Best regards,

Brent

Hi @gianmichele,

Can you post some code around how you’re doing this? I don’t see why iOS would suspend your app if there is still activity occurring (things being saved). There may be some other issue involved.

Thanks,

Brent

P.S. - Please remember to surround your code with “lua” tags for clarity:

[lua] ... [/lua]

Sure! Here’s the simple module I’m using (I wanted to test this separately).

On my iPad 2 with this code it just crashes (Simulator is fine). With 80 it runs and requires 8+ seconds to complete.

[lua]

local M = {}

local cx = display.contentCenterX
local cy = display.contentCenterY
local mRand = math.random

M.init = function()
    
    local numOfMasks = 100
    local maskGroup = display.newGroup( )
    
    local endTime
    local myText

    – Black background
    local black = display.newRect( maskGroup, cx, cy, 768*2, 768*2 )
    black:setFillColor( 0, 0, 0 )

    local loading = display.newRect( cx, cy, 768, 1024 )
    loading:setFillColor( .2, 0, 0 )

    local startTime = system.getTimer( )

    for i=1, numOfMasks do
        local size = mRand( 512 )
        local rr = display.newRoundedRect( maskGroup, cx, cy, size, size, 20 )
        rr:setFillColor( 1, 1, 1 )
        display.save(maskGroup, “mask_” … i … “.jpg”)
        black:toFront()
    end

    endTime = system.getTimer( ) - startTime
    
    myText = display.newText( endTime, cx, cy, native.systemFont, 64 )
    myText:setFillColor( 1, 1, 1 )

end

return M

[/lua]

Hi @gianmichele,

May I ask the reason for saving so many images to local storage? This looks like a fairly intensive process (thus 8 seconds and a potential crash). However, I don’t know what your reasons are for needing so many saved images… these look to be fairly simple display groups consisting of just vector objects and text, correct? Couldn’t these just be generated when needed?

Brent

Hey @Brent, my main reason is to generate different masks based on level and screen resolution. This is an extreme case, as I’m not going to do it this way (I only need about 10-15 max) and I have already found a way to optimize the process.

It would be great to have the ability to use vector display objects directly as a mask (interfaces with rounded rectangles?).

Thanks again.

Hi @gianmichele,

I think somebody came up with a way to generate dynamic masks using vector objects or images. Perhaps this is the link… I haven’t watched the episode, but check it out, or search for similar results in the forum:

https://coronalabs.com/blog/tags/dynamic-masks/

Best regards,

Brent