Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Snapshot canvas issue on ios8?
Started by jacques1 Oct 21 2014 07:39 PM

13 replies to this topic
[TOPIC CONTROLS]
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

jacques1

[GLOBAL: userInfoPane.html]
jacques1
  • Contributor

  • 318 posts
  • Corona SDK

I use display.snapshot's canvas feature for a background image which has other images added to it during a game. The canvas is set to discard new images added (which saves memory). However I am getting feedback that the background snapshot is no longer displaying for users of iOS 8 while users of iOS 6 and 7 can see the background and added images no problem. Is anyone aware of issues with snapshot and canvas with iOS 8?

[TOPIC: post.html]
#2

jacques1

[GLOBAL: userInfoPane.html]
jacques1
  • Contributor

  • 318 posts
  • Corona SDK

I can now confirm this is only happening to users using ios8, so anyone else having issues with their display.newSnapshot canvas not displaying correctly? (note, canvas is set to discard). Is it possible snapshot is rendering a texture too slow on ios8 hence the image is discarded before it gets properly put into the snapshot canvas compared to ios6/7?



[TOPIC: post.html]
#3

bjsorrentino

[GLOBAL: userInfoPane.html]
bjsorrentino
  • Veteran

  • 8,506 posts
  • Corona SDK

Hi @jacques1,

Is it possible for you to file a bug report and a simple test case which exhibits this? Potential bug reports are easily lost in the forums, so we need an official report for tracking this.

 

Thanks,

Brent



[TOPIC: post.html]
#4

jacques1

[GLOBAL: userInfoPane.html]
jacques1
  • Contributor

  • 318 posts
  • Corona SDK

Hi Brent, the problem is that I can't replicate the issue on my iPhone 4 or iPad2 using any of the ios6/7/8 versions, it works fine for me on all those iOS versions and devices. So it's hard to figure out exactly what is causing the canvas snapshot image not to show up. Hence i'm wondering if it has to do specifically with retina display devices having new graphic features activated by ios8 ( only players with iPad 3, iPad Air and newest iPhone 5 are the ones giving feedback about this problem, which they didn't have before updating to ios8). I will be buying an iPad Air to test it out and see if i can relocate the issue and then reply here. note: i mentioned this issue in this post http://forums.coronalabs.com/topic/41552-xcode-simulator-64-bit-devices/?view=getnewpost (rob replied), so not sure if you need to consolidate the thread one way or another.

 

Just to confirm there is no apparent crash/hang as players say the game still runs/plays fine and all other non-snapshot graphics display properly.

Hi @jacques1,

Is it possible for you to file a bug report and a simple test case which exhibits this? Potential bug reports are easily lost in the forums, so we need an official report for tracking this.

 

Thanks,

Brent



[TOPIC: post.html]
#5

jacques1

[GLOBAL: userInfoPane.html]
jacques1
  • Contributor

  • 318 posts
  • Corona SDK

