CreateImage() causes crash

Just starting out? Need help? Post your questions and find answers here.
Lebostein
Addict
Addict
Posts: 826
Joined: Fri Jun 11, 2004 7:07 am

CreateImage() causes crash

Post by Lebostein »

It is impossible to handle errors with large images inside a program. If an image is to large to create, the program crashes. Why CreateImage() don't return zero if the image creation fails?

Code: Select all

Debug CreateImage(0,4000, 32000) ; --> works
Debug CreateImage(0,4000, 32001) ; --> crash the program
User avatar
Keya
Addict
Addict
Posts: 1890
Joined: Thu Jun 04, 2015 7:10 am

Re: CreateImage() causes crash

Post by Keya »

the error log at the bottom of the PB IDE says "[ERROR] CreateImage(): Image 'Height' is > 32000 pixels" so it appears to be a fixed limit, but yes +1 for a graceful return 0 instead of crash :)

Code: Select all

Procedure SafeCreateImage(hImg, width, height, depth, bgcolor)
 If width > 32000 Or height > 32000: ProcedureReturn 0: EndIf
 ProcedureReturn CreateImage(hImg, width, height, depth, bgcolor)
EndProcedure
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: CreateImage() causes crash

Post by Fred »

It's a debugger error, which tells you are above PB limits. It can still works depending of the OS if it's supported, that's why it's not hardcoded in the CreateImage() function. If you disable the debugger it will returns 0 if the image creation failed.
Post Reply