Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Catching an error

Author
Message
sberk
14
Years of Service
User Offline
Joined: 6th Jun 2010
Location: next to a cup of coffee
Posted: 25th Jul 2011 19:30 Edited at: 26th Jul 2011 00:53
Hi,
I'm trying to catch a runtime error. I'm loading an image using the following code:
.
However, if the file is damaged my program crashes. Is there any way to use something along try... catch ... like vb.net?
=PRoF=
21
Years of Service
User Offline
Joined: 17th Mar 2003
Location: Milton Keynes, UK
Posted: 27th Jul 2011 11:28
Sadly not. It would be a great addition to DBP's language.

You could possibly load the image into a memblock, validate it as an actual working image there before converting the memblock to image with the make image from memblock command. Altho I have no idea how you would go about the actual checking.

sberk
14
Years of Service
User Offline
Joined: 6th Jun 2010
Location: next to a cup of coffee
Posted: 27th Jul 2011 11:31
mmm.... sounds pretty complicated. You would have to implement the whole jpg-standard (if you limit it to jpgs) on your own.
Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 28th Jul 2011 04:18 Edited at: 28th Jul 2011 04:54
Do you have a damaged pic we can test this problem with or would a file renamed to .jpg or .png do the same?

Edit: I decided to create a pre-checker for .jpg files for you. It requires IanMs Matrix 1 Utilities Plugin so if you don't have it nows your chance to be one of the cool kids.

IanMs Matrix 1 Utilities Plugin Direct Download:
https://forumfiles.thegamecreators.com/download/2192430

What the following code does it checks for the .jpg identifier that's 6 bytes into all .jpgs. If the .jpg doesn't have "JFIF" at that specific spot it's not a true .jpg. This of course won't help if the .jpg is damaged beyond the "JFIF" identifier.



sberk
14
Years of Service
User Offline
Joined: 6th Jun 2010
Location: next to a cup of coffee
Posted: 28th Jul 2011 10:17
Hi,
your solution won't help. The picture was a jpg, but it was damaged during downloading (the last bytes were missing). I used

which reports whether the download was successfully started, but not successfully finished. At the moment I just check after downloading whether the file size is correct, to prevent this specific mistake.

However, I can't guarantee that the server reports always the correct size. Therfore I just wanted to make sure the programm didn't crash.
I have attached a sample pic.

sberk

PS: Since I'm not sure whether I have all necessary rights to upload the original picture I used one from wiki commons and created the same probleme.
http://commons.wikimedia.org/wiki/File:Black-tailed_gull.jpg?uselang=en
I'm not the photographer of this picture, it was me, Bamse, and all license details can be found there.
PPS: just to make it clear, the wiki picture is correct, the attached picture is the destroyed one

Attachments

Login to view attachments

Login to post a reply

Server time is: 2024-11-22 19:00:23
Your offset time is: 2024-11-22 19:00:23