Snapshot canvas issue on ios8?

Hi @jacques1,

Can you pinpoint the exact size of the snapshot on a device which is specifically failing? Is it a fractional value in either direction?

@brent, the snapshot size is 2000x1200px.

Below is the config.lua (the one that i get the black texture on (iPad Air and Nexus tablet) and a simple test main.lua i used which causes the issue. city1.jpg can be set to any jpg 2000x1200px in size for testing. The main.lua constructs a simple jpg image in one group with 2 angled semi-transparent black squares in another group on top of it. They are then all put into another mainArea group, reason being, a user needs to later on be able to pinch and zoom (but this is not immediately relevant to the snapshot issue).

 local aspectRatio = display.pixelHeight / display.pixelWidth application = { content = { width = aspectRatio \> 1.5 and 640 or math.ceil( 960 / aspectRatio ), height = aspectRatio \< 1.5 and 960 or math.ceil( 640 \* aspectRatio ), scale = "letterBox", fps = 30, }, }

local halfW = display.viewableContentWidth / 2 local halfH = display.viewableContentHeight / 2 initmap=display.newImage("city\_1.jpg", true);initmap.x=0;initmap.y=0 bgArea = display.newSnapshot( 2000, 1200);bgArea.canvasMode="discard";bgArea.canvas:insert(initmap);bgArea:invalidate( "canvas" );bgArea.xScale=0.5;bgArea.yScale=0.5 mainArea=display.newGroup();mainArea:translate( halfW, halfH) mainArea:insert( bgArea ) shadowLayer=display.newSnapshot(2000, 1200);shadowLayer.alpha=0.6;mainArea:insert(shadowLayer);shadowLayer.x=0;shadowLayer.y=0 shadowLayer.fill.effect = "filter.blur" shadow=display.newRect(0,0,200,200);shadow:setFillColor(0,0,0,1);shadow.anchorX=0;shadow.anchorY=0 shadow2=display.newRect(0,0,200,200);shadow2:setFillColor(0,0,0,1);shadow2.anchorX=0;shadow2.anchorY=0;shadow2.rotation=45;shadow2.x=50 shadowLayer.group:insert(shadow ) shadowLayer.group:insert(shadow2) shadowLayer:invalidate() 

So as mentioned, if i use the above config.lua formula code both the bgArea snapshot shows black as well as the shadowlayer snapshot. If i use the bgArea to just hold city1.jpg image without using snapshot then you can see the city1.jpg image underneath the shadowlayer snapshot (but the shadow layer snapshot is still a solid black texture - although semi transparent due to alpha set to 0.6.

If i set width=768,height=1024 (without the formula code) in the config file then both snapshots work fine (i don’t make any changes to the build.settings file so assuming it has nothing to do with the build.settings file.)

You mentioned fractional values, i’m not sure what you meant by that but I do believe the snapshot failing depends on a device’s screen size and the width/height formula results - how these final values relate in the end could be the cause why it only fails sometimes on particular device screen sizes. Still doesn’t explain why it works fine if i put specific width/height values.

Currently I have had feedback on the snapshot not working from android users below. There are a few others but they did not indicate their devices and simply refunded:

ASUS FONEPAD(ME371MG) (800x1200) -  Intel Atom z2420/Z2460,  CPU 1.2/1.6GHz, GPU PowerVR SGX540 

NEXUS 7 ASUS-1A007A (1200x1920) - Qualcomm Snapdragon S4Pro, CPU  Quad-core 1.5 GHz Krait, GPU  Adreno 320

NEXUS 7  (grouper) (800x1200) - NVvidia Tegra 3, CPU 1.3GHz Quad-core Cortex A9, GPU NVIDIA GeForce ULP

So far, there appears to be no issues on the following android devices:

Galaxy S5 (kltevzw) , Nexus 7 (flo) , Xperia Z Ultra (C6833) , Galaxy S3 Mini (goldenltevzw) , Galaxy Tab3 7.0 (lt02ltespr) , Galaxy S3 (m0) , Galaxy Note3 (hltevzw) , Galaxy Note II (t03g) , Moto X (ghost) , Galaxy Note3 (hlte) , Galaxy Tab2 7.0 (espressowifi) , Galaxy Mega 6.3 (meliuslteatt) , TegraNote (tegranote) , Samsung Tab S 8.4

Okay I believe I have been able to narrow down how and when the snapshot fails.

If the snapshot size specified is more then twice the size of either the width or height value set by the following config.lua code, then the snapshot will fail and show black.

         width = aspectRatio > 1.5 and 640 or math.ceil( 960 / aspectRatio ),

         height = aspectRatio < 1.5 and 960 or math.ceil( 640 * aspectRatio ),

Testing on an iPad Air (1536x2048) the above code gives values for game size of width/height = w720xh960. If this value is doubled w1440xh1920, the snapshot w1200xh2000  height is more then double the 1920height set for game width/height and snapshot fails.

I tested changing the 960 in my config to 1000. The above formula then gives values for game size of width/height = w750xh1000.

Double this height would be 2000 which does not exceed the 1200x2000 snapshot size i need and… the snapshot works!

So to summarize, it looks like whatever size you set for your game in the config.lua, you can’t use a snapshot more then double either the width or height. I might be wrong as have not tested more values.

However, this of course doesn’t really help me as if my game is set to w750xh1000 then it doesn’t nicely fill the device screen anymore.

 I believe the reason for the double size issue has something to do with retina devices being at least double resolution, etc? (note, i never had back texture issues with iPhone4 or iPad2).

Last to remind, if i set config.lua values of 768x1024 or 640x1136, or 640x960 snapshot does not fail (i a now assuming because doubling the value of any of these numbers is still greater then the size of the w1200xh2000 snapshot i need to use.)

So… hopefully with this new info Corona can help find a solution to this? I have no idea why other developers have not come across this issue as yet.

Apologies for the numerous posting but I’m hoping someone or Corona will read this and help to solve my dilemma.

So on further testing (with iPad Air 1536x2048px screen), that’s the only device I have that has this issue:

(Note, the game screen is of course not nicely filled with the below game screen values - just testing if snapshot works or fails)

snapshot WORKS with config code below:

application = {

  content = {

 width=640,

 height=1136,

 scale = “letterBox”,

 xAlign = “center”,

     yAlign = “center”,

 fps = 30

  },

}

snapshot FAILS with any config code variation below:

application = {

  content = {

 width=640,

 height=1136,

 scale = “zoomEven”,

 xAlign = “center”,

     yAlign = “center”,

 fps = 30

  },

}

application = {

  content = {

 width=640,

 height=960,

 scale = “letterBox”,

 xAlign = “center”,

     yAlign = “center”,

 fps = 30

  },

}

application = {

  content = {

 width=640,

 height=960,

 scale = “zoomEven”,

 xAlign = “center”,

     yAlign = “center”,

 fps = 30

  },

}

So it appears that my previous post about game screen values set to at least half the width/height of snapshot is not accurate, since iPad Air snapshot also fails on w640xh1136 (1136 being more then half of the h2000 size of snapshot).

Strange though that the snapshot does work if set to letterBox but not if set to zoomEven. Does any of this have to do with how corona calculates the letterBox and zoomEven? If so, then why does the 640x960 letterBox snapshot also fail?

Very confusing, and no closer to finding a solution for android devices.

Hi @jacques1,

This is so random, we may need to step back to something more basic. Can you test one of the Corona sample projects involving snapshots and see if you get the same crash, after modifying their config with the values that are known to either work or crash?

There are two snapshot-based projects in the Graphics-Premium folder of the sample code bundled with the application.

Thanks,

Brent

I pretty much gave up trying to solve the snapshot issue.

What I ended up doing was not using the snapshot any more for my background image and only using it for my shadow layer.

So, I now use a snapshot half the size w600xh1000 for my shadow layer, and again another snapshot the same size for the blood splats I plan to render to that snapshot (which were supposed to render to the background snapshot).

So, instead of reducing the actual snapshot scale to 0.5 which i originally did, i now scale the graphics that goes into the snapshot to 0.5. This of course makes the image inside the snapshot twice (or 4 times?)  as blurry when zooming into the snapshot but no choice as at least the snapshot no longer shows black on devices using the formula code we have been discussing.

So perhaps it is an issue with the size of the snapshot i originally want to make w1200xh2000 (its actually 2000px in width and 1200px in height since my game is landscape but I mention w1200xh2000 in case you assumed its portrait. Although the black texture can’t be due to just texture memory issues since the original way i did it even worked on my old iPhone 4.

When I have time i’ll try what you suggested with one of the bundled projects. Thanks for the time anyways.