Two windows (Default and P3D) on macOS

Hello,

I made a simple model viewer and wanted to use a Drop library for drag and drop. I had to use a second 2D window with default renderer in order to drag and drop. It works great on windows, but not on macOS.

I used this example , but it doesn’t work to have a P3D as main window and default renderer as applet.

I made the code really barebone for testing

SecondApplet sa;

void settings() {
  size(512, 512, P3D);
}

void setup() {
  String[] args = {"blah"};
  sa = new SecondApplet();
  PApplet.runSketch(args, sa);
}

void draw() {
  background(0);
}

public class SecondApplet extends PApplet {
  public void settings() {
    size(200, 200);
  }

  public void setup() {

  }

  public void draw() {
    background(255);
  }
}

but I’m getting following error:

RunnableTask.run(): A caught exception occured on thread main-Display-.macosx_nil-1-EDT-1: RunnableTask[enqueued true[executed false, flushed false, thread[0x512c8489, main-Display-.macosx_nil-1-EDT-1]], tTotal 0 ms, tExec 0 ms, tQueue 0 ms, attachment null, throwable java.lang.RuntimeException: Waited 5000ms for: <713d35ee, 54b3588e>[count 2, qsz 0, owner <main-FPSAWTAnimator#00-Timer0>] - <main-Display-.macosx_nil-1-EDT-1>]
java.lang.RuntimeException: Waited 5000ms for: <713d35ee, 54b3588e>[count 2, qsz 0, owner <main-FPSAWTAnimator#00-Timer0>] - <main-Display-.macosx_nil-1-EDT-1>
    at jogamp.common.util.locks.RecursiveLockImpl01Unfairish.lock(RecursiveLockImpl01Unfairish.java:198)
    at jogamp.newt.WindowImpl$ResizableAction.run(WindowImpl.java:2159)
    at jogamp.newt.DisplayImpl.runOnEDTIfAvail(DisplayImpl.java:447)
    at jogamp.newt.WindowImpl.runOnEDTIfAvail(WindowImpl.java:2859)
    at jogamp.newt.WindowImpl.setResizable(WindowImpl.java:2195)
    at com.jogamp.newt.opengl.GLWindow.setResizable(GLWindow.java:371)
    at processing.opengl.PSurfaceJOGL.lambda$setResizable$5(PSurfaceJOGL.java:436)
    at com.jogamp.common.util.RunnableTask.run(RunnableTask.java:125)
    at jogamp.newt.DefaultEDTUtil$NEDT.run(DefaultEDTUtil.java:375)
DefaultEDT.run(): Caught exception occured on thread main-Display-.macosx_nil-1-EDT-1: RunnableTask[enqueued false[executed true, flushed false, thread[0x512c8489, main-Display-.macosx_nil-1-EDT-1]], tTotal 5010 ms, tExec 5010 ms, tQueue 0 ms, attachment null, throwable java.lang.RuntimeException: Waited 5000ms for: <713d35ee, 54b3588e>[count 2, qsz 0, owner <main-FPSAWTAnimator#00-Timer0>] - <main-Display-.macosx_nil-1-EDT-1>]
java.lang.RuntimeException: Waited 5000ms for: <713d35ee, 54b3588e>[count 2, qsz 0, owner <main-FPSAWTAnimator#00-Timer0>] - <main-Display-.macosx_nil-1-EDT-1>
    at jogamp.common.util.locks.RecursiveLockImpl01Unfairish.lock(RecursiveLockImpl01Unfairish.java:198)
    at jogamp.newt.WindowImpl$ResizableAction.run(WindowImpl.java:2159)
    at jogamp.newt.DisplayImpl.runOnEDTIfAvail(DisplayImpl.java:447)
    at jogamp.newt.WindowImpl.runOnEDTIfAvail(WindowImpl.java:2859)
    at jogamp.newt.WindowImpl.setResizable(WindowImpl.java:2195)
    at com.jogamp.newt.opengl.GLWindow.setResizable(GLWindow.java:371)
    at processing.opengl.PSurfaceJOGL.lambda$setResizable$5(PSurfaceJOGL.java:436)
    at com.jogamp.common.util.RunnableTask.run(RunnableTask.java:125)
    at jogamp.newt.DefaultEDTUtil$NEDT.run(DefaultEDTUtil.java:375)

I tried switching the renderers of the windows, so default on main and p3d on second. Which totally worked fine, but when I try to switch those windows in the already mentioned example i’m getting errors left and right with everything I try. From unsupported file to ArrayIndexOutOfBoundsException (due to wrong placement)

One of my rewritings with switched windows:

// DRAG + DROP
import drop.*;
SDrop drop;
MyDropListener m;

PShape img;
String imgPath = "";

// second window
SecondApplet sa;
boolean saInit = true;

void settings() {
  size(200, 200);
}
void setup() {
  surface.setResizable(true);
  surface.setTitle("dragImage");
  drop = new SDrop(this);
  m = new MyDropListener();
  drop.addDropListener(m);

  String[] args = {"blah"};
  sa = new SecondApplet();
  PApplet.runSketch(args, sa);
}
void draw() {
  if (saInit) {
    surface.setLocation(0, 0);
    saInit= false;
  }
  background(255);
  m.draw();
}


// a custom DropListener class.
class MyDropListener extends DropListener {
  int myC = 0;

  MyDropListener() {
    setTargetRect(0, 0, width, height);
  }

  void draw() {
    sa.noStroke();
    sa.fill(0, 255, 0, myC);
    sa.rect(0, 0, width, height);
    sa.stroke(0);
  }
  void dropEnter() {
    myC = 100;
  }
  void dropLeave() {
    myC = 0;
  }

  void dropEvent(DropEvent theEvent) {
    img = null;
    imgPath = theEvent.toString();
    img = loadShape(imgPath);
  }
}

public class SecondApplet extends PApplet {
  public void settings() {
    size(512, 512, P3D);
  }

  public void setup() {
    surface.setResizable(true);
    
  }

  public void draw() {
    background(0);
    if (img != null) {
      shape(img, 0, 0);
    }
  }
}

hi,

i tested first code and it works on my computer, what is your version of macos and processing?
(note: as i m on processing 3.5.4, i added frameRate(20); on the two setup(){} )

I’m using the Processing version of 4.0b6. My Mac is using a M1 chip and runs on Monterey 12.2.1.
Which of those codes did you try?

The barebone code worked fine with adding frameRate(20);! That’s great to know, but my main code still getting this error:

RuntimeException: Waited 5000ms for: <7881e80f, 7646196f>[count 2, qsz 1, owner <main-FPSAWTAnimator#00-Timer0>] - <main-FPSAWTAnimator#00-Timer0-FPSAWTAnimator#00-Timer1>
java.lang.RuntimeException: Waited 5000ms for: <7881e80f, 7646196f>[count 2, qsz 1, owner <main-FPSAWTAnimator#00-Timer0>] - <main-FPSAWTAnimator#00-Timer0-FPSAWTAnimator#00-Timer1>
    at processing.opengl.PSurfaceJOGL.lambda$initAnimator$2(PSurfaceJOGL.java:411)
    at java.base/java.lang.Thread.run(Thread.java:833)
RuntimeException: Waited 5000ms for: <7881e80f, 7646196f>[count 2, qsz 1, owner <main-FPSAWTAnimator#00-Timer0>] - <main-FPSAWTAnimator#00-Timer0-FPSAWTAnimator#00-Timer1>

Edit:
The barebone code does not run everytime, sometimes I get the error above there aswell.

hi,
i’m on m1 12.2.1 too…
i tested barebone, in 3.5.4 it always run
but in 4.0b5, it fail
it works if you make sure first window is set before creating the second one
i got this kind of error when tried to manipulate opengl stuff so i tried this but i can’t say i really understand what i’m doing (;

SecondApplet sa;

void settings() {
  size(512, 512, P3D);
}

void setup() {
  frameRate(20);
}

void draw() {
  background(0);
  if (frameCount==1) {
    String[] args = {"blah"};
    sa = new SecondApplet();
    PApplet.runSketch(args, sa);
  }
}

public class SecondApplet extends PApplet {
  public void settings() {
    size(200, 200);
  }

  public void setup() {
    frameRate(20);
  }

  public void draw() {
    background(random(255));
  }
}

Hey,
I’m really surprised that it does work on 3.5.4, just tested it myself. The if (frameCount==1)… sadly didn’t work for my application. I attached the window position of the Second Applet ( surface.setLocation(wx-8, wy+770); ) to my main window and it just gets Nullpointer, but I think I will beable to fix that with the knowledge you just gave me.
Thank you so much!

Edit:
Update: I fixed it! Thank you so much!