Quantcast
Channel: Processing Forum
Viewing all articles
Browse latest Browse all 1768

Re : 2.x PGraphics thread crash

$
0
0
I got this to work... not sure how safe it is though....
  1. import java.util.concurrent.ExecutorService;
  2. import java.util.concurrent.Executors;

  3. PGraphics buffer;
  4. boolean runthread = false;
  5. ExecutorService executor;
  6. PGraphicsOpenGL pgl;
  7. PGL pglx;

  8. void setup() {
  9.   size(width, height, P3D);
  10.   buffer = createGraphics(width, height, P3D);
  11.   executor = Executors.newFixedThreadPool(1);
  12.   pgl = (PGraphicsOpenGL) g;
  13.   pglx = pgl.beginPGL();
  14.    //pglx.context.setGLDebugSynchronous(true);
  15. }
  16. void draw() {
  17.   //do stuff
  18.   stroke(random(0,255),random(0,255),random(0,255));
  19.   line(random(0,width),random(0,height),random(0,width),random(0,height));
  20.   if (!runthread) {
  21.     runthread = true;
  22.     executor.submit(new RunLoadNodes());
  23.   }
  24. }
  25. void loadbuffer() {
  26.   println("ya");
  27.   pglx.context.makeCurrent();
  28.   buffer.beginDraw();
  29.   //do stuff
  30.   buffer.endDraw();
  31.   pglx.context.release();
  32. }
  33. public class RunLoadNodes implements Runnable {
  34.   public RunLoadNodes() {
  35.   }
  36.   public void run() {
  37.       loadbuffer();
  38.   }
  39. }

Viewing all articles
Browse latest Browse all 1768

Trending Articles