FreeImage Error

BlitzMax Forums/Brucey's Modules/FreeImage Error

JoshK(Posted 2012) [#1]
LoadPixmap() crashes with no explanation. LoadFreeImage() and GetPixmap() approach do not crash.

Here's the file:
http://www.leadwerks.com/werkspace/topic/5688-psd-image/

Import bah.freeimage
Import brl.pngloader

Local freeimage:TFreeImage
Local pixmap:TPixmap

Const testmode=0

If testmode=0
	freeimage = LoadFreeImage("test.psd")
	pixmap = freeimage.getPixmap()
Else
	pixmap = LoadPixmap("test.psd")	
EndIf

SavePixmapBMP pixmap,"test.bmp"

Function SavePixmapBMP:Int (pixmap:TPixmap,url:Object)
	Local stream:TStream
	Local buf:Byte[]
	Local hsize,hoffset
	Local size,width,height
	Local planes,bits,compression,isize,xpels,ypels,cols,inuse
	Local w,y
	stream=WriteStream(url)
	If Not stream Return False
	width=pixmap.width
	height=pixmap.height
	w=width*3
	w=(w+3)&$fffc
	hsize=w*height+54
	size=40
	hoffset=54
	planes=1
	bits=24
	compression=0
	isize=40
	xpels=2834
	ypels=2834
	cols=0
	inuse=0
	stream=LittleEndianStream(stream)
	WriteByte stream,Asc("B")
	WriteByte stream,Asc("M")
	WriteInt stream,hsize
	WriteInt stream,0
	WriteInt stream,hoffset
	WriteInt stream,size
	WriteInt stream,width
	WriteInt stream,height
	WriteShort stream,planes
	WriteShort stream,bits
	WriteInt stream,compression
	WriteInt stream,isize
	WriteInt stream,xpels
	WriteInt stream,ypels
	WriteInt stream,cols
	WriteInt stream,inuse	
	buf=New Byte[w]
	For y=height-1 To 0 Step -1
		ConvertPixels(pixmap.pixelptr(0,y),pixmap.format,buf,PF_BGR888,width)
		stream.WriteBytes(buf,w)
	Next
	stream.close()
	Return True
EndFunction



Brucey(Posted 2012) [#2]
This is not surprising. With no "Framework", you are building in ALL of BlitzMax's default modules, which includes libpng and libjpeg. FreeImage has its own copies of these, and it's not a good idea to mix them.
Image modules register themselves at startup, and the way BlitzMax decides how to load an image is to test loading the image against each module until one returns with success. Having mixed potentially different versions of image libraries together, the outcome, when it tries to use one of those is more likely to result in crash.