Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Mar 18th, 2005, 4:35 PM   #1
chepfaust
Programmer
 
chepfaust's Avatar
 
Join Date: Feb 2005
Posts: 62
Rep Power: 4 chepfaust is on a distinguished road
pictureboxes and corrupted images

in my pseudo-file manager program, i've noticed that whenever i try to load an image that is corrupt (say, one that hasn't been downloaded completely and is missing some image data) into a picturebox, it invariably causes my program to hang.

i have managed a simple workaround by exiting the subroutine upon error (thus just displaying whatever image was previously displayed), which works great for 90% of the corrupted images that pass through the program but every so often i still come across a corrupted image that brings the program to its knees.

any of you guys know/can think of a more surefire solution to dealing with such errors?

thanks
chepfaust is offline   Reply With Quote
Old Mar 18th, 2005, 7:34 PM   #2
tempest
Programming Guru
 
tempest's Avatar
 
Join Date: Oct 2004
Posts: 1,041
Rep Power: 5 tempest is on a distinguished road
Send a message via ICQ to tempest Send a message via AIM to tempest Send a message via Yahoo to tempest
Use some GD library DLLs written in C++ to tie into VB and check to see if an image has all the required data to be displayed..
__________________

tempest is offline   Reply With Quote
Old Apr 2nd, 2005, 1:30 AM   #3
chepfaust
Programmer
 
chepfaust's Avatar
 
Join Date: Feb 2005
Posts: 62
Rep Power: 4 chepfaust is on a distinguished road
Quote:
Originally Posted by tempest
Use some GD library DLLs written in C++ to tie into VB and check to see if an image has all the required data to be displayed..
que?

seriously, none of that computes. what are GD library DLLs, and how much C++ do i have to learn in order to accomplish this simple(?) task? i know -nothing- about it at this point.
chepfaust is offline   Reply With Quote
Old Apr 2nd, 2005, 9:56 PM   #4
Rory
Expert Programmer
 
Rory's Avatar
 
Join Date: Jan 2005
Location: London
Posts: 542
Rep Power: 4 Rory is on a distinguished road
Send a message via MSN to Rory
Yeah, call on a DLL, or better DirectX to render your images. The GDI libraries that are in the VB runtime are incredibly primitive, as they were written for windows 98 and can only handle a few file formats.
Rory is offline   Reply With Quote
Old Apr 12th, 2005, 12:30 AM   #5
chepfaust
Programmer
 
chepfaust's Avatar
 
Join Date: Feb 2005
Posts: 62
Rep Power: 4 chepfaust is on a distinguished road
hah!

i've figured out the problem.

it only crashes when i load a corrupt image and imagebox.stretch = true. if imagebox.stretch = false, then my error handler is able to pick it up. stretching corrupt images is the cause of the problem.

so what i've done is made an invisible imagebox (.stretch = false) that i load all pictures into first. if the errorhandler doesn't detect anything wrong with it, the program loads the image into my main imagebox (.stretch = true) and there are no problems with it beyond that.

i love you guys, but sometimes, i love myself more
chepfaust is offline   Reply With Quote
Old Apr 12th, 2005, 4:12 AM   #6
Rory
Expert Programmer
 
Rory's Avatar
 
Join Date: Jan 2005
Location: London
Posts: 542
Rep Power: 4 Rory is on a distinguished road
Send a message via MSN to Rory
LOL! Good way to get around the problem.
Rory is offline   Reply With Quote
Old Apr 24th, 2005, 2:46 PM   #7
chepfaust
Programmer
 
chepfaust's Avatar
 
Join Date: Feb 2005
Posts: 62
Rep Power: 4 chepfaust is on a distinguished road
hmm well it seems my method isn't quite as infallable as i thought, i still get crashes once in a blue moon.

what's weird about it is this though- as far as i've tested, the program NEVER crashes if i make a breakpoint at the line of code where the image is first loaded into the testing (stretch=false) imagebox. the program halts before loading the image, i push F8 to allow the program to execute that line of code to load the image, and the program automatically jumps to the errorhandler before going to the next line.

here's some pseudo-code; the asterisk is the breakpoint:

imgtestingbox.stretch = false
imgmaindisplay.stretch = true

on error goto errorhandler
*imgtestingbox.picture = loadpicture(filename)
imgmaindisplay.picture = loadpicture(filename)
rest of code goes here
exit sub

errorhandler:
msgbox("there was an error")
exit sub

i suspect that the program starts loading the picture into the problematic stretch=true box before the program realizes the one in the stretch=false box is going to set off an error. i came to this conclusion because i seem to have more problems with this on my p4 than my p3.

is there a way to use an if/then statement to say "if [error happens] then [exit sub] else [continue]" right after loading the picture into the imgtestingbox? "on error..." just doesn't seem to cut it.

Last edited by chepfaust; Apr 24th, 2005 at 2:49 PM.
chepfaust is offline   Reply With Quote
Old Apr 25th, 2005, 10:27 AM   #8
Rory
Expert Programmer
 
Rory's Avatar
 
Join Date: Jan 2005
Location: London
Posts: 542
Rep Power: 4 Rory is on a distinguished road
Send a message via MSN to Rory
You want:
Try
 (do something)
Catch Err as Exception
 (if an error occurs, Err defines it)
Finally
 (always executed)
End Try
Finally, VB got some proper error handling courtesy of Delphi. VB.NET only, though. I'd also recommend it because the GDI methods are a lot more stable, and won't produce random errors.
Rory is offline   Reply With Quote
Old Apr 26th, 2005, 8:49 AM   #9
chepfaust
Programmer
 
chepfaust's Avatar
 
Join Date: Feb 2005
Posts: 62
Rep Power: 4 chepfaust is on a distinguished road
very interesting; you never seem to run out of completely new concepts i've never seen before. thanks very much; i'll try implementing that when i get a chance later on
chepfaust is offline   Reply With Quote
Old Apr 26th, 2005, 1:01 PM   #10
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
Quote:
Originally Posted by chepfaust
very interesting; you never seem to run out of completely new concepts i've never seen before.
Not fair, is it?
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 5:16 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC