Possible Crash Bug in LibPNG of FreeImage.mod

BlitzMax Forums/Brucey's Modules/Possible Crash Bug in LibPNG of FreeImage.mod

Armitage 1982(Posted 2012) [#1]
If you are using freeimage.mod (for example with CEgui) it comes with it's own version of LibPNG and LibJPG.

I'm using them instead of the BRL one to avoid conflicts.
The problem is Freeimage.mod currently using v1.2.40 of LibPNG while BRL was using an older v1.2.12.

Since I'm exclusively using Freeimage I get a nice EXCEPTION_ACCESS_VIOLATION ("pure virtual method called") error once every ~50 tilemap loading.
If it wasn't enough it only happen in release mode, never in debug mode and it's nearly impossible to reproduce that random crash.

I isolated the problem : obviously it's coming from a loadAnimImage() in my tilemap engine.
It's generally happening with a specific 768x1024 tilemap with 768 tiles of "32x32" pixels.


What I tried today was to manually update the LibPNG library inside Freeimage.mod from v1.2.40 to 1.2.48 (the last of that branch) and rebuild that module.

From the change log I see no breaking changes and my game is still working correctly.
I see no major fix either but I guess only time will tell if it was a good move or not (I'm nearly sure it won't change a thing).

I may eventually still try to use the same BRL v1.2.12 but I guess I will face low level problems with Freeimage this time.
Pretty hard to fix anything there... Too many breaking changes for recent version of LibPNG, I already try that just to see.

Does somebody using FreeImage.mod from Brucey already report such weird bug ?

Last edited 2012


AdamRedwoods(Posted 2012) [#2]
you know what, i'm not kidding but i get that error.

I created an image viewer program and every so often i get that crash.
i thought it was because i was loading thumbnails embedded in large jpegs. perhaps i'll look into this.


Armitage 1982(Posted 2012) [#3]
I think I've spot someone else having a similar bug : http://blitzmax.com/Community/posts.php?topic=96210

If that crash happen again of if by chance updating (or downgrading) LibPNG fix it, I will report it here.

For the moment no more trace of it with the v1.2.48 yet.
(Home of the LibPNG v1.2 branch if someone else want to try : http://sourceforge.net/projects/libpng/files/libpng12/ )

EDIT
40 minutes and counting : EXCEPTION_ACCESS_VIOLATION :D
Will try with v1.2.12 later on.

EDIT2
Everything still building and work fine with v1.2.12 (the same version BlitzMax is using). Hope it's coming from there or else... ?

Last edited 2012


Armitage 1982(Posted 2012) [#4]
LoadAnimImage() failed me once more, whatever the version of LibPNG I'm using...

It's a library EXCEPTION_ACCESS_VIOLATION ("pure virtual method called") error resulting in a C++ runtime crash, so I will probably have to use OllyDbg and make sure it's related to LibPNG or anything else.

Damned !

Edit
Don't know how to use OllyDbg, all I can tell is that there is a random bug somewhere in FreeImage.mod :(

Last edited 2012


Armitage 1982(Posted 2012) [#5]
SO !
Finally !

It's maybe not related with LibPNG not even with Freeimage.mod.

I discover one way to throw the EXCEPTION_ACCESS_VIOLATION : I simply endlessly reload the same level until it's happening (generally 9 times after).


I discover a few things about that error :

1) It's happening with LoadAnimImage()

2) It's happening only in Release mode, never in Debug Mode !

3) It will happen if I completely load each 768 cell_count of my tilemap
(a PNG of 768x1024, cell_width=32, cell_height=32, first_cell=0)
BUT it won't happen a single time if I'm loading 767 tiles only.
I'm just talking about loading stuff here, I'm not even trying to render an unavailable 768th frames here.

4) If I call GCCollect() before using LoadAnimImage() (with the right amount of 768 cells) : NO MORE CRASH

5) I'm reusing a Field variable here, If I'm doing a
image = Null
image = New TImage

before calling LoadAnimImage, it's like calling GCCollect() : NO MORE CRASH

5') To be sure I'm now nullify, renew my variable type, call GCCollect() then I'm only using LoadAnimImage() : NO CRASH (for the moment).


So obviously there is something bad going on with garbage collection, or maybe I'm doing wrong when reusing Field variable without nullifying them. Dunno


Anyway, it's fixing my exception and it's all I ask !

Damn, it was tough !

Last edited 2012


ziggy(Posted 2012) [#6]
Maybe raise a bug report for Mark to take a look to the GC?


Armitage 1982(Posted 2012) [#7]
It's a combination of third party modules and can only happen if you are using CEgui.mod particularly TCEsystem.renderGUI() in a very short frame (for example while updating a loading progress bar).

It's messing down the road for Freeimage and was the true responsible of that crash. I simply forget about using CEgui for loading progress and write my own loader. I guess something wrong is happening in OpenGL with CEgui but since I'm only using an old revision version (6.3) and since the official current one will soon be 8.0, there is no need to solve this.

I'm currently porting Box2D rev 247 to a new module (and it's taking ages since I know very little of C++). If I succeed in doing this I will try to do the same update with CEgui. Until then they (CrazyEddie) will surely release the version 0.8.0 which is already very compliant with OpenGL and way faster.


LT(Posted 2014) [#8]
Reviving this thread because I've been getting an error with FreeImage also. But it's inconsistent and very hard to isolate. I'm not using CEgui, so I know it's not that.


xlsior(Posted 2014) [#9]
Brucey released updated versions of the 'official' brl.mod and pub.mod modules using the latest versions of the image loader libraries -- perhaps those behave differently?


LT(Posted 2014) [#10]
Thanks, I did try that and it *seems* to have reduced the frequency that it occurs, but it still happens. :(


Brucey(Posted 2014) [#11]
Have you got some code that can reproduce the problem?


LT(Posted 2014) [#12]
Thanks for the reply, but unfortunately, I don't. It happens "every once in a while" (TM). I was hoping other people might have had some luck isolating the issue.

I know that commenting out FreeImage and using the brl loaders instead removes the problem. Of course, it could be some other conflict with my code, but it started when I began using FreeImage. The OP's description is exactly what I've experienced.

I just barely switched to the latest brl and pub mods and it has only happened once since then. I suppose it's possible that even that one time was a fluke, so I'll keep using it and see if the problem comes back.


LT(Posted 2014) [#13]
UPDATE: It's not a fluke, but hard to track and I just don't have time right now. Going to use the brl loaders, for now. :(