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 & HelpOther Libraries › Web-based loadString freezes draw()
Page Index Toggle Pages: 1
Web-based loadString freezes draw() (Read 607 times)
Web-based loadString freezes draw()
Jul 18th, 2008, 9:58pm
 
I'm having problems with draw() freezing noticeably while loadString()-ing a webpage. It seems to freeze for the amount of time it takes for the webpage to return its results.

On a good day, the webpage returns pretty quickly, but the project is animated so any pauses and delays make it look shoddy.

The loadString() webpage call is used to update the data that the animation is based on, so it's not crucial that its data gets inputted before I draw the next frame, it just needs to get in at some point.

So my question is:
How can I have loadString() do its own thing without having draw() stop everything and wait for it?

If you need a code example, I can provide one...right now it's in a huge project.
Re: Web-based loadString freezes draw()
Reply #1 - Jul 20th, 2008, 6:47pm
 
I may have just found the answer to my own question from the Hacks section here. If anyone has a simpler solution I'd love to hear it too.

http://processing.org/hacks/doku.php?id=hacks:dataloadqueue

I'll give it a shot and post if it works out for other people's future reference.
Re: Web-based loadString freezes draw()
Reply #2 - Jul 20th, 2008, 7:15pm
 
It is simple, in its use, in the sketch itself...
You don't have to worry about the internals, just to provide them.
The problem isn't simple, so the solution can't be simple, but complexity can be hidden, like Processing hides most Java complexities to us.
Re: Web-based loadString freezes draw()
Reply #3 - Jul 21st, 2008, 1:32am
 
Right, loadString() and loadImage(), etc., etc. will all halt operation of your sketch, because they don't run as independent threads. This is true of local data loading, not just Web stuff. If you think about it, it makes sense -- otherwise, other parts of your sketch that relied on the loading mechanism would continue before the file had been loaded! This is generally the way all of these things operate in any environment (not just Processing) unless you explicitly set aside a thread for that task.

As far as I know, toxi's is the best approach because it's agnostic about data types.

I'm looking at some other threading examples, though, so if I think of something better for Processing I'll chime in. Smiley
Re: Web-based loadString freezes draw()
Reply #4 - Jul 21st, 2008, 3:48pm
 
It's a "Hack" so I didn't expect it to be too easy to implement but I've gotten it working now. I mostly just had to modify the listener class and variables to getAsText instead of getAsImage as my project worked with text.

My case is really simple, but this Hack covers much more complicated situations too.
Re: Web-based loadString freezes draw()
Reply #5 - Jul 21st, 2008, 3:52pm
 
Well, right -- no need to be afraid of the word "hack" in regards to that site, as some of those would be better described as tips / tricks. Smiley It's a hack in the sense that Processing core doesn't provide a facility to do this, and you're directly dumping bytes into that cache. But it does work quite nicely.
Page Index Toggle Pages: 1