Two bugs about restore on andorid

display.capture() object cannot be restored on android, I’ve read the document, but I think it should be a bug.

before

post-226893-0-13955000-1416904850.jpg

restore

post-226893-0-86709500-1416904876.jpg

snapshot object cannot be restored on android

before

post-226893-0-60762900-1416904984.jpg

restore

post-226893-0-09100600-1416905027.jpg

We haven’t released any android apps because these two BUGs  :frowning:

What device are you having the problem on?

Can you get it tested on some other devices?

Can you create a sample that shows this issue?

Rob

Google Nexus 7, Android 4.1 Xiaomi 2, Android 4.3

Hi @pickerel,

So, you saved the texture to file using display.save() as the document suggests? Can you post your relevant code here so we can inspect?

Thanks,

Brent

Hi Brent:

About display.capture():

I didn’t call display.save because there are plenty of dynamic capture objects, and they are temporary. It’s not a good idea to save them to document dir.

About snapshot:

test code

https://github.com/CoronaCards/sample-ios-OverlayChildView/tree/447cfc7545631fc2e9689f5c435ed4ecc56332af/Corona

thanks

Hi @pickerel,

It’s not optional in the case of Android. Because of the limitation of that platform and how it discards OpenGL textures on suspend, you must save them somewhere and then reload them on application resume. This is the reason why your textures are showing up corrupted on Android.

Please inspect the “Gotchas” section in the doc:

http://docs.coronalabs.com/api/library/display/capture.html

Take care,

Brent

Hi Brent,

