andrewz
andrewz

Reputation: 5220

Loading PNG image on iPhone fails, works in simulator

I just started testing my project on an iPhone and I ran into a problem while loading a png image near the beginning of launch. Basically the image is not read - it exists, and it is found, but fails to process, and consequently a NULL texture is returned. I am using Cocos2DX v3.4

I traced it down to CCImage.cpp:

png_read_info(png_ptr,info_ptr); // line 956 -- I can't get past this point in debug mode, execution immediately transfers out -- I suspect an exception is thrown from inside this function

This is inside this method: bool Image::initWithPngData(const unsigned char * data, ssize_t dataLen) // line 916

Searching on the web this may be caused by some inconsistency in the libpng library perhaps due to 64-bit architecture, although I doubt it - otherwise linker would complain. I compile with arm64.

This is not an issue with the image I believe, because everything works in simulator, and when I use other images on the device I get same problem.

Any idea?

[EDIT]

Here is additional info I found out:

1 Substituting a jpg file and loading it in works

2 There is a cc_fps_images_png file loaded correctly, but its data is contained within the executable (ie a static array of bytes), not read in from disk

3 I am running this on iPhone 6 iOS 8.1. Here are the stats displayed in the console when the app launches:

{
gl.supports_vertex_array_object: true
cocos2d.x.version: cocos2d-x 3.4
gl.vendor: Apple Inc.
gl.supports_PVRTC: true
gl.renderer: Apple A8 GPU
cocos2d.x.compiled_with_profiler: false
gl.max_texture_size: 4096
gl.supports_ETC1: false
gl.supports_BGRA8888: false
cocos2d.x.build_type: DEBUG
gl.supports_discard_framebuffer: true
gl.supports_NPOT: true
gl.supports_ATITC: false
gl.max_samples_allowed: 4
gl.max_texture_units: 8
cocos2d.x.compiled_with_gl_state_cache: true
gl.supports_S3TC: false
gl.version: OpenGL ES 2.0 Apple A8 GPU - 50.6.10
}

[EDIT]

More info:

1 I didn't notice this earlier but in the output I get this error message: libpng error: CgBI: unhandled critical chunk

Upvotes: 4

Views: 1151

Answers (3)

Laine Mikael
Laine Mikael

Reputation: 183

I was getting this whether compression was turned on or off. Also, 'Remove Text Metadata From PNG files' option doesn't seem to be available in XCode 8.0.

Instead, I have to change the 'Type' of the png image to 'Data' under right-click->Show File Inspector.

Upvotes: 0

fnc12
fnc12

Reputation: 2237

In XCode project open 'Build settings' and set

Compress PNG Files to NO and

Remove Text Metadata From PNG files to NO.

enter image description here

Upvotes: 4

andrewz
andrewz

Reputation: 5220

In XCode go to build settings and set the setting 'Compress PNG Files' to NO.

Upvotes: 0

Related Questions