After further testing and feedback from users, I believe the failure of snapshot api comes from the config.lua code below (it's not the full config just the key area in discussion). the snapshot only fails to work (i.e.; it just appears black) on certain device screen resolutions (both android and IOS suffer from it). I resolved the issue on IOS but not using the code below and manually checking the device type and assigning width and height. For example when using the code below, iPad Air and some other retina devices showed black screen while iPad2, iPhone4 etc didn't. I still have some android users with the problem (lots of android devices work fine and don't show a black texture), namely nexus tablet (1200x1920 resolution) has this issue (whether i set to letterBox or zoomEven). Based on the code below the width and height becomes 640x1024 and for some reason that will cause the back texture. So again, I really don't know if it is specific width/height outcomes of the code below or something else (As mentioned not every device size has this issue).

My safe area is always 640x960 (landscape), but i use background screens of 768x1136 (to prevent black bars).

However users have no problems with any graphics in the game until the game tries to use a snapshot. The snapshot size I make is 2000x1000px (if that helps) and that's what shows as black on certain devices with certain resolutions.

content =
 {
    width = (display.pixelHeight / display.pixelWidth) > 1.5 and 640 or math.ceil(960 / (display.pixelHeight / display.pixelWidth)),
    height = (display.pixelHeight / display.pixelWidth) < 1.5 and 960 or math.ceil(640 * (display.pixelHeight / display.pixelWidth)),

    scale = "zoomEven",
    xAlign = "center",
    yAlign = "center",
    fps = 30
 },


[TOPIC: post.html]
#6

bjsorrentino

[GLOBAL: userInfoPane.html]
bjsorrentino
  • Veteran

  • 8,506 posts
  • Corona SDK

Hi @jacques1,

I think we'll need to (attempt) to narrow this down to some common factor on devices. Are all those which are "failing" using iOS 8? Are they all "Retina" but running different versions of iOS 8?

 

Basically, can you get a list of which combinations of screens and iOS versions are working, and which aren't?

 

Also, what happens if you take out that calculation of width and height, and just use something like 640 x 960?

 

Thanks,

Brent



[TOPIC: post.html]
#7

jacques1

[GLOBAL: userInfoPane.html]
jacques1
  • Contributor

  • 318 posts
  • Corona SDK

@Brent, sorry it's my mistake initially, I believe it is not actually an IOS8, as some android users also experience it.

It definitely has to do with screen resolution and the width/height the above formula sets.

It also has no difference whether using letterBox or zoomEven.

 

If i use 640x960 or 640x1136 or 768x1024 then it works fine on any IOS device even iPhone 6/6+.

(note: i only managed to replicate this problem myself on my iPad Air. My iPhone 4 and iPad 2 had no black texture problems when using either the code formula or set values), only iPad Mini, iPad3, iPad Air, iPhone 6 /6+ users experienced the issue (other newer devices I didn't get feedback from). 

 

For android I have so far only heard from a nexus tablet user (1200x1920px scree size), but there might be other android users with the same black screen problem as I have only preset width/height for IOS devices and still use the code formula for android devices.

 

I don't know if it has anything to do with the snapshot size I'm creating, its a 2000x1200px snapshot (previous post was wrong when i said 2000x1000px).

 

So, since on my iPhone 4, and iPad2, (nor my samsung tab s 8.4)  i never had any problems, i tested on the iPad Air.

 

When using:

width = (display.pixelHeight / display.pixelWidth) > 1.5 and 640 or math.ceil(960 / (display.pixelHeight / display.pixelWidth))

height = (display.pixelHeight / display.pixelWidth) < 1.5 and 960 or math.ceil(640 * (display.pixelHeight / display.pixelWidth))

 

iPad Air always display a black texture, but when using width=768,height=1024 the iPad Air snapshot texture works fine.

Using the above formula, if i'm not wrong would return something like width=722 x height=960 and then I get the black snapshot texture issue.

 

So, kind of stuck solving this issue only for android, since now using set values for all IOS devices I don't come across the problem, however you know that it's almost impossible to set values for every kind of screen ration android devices have.

 

Sorry I haven't tried with a smaller snapshot size so not sure if the snapshot does not work because of the 2000x1200px size when game screen is set by the code formula or what.

 

Any further ideas or help would be greatly appreciated.



[TOPIC: post.html]
#8

bjsorrentino

[GLOBAL: userInfoPane.html]
bjsorrentino
  • Veteran

  • 8,506 posts
  • Corona SDK

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?



[TOPIC: post.html]
#9

jacques1

[GLOBAL: userInfoPane.html]
jacques1
  • Contributor

  • 318 posts
  • Corona SDK

@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.



[TOPIC: post.html]
#10

jacques1

[GLOBAL: userInfoPane.html]
jacques1
  • Contributor

  • 318 posts
  • Corona SDK

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/Z2460CPU 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



[TOPIC: post.html]
#11

jacques1

[GLOBAL: userInfoPane.html]
jacques1
  • Contributor

  • 318 posts
  • Corona SDK

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.



[TOPIC: post.html]
#12

jacques1

[GLOBAL: userInfoPane.html]
jacques1
  • Contributor

  • 318 posts
  • Corona SDK

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.


[TOPIC: post.html]
#13

bjsorrentino

[GLOBAL: userInfoPane.html]
bjsorrentino
  • Veteran

  • 8,506 posts
  • Corona SDK

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



[TOPIC: post.html]
#14

jacques1

[GLOBAL: userInfoPane.html]
jacques1
  • Contributor

  • 318 posts
  • Corona SDK

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.




[topic_controls]
[/topic_controls]