display.save on android

I’m having some issues using display.save on a android device. What I’m trying to do is load something and as soon as it’s load save it. Here is some example code here:-

testGroup = display.newGroup()  
rect = display.newRect(0,0,100,100)  
testGroup:insert(rect)  
display.save(testGroup, "test.jpg", system.DocumentsDirectory)  
  
image = display.newImage("test.jpg", system.DocumentsDirectory)  
image.x = 200  
image.y = 200  

When I use this in the simulator, it works and displays the two white rects. When I put it on the android device the first one shows, but the second one doesn’t appear at all. I tried a test where I put the image display on a delay like this:-

testGroup = display.newGroup()  
rect = display.newRect(0,0,100,100)  
testGroup:insert(rect)  
  
function doSave()  
 display.save(testGroup, "test.jpg", system.DocumentsDirectory)  
 image = display.newImage("test.jpg", system.DocumentsDirectory)  
 image.x = 200  
 image.y = 200  
end  
  
timer.performWithDelay(300, doSave)  

Which does work, but obviously isn’t idea as it’s going to be much slower and will be wasting a fair bit of time. Can anyone suggest away around this without having to use a delay? Or am I possibly doing something wrong that I have missed?

Considering I get the same results using the result example I’m not 100% sure though

local myObject1 = display.newRect( 50, 50, 100, 150 ) -- Create a rectangle object  
local myObject2 = display.newCircle( 100, 300, 50 ) -- Create a circle object  
   
local g = display.newGroup()  
   
g:insert(myObject1)  
g:insert(myObject2)  
   
local baseDir = system.DocumentsDirectory  
display.save( g, "entireGroup.jpg", baseDir )  
  
image = display.newImage("entireGroup.jpg", baseDir)  
image.x = 0  
image.y = 0  

[import]uid: 133056 topic_id: 31240 reply_id: 331240[/import]

I had a look into this a bit more and I think it’s possibly a bug… unfortunately a possible game breaking bug for an idea I want to use. I’m not 100% sure if this is something which is just android related as I’m unable to test on ios unfortunately (going to have to invest in a test phone I think!)

I’ll add I was using Ice Cream Sandwich, I am just doing an update now to see if there that helps. [import]uid: 133056 topic_id: 31240 reply_id: 125000[/import]

I had a look and if I do a timer.performWithDelay at 1 millisecond it seems to fix it, so I have to make a closure to pass the details to the function which then works… Not ideal and still possibly a bug, but a work around at the very least.

I did submit a bug report for this so hopefully it’ll be fixed up eventually!

[code]
function saveRow(saveGroup, file)
display.save(saveGroup, file, system.DocumentsDirectory )
end

saveClosure = function() saveRow(showGroup, maskGroup, row) end
timer.performWithDelay(1, saveClosure)
[/code] [import]uid: 133056 topic_id: 31240 reply_id: 125256[/import]

Hey there, sorry, don’t normally deal with Android sub forum - thanks for filing and for posting your workaround here, really good of you to follow up as it helps other users when they encounter these issues. (Though hopefully it will be fixed promptly :-)) [import]uid: 52491 topic_id: 31240 reply_id: 125355[/import]

I had a look into this a bit more and I think it’s possibly a bug… unfortunately a possible game breaking bug for an idea I want to use. I’m not 100% sure if this is something which is just android related as I’m unable to test on ios unfortunately (going to have to invest in a test phone I think!)

I’ll add I was using Ice Cream Sandwich, I am just doing an update now to see if there that helps. [import]uid: 133056 topic_id: 31240 reply_id: 125000[/import]

No worries at all, I still need to test on older android devices and what kind of effect this has on ios as well so can’t say for sure it’s 100% resolved, but at least it’s a step in the right direction. If I find anything else out I’ll be sure to post it.

I am slightly surprised something like this hasn’t been mentioned before to be honest. I would have thought it’s something pretty common people would use to generate images when an app is first loaded to keep file size down on the app store or generate custom graphics and cache them for later use.

Steve [import]uid: 133056 topic_id: 31240 reply_id: 125363[/import]

Thanks stevil for posting your work here!

It helped me a lot. [import]uid: 175437 topic_id: 31240 reply_id: 125557[/import]

No worries. I just got an email from corona addressing this and they have updated the documentation to mention this. You can read it here docs.coronalabs.com/api/library/display/save.html

they mention to use a 100ms gap but in my tests i get away with only 1ms. If anyone else can test this i would be interested in hearing what times other people get to work. [import]uid: 133056 topic_id: 31240 reply_id: 125564[/import]

I had a look and if I do a timer.performWithDelay at 1 millisecond it seems to fix it, so I have to make a closure to pass the details to the function which then works… Not ideal and still possibly a bug, but a work around at the very least.

I did submit a bug report for this so hopefully it’ll be fixed up eventually!

[code]
function saveRow(saveGroup, file)
display.save(saveGroup, file, system.DocumentsDirectory )
end

saveClosure = function() saveRow(showGroup, maskGroup, row) end
timer.performWithDelay(1, saveClosure)
[/code] [import]uid: 133056 topic_id: 31240 reply_id: 125256[/import]

Hey there, sorry, don’t normally deal with Android sub forum - thanks for filing and for posting your workaround here, really good of you to follow up as it helps other users when they encounter these issues. (Though hopefully it will be fixed promptly :-)) [import]uid: 52491 topic_id: 31240 reply_id: 125355[/import]

No worries at all, I still need to test on older android devices and what kind of effect this has on ios as well so can’t say for sure it’s 100% resolved, but at least it’s a step in the right direction. If I find anything else out I’ll be sure to post it.

I am slightly surprised something like this hasn’t been mentioned before to be honest. I would have thought it’s something pretty common people would use to generate images when an app is first loaded to keep file size down on the app store or generate custom graphics and cache them for later use.

Steve [import]uid: 133056 topic_id: 31240 reply_id: 125363[/import]

Thanks stevil for posting your work here!

It helped me a lot. [import]uid: 175437 topic_id: 31240 reply_id: 125557[/import]

No worries. I just got an email from corona addressing this and they have updated the documentation to mention this. You can read it here docs.coronalabs.com/api/library/display/save.html

they mention to use a 100ms gap but in my tests i get away with only 1ms. If anyone else can test this i would be interested in hearing what times other people get to work. [import]uid: 133056 topic_id: 31240 reply_id: 125564[/import]