2004/01/07 20:37:32
[org.ibex.core.git] / src / org / xwt / Scheduler.java
index d61ad55..5439bf9 100644 (file)
@@ -27,10 +27,23 @@ public class Scheduler {
     public static Task current() { return current; }
 
     /** synchronizd so that we can safely call it from an event-delivery thread, in-context */
-    public static synchronized void renderAll() {
-        for(int i=0; i<Surface.allSurfaces.size(); i++) {
-            Surface s = ((Surface)Surface.allSurfaces.elementAt(i));
-            do { s.render(); } while(s.abort);
+    private static volatile boolean rendering = false;
+    private static volatile boolean again = false;
+    public static void renderAll() {
+        if (rendering) { again = true; return; }
+        synchronized(Scheduler.class) {
+            try {
+                rendering = true;
+                do {
+                    again = false;
+                    for(int i=0; i<Surface.allSurfaces.size(); i++) {
+                        Surface s = ((Surface)Surface.allSurfaces.elementAt(i));
+                        do { s.render(); } while(s.abort);
+                    }
+                } while(again);
+            } finally {
+                rendering = false;
+            }
         }
     }
 
@@ -70,11 +83,12 @@ public class Scheduler {
                 }
                 renderAll();
             } catch (JSExn e) {
-                Log.log(Scheduler.class, "a JavaScript thread spawned with xwt.thread() threw an exception:");
-                Log.log(Scheduler.class, e);
+                Log.info(Scheduler.class, "a JavaScript thread spawned with xwt.thread() threw an exception:");
+                Log.info(Scheduler.class, "JS Exception: " + e.getObject() + "\n" + e.backtrace());
+                Log.info(Scheduler.class,e);
             } catch (Exception e) {
-                Log.log(Scheduler.class, "a Task threw an exception which was caught by the scheduler:");
-                Log.log(Scheduler.class, e);
+                Log.info(Scheduler.class, "a Task threw an exception which was caught by the scheduler:");
+                Log.info(Scheduler.class, e);
             }
             // if an Error is thrown it will cause the engine to quit
         }