Bug? LoadImage() causes program to crash

Everything else that doesn't fall into one of the other PB categories.
c4s
Addict
Addict
Posts: 1981
Joined: Thu Nov 01, 2007 5:37 pm
Location: Germany

Bug? LoadImage() causes program to crash

Post by c4s »

Wow, I needed at least 2 hours (because first I was on a wrong track) to reproduce the error I get with this code:

Code: Select all

#File = "C:\image.jpg"  ; I'm using this: http://em.q-soft.ch/filestore/a4/hyrC4BGV1j.image.jpg._


; Insert those lines to get the 2. crash
;UseJPEGImageDecoder()
;UsePNGImageDecoder()
UseTGAImageDecoder()
UseJPEG2000ImageDecoder()

; Make a backup
CopyFile(#File, #File + ".bak")

; Load normal image
ImageID = LoadImage(#PB_Any, #File)  ; <- 1. Crash: "Read error at address 12813"
If ImageID <> 0
	FreeImage(ImageID)
	Debug "Load normal - Ok"
Else
	Debug "Load normal - Error"
EndIf

; Make image corrupt
FileID = OpenFile(#PB_Any, #File)
If FileID <> 0
	FileSeek(FileID, 23)
	WriteByte(FileID, $F9)  ; (Wrong marker size, correct is $6E)
	CloseFile(FileID)
EndIf

; Load corrupt image
ImageID = LoadImage(#PB_Any, #File)  ; <- 2. Crash: "Read error at address 12813"
If ImageID <> 0
	FreeImage(ImageID)
	Debug "Load corrupt - Ok"
Else
	Debug "Load corrupt - Error"
EndIf

; Backup - you won't get here anyway because of the crashs ;)
DeleteFile(#File)
RenameFile(#File + ".bak", #File)
The following normal image that I corrupt with the code causes the crash in my program:
http://em.q-soft.ch/filestore/a4/hyrC4BGV1j.image.jpg._

It's possible to create the crash in two ways: By using a combination of image decoders and by corrupting the image.
Anyway I learned to post it in the discussion first because maybe I mixed something up again. ;)
If any of you native English speakers have any suggestions for the above text, please let me know (via PM). Thanks!
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8453
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: Bug? LoadImage() causes program to crash

Post by netmaestro »

Code: Select all

#File = "d:\image.jpg"  ; I'm using this: http://em.q-soft.ch/filestore/a4/hyrC4BGV1j.image.jpg._

; Insert those lines to get the 2. crash
UseJPEGImageDecoder()
UsePNGImageDecoder()
UseTGAImageDecoder()
UseJPEG2000ImageDecoder()

; Make a backup
CopyFile(#File, #File + ".bak")

; Load normal image
ImageID = LoadImage(#PB_Any, #File)  ; <- 1. Crash: "Read error at address 12813"
If ImageID <> 0
   FreeImage(ImageID)
   Debug "Load normal - Ok"
Else
   Debug "Load normal - Error"
EndIf

DeleteFile(#File)
RenameFile(#File + ".bak", #File)
Your first crash is caused by the decoder not being loaded, the second because you deliberately corrupt the file. With the correct decoder loaded, regardless of how many other decoders are loaded as well, the program works fine. The "crashes" are only debugger stops, if you run without debugger there is no crash, it just doesn't work. All this is to be expected.
BERESHEIT
c4s
Addict
Addict
Posts: 1981
Joined: Thu Nov 01, 2007 5:37 pm
Location: Germany

Re: Bug? LoadImage() causes program to crash

Post by c4s »

netmaestro wrote:Your first crash is caused by the decoder not being loaded, the second because you deliberately corrupt the file. With the correct decoder loaded, regardless of how many other decoders are loaded as well, the program works fine. The "crashes" are only debugger stops, if you run without debugger there is no crash, it just doesn't work. All this is to be expected.
That's the point: It isn't a debugger stop. The executable immediately closes itself so as I wrote in my example code you won't come to the backup.
Sorry but did you even tried the code with this image?

If the image is corrupt I should get a #False return value but not a complete crash.
Also I don't understand why I should get a warning if one image decoder isn't loaded. Just comment every decoder out and no compiler warning is comming as expected but a #False return value...
If any of you native English speakers have any suggestions for the above text, please let me know (via PM). Thanks!
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8453
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: Bug? LoadImage() causes program to crash

Post by netmaestro »

Don't worry about my opinion, it doesn't count for anything. The team will look at it and if they see something to fix, it'll get fixed.
BERESHEIT
c4s
Addict
Addict
Posts: 1981
Joined: Thu Nov 01, 2007 5:37 pm
Location: Germany

Re: Bug? LoadImage() causes program to crash

Post by c4s »

Sorry, for being harsh but you know...I spend the whole day searching for the cause. And to me it looks like a bigger problem... So overall I'm getting a bit upset.

Edit:
Should I create a new message in the bug forum?
If any of you native English speakers have any suggestions for the above text, please let me know (via PM). Thanks!
Post Reply