Loading...
Logo
Processing Forum

Hi,

I have been trying to display a sketch built using processing on a web browser (FireFox) with the help of processing.js

However, my browser window hangs (Not responding message in the title bar) for a couple of minutes before the sketch can be successfully loaded. I know this time is being taken as lot of computations(like reading from a huge text file several times) are being carried out by the processing code before it can display the sketch.
However, this gives a bad user experience.

Can someone help me with the resolution of this issue ?  Tried alot of things but none seem to work.

Replies(3)

What all are you doing that makes it take a couple mins. a huge text file shouldnt take a couple mins to load unless its hundreds of pages long? are you loading lots of images as well? Is there a test for this somewhere or code we can look at? Processing Js is just regular javascript so you can combine javascript with it. Can you break some of that text into a javascript String array to hold instead of loading in the huge text file?


I agree to kobby.

you could also go right into draw and display a message like "please wait..."
and then load your stuff from draw once. After that's done, have a boolean (or pogram state) that tells you loadingIsDone to avoid the loading every time draw is run.

There are some pit falls but maybe like this:

Copy code
  1. int drawRunSoManyTimes=0;
  2. boolean loadingIsDone=false;

  3. void draw () {
  4. if (drawRunSoManyTimes==1 && !loadingIsDone) {
  5.       loadMyHugeTextfile();
  6. }
  7. else {
  8. // do nothing
  9. }
  10. if (drawRunSoManyTimes==0 && !loadingIsDone) {
  11. text ("please wait...",200,200);
  12. }
  13. else {
  14. background(0);
  15. runNormalStuff();
  16. }
  17. drawRunSoManyTimes++;
  18. }


not tested................
Thanks for your suggestions. Appreciate the help.

Well when I run the processing code "memory_diagram.pde" on windows IDE it takes upto 20-30 secs so that isn't really a big problem.
However when I try to run that code in a web browser using below :-

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<script type="text/javascript" src="processing-1.2.js">
</script>
</head>
<body >
<canvas id="mysketchcanvasid" data-processing-sources="memory_diagram.pde"/></canvas>
</body>
</html>

The sketch successfully loads after a minute or so. However, during that duration the web browser hangs (Not responding message in title bar). How can I avoid this ? I tried playing around with the browser settings to increase the script running time and stuff but no luck.