Problems with RunTimeError()
Blitz3D Forums/Blitz3D Beginners Area/Problems with RunTimeError()
| ||
Function LoadLogo() Logo_Pointer = LoadImage ("klogo.png") If (Logo_Pointer) <> 0 Then Return Else RuntimeError "Failed to locate & load required image file" End If End Function If DEBUG is enabled, AND the file is NOT found, I correctly get a runtimeerror. If DEBUG is DISABLED and the file is still not found, I get a black screen and nothing happens?? |
| ||
What happened to my simplified version?Function LoadLogo() Logo_Pointer = LoadImage ("klogo.png") If Logo_Pointer = 0 Then RuntimeError "Failed to locate & load required image file" End Function |
| ||
@Wolron, Same thing happens with both the "big" and simplified version. I have located the problem though. I used GRAPHICS before trying to LoadImage(). When LoadImage() fails, the program would terminate and return to Windows. But because I used GRAPHICS before "forcefully" faking a failed LoadImage(), I of course ended up with an empty blank/black GRAPHICS command. DOH! |
| ||
I'm assuming Logo_Pointer is a global variable... However, a more tidy version would be... Function LoadBitmap(filename$) bitmap = LoadImage (filename$) If bitmap = 0 Then RuntimeError "Failed to locate & load "+filename Return bitmap End Functionand then you'd use logopointer = loadbitmap("klogo.png") And they'd be no need for globals and the function is more flexible. |
| ||
@rob, I already suggested something like that in that other thread he made, but it doesn't look like he would like to use sensible and reusable code. |
| ||
@Zawran Which of my other threads? of course I want to produce sensible and reusable code. Who would NOT be interested in that?? |
| ||
@Rob, Thanks for your code snippet. It's highly appreciated. But in my case, I don't want to pass the filename as a variable to the function, but when I eventually will need to, your snippet is ideal. |
| ||
http://www.blitzbasic.com/Community/posts.php?topic=40757 that one, I was being sarcastic, its a trade of people from Denmark, can't help it really. :) The idea about passing the filename is so that you don't have to have a new function for each image you would want to load, but can reuse the same function over and over again. |