PNG FATAL ERROR: Invalid image width

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
kkrizka
Posts: 70
Joined: Sun Sep 30, 2007 3:10 am

PNG FATAL ERROR: Invalid image width

Post by kkrizka »

Hi there,

I'm trying to get Irrlicht working with loading images, because a project I started hacking on a project that uses Irrlicht for graphics. The problem I run into is that everytime I try to load a PNG image as a texture, I get the following error:
PNG FATAL ERROR: Invalid image width
PNG FATAL ERROR: Invalid image width
Could not load texture: back-next.png
In order to fix this, I decided to isolate the texture loading code in order to see what's wrong. I used a jpeg file, and converted it into a png file, and tried to load both. The jpeg file loaded perfectly, but the png file failed with the same error. I used the code attached at the end of the post.

Does anyone know what the problem could be? I'm using irrlicht 1.3.1 on 64bit Gentoo Linux.
#include <irrlicht.h>

using namespace irr;

using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;

int main()
{
IrrlichtDevice *device =
createDevice(EDT_SOFTWARE, dimension2d<s32>(512, 384), 16,
false, false, false, 0);
device->setWindowCaption(L"Hello World! - Irrlicht Engine Demo");
IVideoDriver* driver = device->getVideoDriver();
ISceneManager* smgr = device->getSceneManager();
IGUIEnvironment* guienv = device->getGUIEnvironment();

guienv->addStaticText(L"Hello World! This is the Irrlicht Software engine!",
rect<int>(10,10,200,22), true);


ITexture* ATB_Sel=driver->getTexture("back-next.jpg");
ITexture* ATB_Sel2=driver->getTexture("back-next.png");

while(device->run())
{

driver->beginScene(true, true, SColor(255,100,101,140));

driver->draw2DImage(ATB_Sel, core::position2d<s32>(100,100), core::rect<s32>(0,0,128,64), 0, video::SColor(255, 255, 255, 255),true);
driver->draw2DImage(ATB_Sel2, core::position2d<s32>(300,100), core::rect<s32>(0,0,128,64), 0, video::SColor(255, 255, 255, 255),true);


smgr->drawAll();

guienv->drawAll();
driver->endScene();

}

device->drop();
return 0;

}
Cheers,
Karol Krizka

http://www.krizka.net
Perceval
Posts: 158
Joined: Tue May 30, 2006 2:42 pm

Post by Perceval »

May be your texture width is not a power of 2 (i know some people got problems with that, don't know if it's corrected now).
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

No, that was a 64bit problem with libpng. It'll be fixed in the next release.
kkrizka
Posts: 70
Joined: Sun Sep 30, 2007 3:10 am

Post by kkrizka »

hybrid wrote:No, that was a 64bit problem with libpng. It'll be fixed in the next release.
That's most likely it, thank you. I just noticed that the 1.4 has been released in beta, so I will give it a run when I get home. Thank you! :)
Cheers,
Karol Krizka

http://www.krizka.net
AzP
Posts: 16
Joined: Fri Jun 09, 2006 8:47 pm
Location: Stockholm, Sweden

Post by AzP »

This still hasn't been solved for me, and I'm using 1.2.22 now. Has it been resolved for you?
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

What is 1.2.22? The png loading works on my 64bit machines, yes.
AzP
Posts: 16
Joined: Fri Jun 09, 2006 8:47 pm
Location: Stockholm, Sweden

Post by AzP »

libpng version 1.2.22. That is the newest stable release.
What version are you using and compiling against? Do I need to recompile Irrlicht after the new version of libpng has been installed?
AzP
Posts: 16
Joined: Fri Jun 09, 2006 8:47 pm
Location: Stockholm, Sweden

Still there in 1.2.25

Post by AzP »

Hi again..

After waiting for any fixes regarding this problem, I'm growing tired of not seeing any changes... It is really stopping me from getting any further on my little project, which really sucks.

I've tried installing the 1.2.25beta03 version of libpng, but it still only shows big gray images. Completely without alpha channel too.

See the two different pictures below, the first one is how it used to look (and I think it still looks like it on a 32 bit os) and the second is how in looks for me.

Image

Image

Is it true that it is only because of a problem with libpng on 64 bit, or could I fix it in some way?
No, that was a 64bit problem with libpng. It'll be fixed in the next release.
Where did you find that? I've read through the libpng bug database, but I couldn't find anything regarding it.

The output still says "PNG FATAL ERROR: Invalid image width" when loading the images. It doesn't matter if it's a image with a size which is the power of two or not.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

I added this patch to the Irrlicht version of libpng:
http://irrlicht.svn.sourceforge.net/vie ... 643&r2=688
Without this change the size of the numbers is not 32bit anymore, hence the numbers are read wrongly.
AzP
Posts: 16
Joined: Fri Jun 09, 2006 8:47 pm
Location: Stockholm, Sweden

Post by AzP »

Thank you! You have made my day!! I will try it when I get home.

How come more/other people haven't seen this problem?

And btw, shouldn't this have been released, since it was changed 4th of June 2007?
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Yes, the actual libpng code of Irrlicht 1.4 uses it. And I can load pngs on my 64bit linux. Maybe you link in a different libpng instead of using the one from libIrrlicht?
AzP
Posts: 16
Joined: Fri Jun 09, 2006 8:47 pm
Location: Stockholm, Sweden

Post by AzP »

Yeah, I'm using Gentoo, so I think it's using the system installed libpng. I'll see if I can sort this out now ;)
AzP
Posts: 16
Joined: Fri Jun 09, 2006 8:47 pm
Location: Stockholm, Sweden

Post by AzP »

A strange thing with this problem is that i REALLY want Irrlicht to use my systems libpng, which is libpng 1.2.25. That would probably have fixed the issue. But now it doesn't seem to use that, does it always come bundled with it's own png library?

Any way to force it to compile against the systems library instead? Do I really want that?

I think I'll check if I'm using 1.4 release of Irrlicht or an older one...
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

You can undefine _IRR_USE_NON_SYSTEM_LIB_PNG_ in IrrCompileConfig.g to use the system library. But this will also require some changes to the project setup when compiling Irrlicht, because this define only changes some include statements.
AzP
Posts: 16
Joined: Fri Jun 09, 2006 8:47 pm
Location: Stockholm, Sweden

Post by AzP »

Hmm the funny thing is that it is already compiled without that define. I guess the package maintainers in gentoo wants it to use the system installed version..

Why does Irrlicht have a problem with the alpha channel of png images then, since no other software on my computer has it? Strange implementation?
Post Reply