Zlib Compression - PNG Fatal Error

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.

Zlib Compression - PNG Fatal Error

Postby LunaRebirth » Thu May 17, 2018 11:55 pm

Hi,

I'm using Zlib to compress a file and send it over sockets.
Specifically from https://gist.github.com/gomons/9d446024fbb7ccb6536ab984e29e154a.
Once the client receives the compressed file and decompresses it, I can open the image in Windows Image Viewer, Paint.NET, and any other software.

However, Irrlicht won't open draw it.
I get "PNG Fatal Error: Read Error"

Why might Irrlicht be doing this, and what should I do to try to fix it?

Note that sending other files, such as WAV files to be played by OpenAL, are working and loading just fine.

Thanks
LunaRebirth
 
Posts: 330
Joined: Sun May 11, 2014 12:13 am

Re: Zlib Compression - PNG Fatal Error

Postby devsh » Fri May 18, 2018 7:35 am

Woah dude, we need to see a bit more code in that gist.

The thing which throws red flags for me is that std::string which is not used carefully on an arbitrary byte buffers could result in truncation from a single 0 byte in your buffer.
(however it won't in your gist because your std::string::append is sized, and you're debugging out the sizes, so I'd guess you'd notice)

How do you read the texture/file, do you create an IReadFile from the memory?

Note that most compression libraries pad certain buffers to become nice round multiplies of some magic constant, so you should most probably send the original buffer/file size too.

Also, have you checked that the decompressed data is 1:1 byte-for-byte identical (content and length) with the data you'd have read from disk???
User avatar
devsh
Competition winner
 
Posts: 1890
Joined: Tue Dec 09, 2008 6:00 pm
Location: UK

Re: Zlib Compression - PNG Fatal Error

Postby CuteAlien » Fri May 18, 2018 9:46 am

Try to locate first where the error really happens.
Does the zip load when you do not send it over the net?
What when compressing and not sending it over the net?
What about sending it uncompressed over the net?
IRC: #irrlicht on irc.freenode.net
Code snippets, patches&stuff: http://www.michaelzeilfelder.de/irrlicht.htm
Free racer created with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
User avatar
CuteAlien
Admin
 
Posts: 8533
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany

Re: Zlib Compression - PNG Fatal Error

Postby LunaRebirth » Fri May 18, 2018 2:33 pm

I tried to remove this post last night, or at least update it to say it was my own problem, but the site went down :-(

The files weren't identical, but I am still curious why every program I tried could open the files except Irrlicht
LunaRebirth
 
Posts: 330
Joined: Sun May 11, 2014 12:13 am

Re: Zlib Compression - PNG Fatal Error

Postby CuteAlien » Fri May 18, 2018 3:35 pm

Once things are messed up anything can happen. Don't think too much about it :-)
IRC: #irrlicht on irc.freenode.net
Code snippets, patches&stuff: http://www.michaelzeilfelder.de/irrlicht.htm
Free racer created with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
User avatar
CuteAlien
Admin
 
Posts: 8533
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany

Re: Zlib Compression - PNG Fatal Error

Postby MartinVee » Fri May 18, 2018 4:07 pm

Since you asked...

Some program or library may decompress the zlib'ed file in chunk, and try to display the chunks individually, instead of stopping the entire process on a bad chunk. Since a PNG is pretty much a zlib'ed BMP, each valid chunk will hold valid bitmap data. And for each invalid chunk, you may still have a valid IHDR width and height, which would enable the rendering of "something". That "something" may be noise, repeating of the last chunk, random colors, ... name it, that entierly depends on the implementation.

So, you may end up with something that closely (or not) looks like the original image. That may or may not be what you want.

Personnaly, since in my line of work all graphical assets have to go through a rigorous approval process, I don't want Irrlicht to render it "close enough". If the asset is bad, then it's bad. I need to fix that.

So, again personnaly, I'm good with Irrlicht not displaying it. But I can understand why a program like Irfanview (for example) would try to display a PNG as best at it can, even if a chunk or two are wrong. After all, you don't want to loose an picture of an important moment just for a byte or two of corruption.
MartinVee
 
Posts: 131
Joined: Tue Aug 02, 2016 3:38 pm
Location: Québec, Canada

Re: Zlib Compression - PNG Fatal Error

Postby LunaRebirth » Fri May 18, 2018 7:38 pm

Thanks for the detailed explanation, that makes sense why you would not want to display an "almost good enough" image.
LunaRebirth
 
Posts: 330
Joined: Sun May 11, 2014 12:13 am


Return to Beginners Help

Who is online

Users browsing this forum: No registered users and 0 guests