Search code examples
iphoneiosxcodelibpngpngcrush

pngcrush caught libping error, but only when building for device


I have some png files in my iPhone app project. They work fine when I build for the simulator. But when I build for the device, suddenly every single png file generates the dreaded "while reading such-and-such.png pngcrush caught libpng error: ... Could not find file: ..."

As I say, everything builds and runs great with the simulator. It's only when I change the scheme to build for the device that I get the errors.

I tried cleaning and rebuilding.

I tried manually deleting the Products directory.

I tried restarting my system.

I tried using the files in a different project (same results there).

The only thing I have found that works is to open the files and resave them. However, this is a less than optimal solution because I have hundreds of PNG files all suffering from this issue. I would rather understand what the issue is so that I can fix it directly.

Any ideas?


Solution

  • It sounds as though you've got PNG files that were recompressed with Apple's rogue "pngcrush" Xcode program, which writes files that are not valid PNGs. Look for the string "CgBI" near the beginning of the file (starting at the 12th byte) where "IHDR" should be. There are applications (including the Apple version of "pngcrush") that can undo the problem.