We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › loadimage timeouts break program
Page Index Toggle Pages: 1
loadimage timeouts break program (Read 752 times)
loadimage timeouts break program
Jan 20th, 2007, 3:02am
 
Code:

PImage test;
void setup(){
size(400,400);
try{
//currently broken image
test = loadImage("http://static.last.fm/avatar/f6f524add87b1289bd1303f482dc0ee3.jpg");
//working image
//test = loadImage("http://www.ghost-hack.com/meow.jpg");
}catch(Exception e){
println("we have a problem!, but is it being caught?");
println(e);
}
}

void draw(){
background(0);
if(test!=null)
image(test,0,0);
}



If an image load is timing out (server not responding) the proper catch block isn't being executed at all. Instead, it looks like a C / DLL exception that's thrown. It looks like:

java.net.ConnectException: Connection timed out: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)

It will crash the entire program even if you have all network connections loading from different threads. All future network attempts will fail after this...

Please help Sad

Re: loadimage timeouts break program
Reply #1 - Jan 20th, 2007, 5:04am
 
loadImage() doesn't throw any exceptions, it will catch them internally and return 'null' for the image. it will still print the exception (which is what you're seeing) because it's helpful for debugging, because what usually follows is a NullPointerException.

i just ran your code with a println() at the end of setup() to confirm that it's not actually stopping the program, it's just that the timeout is several seconds, during which the program blocks because loadImage() isn't threaded. (see elsewhere on the board for a description of loading images in a threaded fashion).
Re: loadimage timeouts break program
Reply #2 - Jan 20th, 2007, 10:23pm
 
Hey Ben

I've actually written an entire program that loads all images threaded, and it will actually still break the program.

If the image doesn't exist, but the server responds, then that thread will die (or be caught as an error exception and handled) but the main thread will keep drawing.

In this example I posted (the image server is now back online, so you'll need another non-responsive server...) even if the loadImage is threaded it will crash the program.

Hrm.. let me make an example in 5 minutes.

~M
Re: loadimage timeouts break program
Reply #3 - Jan 20th, 2007, 10:43pm
 
sigh.. I can't reproduce it. I can't find a server that will time out, even looking through all the digg sites hoping one is dugg to death.

Anyway, is there a way to simulate a server time-out? I am absolutely certain this will not work, even with threading (the current project I'm working on proves this, but there is a LOT of code and resources to upload Sad    )
Re: loadimage timeouts break program
Reply #4 - Jan 20th, 2007, 10:58pm
 
i suspect it's elsewhere in your code. last night when i tested it, i still got the error:

java.net.ConnectException: Connection timed out: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)

but the example continued just fine. there may be something else that's causing a problem elsewhere in the code, but it's not showing up as an error.

if you're on a mac, there are additional problems with some errors not showing in sketches that use threads, but iirc you use a pc, right?
Page Index Toggle Pages: 1