Some images in my iOS builds have started appearing as black squares

In the simulator and on Android it works fine, but on iOS some but not all of my images are just rendered as black rects.

There is no error message in the console output, and the project worked previously so I’m not sure what could be causing the problem.  

Has anyone else seen this happen before, or does anyone have any ideas?

Edit: Also, when building the app, I can see in the terminal that all of the images are being copied across during the build process.

The images are varying sizes: 320*480, 584*180, 2048*2048 and 2048*1280

It turns it the problem was caused by my use of:

display.setDefault( "textureWrapX", "repeat" ) display.setDefault( "textureWrapY", "mirroredRepeat" )

at the top of main.lua

I thought this function only applied to objects that have an image fill applied to them like so:

myObj.fill = { type=“image”, filename=“myImage.png” }

and not all objects from then on.

Putting this:

display.setDefault( "textureWrapX", "repeat" ) display.setDefault( "textureWrapY", "mirroredRepeat" ) 

before I create my tiled object and then:

display.setDefault( "textureWrapX", "clampToEdge" ) display.setDefault( "textureWrapY", "clampToEdge" ) 

after it fixed the problem.

Does anyone know why this only affected iOS though?

Hi @AlanPlantPot,

I’m a bit unsure why this would only be happening in iOS. But, I know that you must use Power-of-2 size fill textures for anything except the default “clampToEdge” repeating modes (so, for “repeat” or “mirroredRepeat”). If you don’t, those objects will not be filled/rendered properly on devices.

Hope this helps somewhat,

Brent

It turns it the problem was caused by my use of:

display.setDefault( "textureWrapX", "repeat" ) display.setDefault( "textureWrapY", "mirroredRepeat" )

at the top of main.lua

I thought this function only applied to objects that have an image fill applied to them like so:

myObj.fill = { type=“image”, filename=“myImage.png” }

and not all objects from then on.

Putting this:

display.setDefault( "textureWrapX", "repeat" ) display.setDefault( "textureWrapY", "mirroredRepeat" ) 

before I create my tiled object and then:

display.setDefault( "textureWrapX", "clampToEdge" ) display.setDefault( "textureWrapY", "clampToEdge" ) 

after it fixed the problem.

Does anyone know why this only affected iOS though?

Hi @AlanPlantPot,

I’m a bit unsure why this would only be happening in iOS. But, I know that you must use Power-of-2 size fill textures for anything except the default “clampToEdge” repeating modes (so, for “repeat” or “mirroredRepeat”). If you don’t, those objects will not be filled/rendered properly on devices.

Hope this helps somewhat,

Brent

Thanks AlanPlantPot!  This should be put in BOLD in the documentation of https://docs.coronalabs.com/api/library/display/setDefault.html#texturewrapx I have wasted couple of hours trying to debug my code and filling unnecessary bug report.

Woop! I had a real moment of panic there when images on my device started to go black. It’d be great if there was a warning about this. 

I noticed that the device console didn’t print any errors, which makes it quite confusing!

Thanks AlanPlantPot!  This should be put in BOLD in the documentation of https://docs.coronalabs.com/api/library/display/setDefault.html#texturewrapx I have wasted couple of hours trying to debug my code and filling unnecessary bug report.

Woop! I had a real moment of panic there when images on my device started to go black. It’d be great if there was a warning about this. 

I noticed that the device console didn’t print any errors, which makes it quite confusing!