This is the sample code(https://github.com/CoronaCards/sample-ios-OverlayChildView/blob/447cfc7545631fc2e9689f5c435ed4ecc56332af/Corona/main.lua), would you mind give me any suggestion how to solve the snapshot bug?  thanks.

Note: You can’t use the display.save() function in Android applicationSuspend and applicationExit events because there are no OpenGL textures in memory to save. – http://docs.coronalabs.com/api/library/display/newSnapshot.html

Hi @pickerel,

I’m a little confused now… you’re developing a CoronaCards app? If not, what is the reason for using the CoronaCards-based sample code?

Brent

Hi @Brent

I’m developing Corona App, Not CoronaCards. This is the code:

 

-- -- Abstract: SnapshotPaint sample app -- -- Version: 2.0 -- -- Sample code is MIT licensed, see http://www.coronalabs.com/links/code/license -- Copyright (C) 2013 Corona Labs Inc. All Rights Reserved. -- -- Supports Graphics 2.0 ------------------------------------------------------------ local w = display.actualContentWidth local h = display.actualContentHeight display.setDefault( "background", 0, 0, 0, 0 ) local snapshot = display.newSnapshot( w,h ) snapshot:translate( display.contentCenterX, display.contentCenterY ) -- Don't record changes to save memory. -- -- However, saving memory comes at a cost. If the GL context changes, -- the snapshot will \*not\* be able to re-draw the contents. For example, -- on some Android devices, this can occur after a suspend/resume cycle. snapshot.canvasMode = "discard" local previousX, previousY local threshold = 0 local thresholdSq = threshold\*threshold local function draw( x, y ) local o = display.newImage( "brush.png", x, y ) o:setFillColor( 1, 0, 1 ) -- magenta paint snapshot.canvas:insert( o ) snapshot:invalidate( "canvas" ) -- accumulate changes w/o clearing end local function listener( event ) local x,y = event.x - snapshot.x, event.y - snapshot.y if ( event.phase == "began" ) then previousX,previousY = x,y draw( x, y ) elseif ( event.phase == "moved" ) then local dx = x - previousX local dy = y - previousY local deltaSq = dx\*dx + dy\*dy if ( deltaSq \> thresholdSq ) then draw( x, y ) previousX,previousY = x,y end end end Runtime:addEventListener( "touch", listener ) local instruction = display.newText{ text="Touch screen to start painting", x = display.contentCenterX, y = 30, fontSize=12, } instruction:setFillColor( 0 ) Runtime:addEventListener( "bar", function(event) print( event.name, event.key, type( event.key) ) end )

Hi @pickerel,

Where are you saving the snapshot, as I mentioned before? When you want to create a snapshot or capture of something that needs to persist on Android, you should do so, then immediately “display.save()” it, then remove the original object, and finally re-load it via “display.newImage()” or “newImageRect()”. By doing that, Corona will be able to restore the image when the app resumes. The key thing being is you have to “display.save()” it immediately… don’t wait to do it later, like during suspend, because then it is too late, and there won’t be any textures in OpenGL to save. In other words, do a “display.save()” in the same code block that is doing the snapshot/capture.

Best regards,

Brent

Hi @Brent,

I understand what’s you mean, but you’d better take a look at the code. It implements a finger drawing function, and the snapshot will be updated continuously within a touch event. If I do as your suggestion, I must saving the snapshot in touch event, It’s very inefficiency. Maybe I can do a delay with a timer,  save the snapshot every 1 or 2 seconds, but it’s still inefficiency, and some data may be lost.

Thanks

Pickerel 

Hi @pickerel,

Hmm, I see your point now. Saving the snapshot on every “moved” touch phase is unrealistic, but in practice, it seems like the only time the user would “suspend” the app would be between drawing motions (meaning, who would be in the middle of drawing something and click the power button off or close the app?). So, you could save the snapshot each time the draw motion ended, or even every 2nd or 3rd time, and realistically I think the user would not see any major issues in that.

This is, by the way, a fairly annoying aspect of Android that we can’t control, and iOS handles it more gracefully.

Brent

What device are you having the problem on?

Can you get it tested on some other devices?

Can you create a sample that shows this issue?

Rob

Google Nexus 7, Android 4.1 Xiaomi 2, Android 4.3

Hi @pickerel,

So, you saved the texture to file using display.save() as the document suggests? Can you post your relevant code here so we can inspect?

Thanks,

Brent

Hi Brent:

About display.capture():

I didn’t call display.save because there are plenty of dynamic capture objects, and they are temporary. It’s not a good idea to save them to document dir.

About snapshot:

test code

https://github.com/CoronaCards/sample-ios-OverlayChildView/tree/447cfc7545631fc2e9689f5c435ed4ecc56332af/Corona

thanks

Hi @pickerel,

It’s not optional in the case of Android. Because of the limitation of that platform and how it discards OpenGL textures on suspend, you must save them somewhere and then reload them on application resume. This is the reason why your textures are showing up corrupted on Android.

Please inspect the “Gotchas” section in the doc:

http://docs.coronalabs.com/api/library/display/capture.html

Take care,

Brent

Hi Brent,

This is the sample code(https://github.com/CoronaCards/sample-ios-OverlayChildView/blob/447cfc7545631fc2e9689f5c435ed4ecc56332af/Corona/main.lua), would you mind give me any suggestion how to solve the snapshot bug?  thanks.

Note: You can’t use the display.save() function in Android applicationSuspend and applicationExit events because there are no OpenGL textures in memory to save. – http://docs.coronalabs.com/api/library/display/newSnapshot.html

Hi @pickerel,

I’m a little confused now… you’re developing a CoronaCards app? If not, what is the reason for using the CoronaCards-based sample code?

Brent

Hi @Brent

I’m developing Corona App, Not CoronaCards. This is the code:

 

-- -- Abstract: SnapshotPaint sample app -- -- Version: 2.0 -- -- Sample code is MIT licensed, see http://www.coronalabs.com/links/code/license -- Copyright (C) 2013 Corona Labs Inc. All Rights Reserved. -- -- Supports Graphics 2.0 ------------------------------------------------------------ local w = display.actualContentWidth local h = display.actualContentHeight display.setDefault( "background", 0, 0, 0, 0 ) local snapshot = display.newSnapshot( w,h ) snapshot:translate( display.contentCenterX, display.contentCenterY ) -- Don't record changes to save memory. -- -- However, saving memory comes at a cost. If the GL context changes, -- the snapshot will \*not\* be able to re-draw the contents. For example, -- on some Android devices, this can occur after a suspend/resume cycle. snapshot.canvasMode = "discard" local previousX, previousY local threshold = 0 local thresholdSq = threshold\*threshold local function draw( x, y ) local o = display.newImage( "brush.png", x, y ) o:setFillColor( 1, 0, 1 ) -- magenta paint snapshot.canvas:insert( o ) snapshot:invalidate( "canvas" ) -- accumulate changes w/o clearing end local function listener( event ) local x,y = event.x - snapshot.x, event.y - snapshot.y if ( event.phase == "began" ) then previousX,previousY = x,y draw( x, y ) elseif ( event.phase == "moved" ) then local dx = x - previousX local dy = y - previousY local deltaSq = dx\*dx + dy\*dy if ( deltaSq \> thresholdSq ) then draw( x, y ) previousX,previousY = x,y end end end Runtime:addEventListener( "touch", listener ) local instruction = display.newText{ text="Touch screen to start painting", x = display.contentCenterX, y = 30, fontSize=12, } instruction:setFillColor( 0 ) Runtime:addEventListener( "bar", function(event) print( event.name, event.key, type( event.key) ) end )