Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash while using two different renderers in main and 2nd window (MacOS / Linux) #427

Closed
Devostated opened this issue Feb 27, 2022 · 6 comments

Comments

@Devostated
Copy link

Devostated commented Feb 27, 2022

Hello, I've been creating a little tool within processing, which has a main window and a secondary. The main window is using P3D renderer and the secondary the default one. I'm using this to beable to use the Drop library for 3D models.
Here is a small example code for two windows with different renderers. It works totally fine on Windows, but not on MacOS or Linux:

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);
  }
}

This has been tested with the Processing version of 4.0b6.
My Mac is using a M1 chip and runs on Monterey 12.2.1.
I have no idea what Linux version it has been tested on.

Removing P3D from the main window and adding it to the second one, fixed it for MacOS, but not Linux.
In the following I will provide with the errors I have on Mac and Linux with having P3D in different windows.

This is the error I get on MacOS with P3D in the main window

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)

This is the Linux error with P3D in the main window

java.lang.RuntimeException: Profile GL4bc is not available on X11GraphicsDevice[type .x11, connection :0, unitID 0, handle 0x7f3f9c023ef0, owner true, ResourceToolkitLock[obj 0x6ba916fa, isOwner true, <6f968f57, 2a941cc1>[count 1, qsz 0, owner <main-FPSAWTAnimator#00-Timer0>]]], but: [GLProfile[GLES1/GLES1.hw], GLProfile[GLES2/GLES3.hw], GLProfile[GL2ES1/GLES1.hw], GLProfile[GL4ES3/GL4.hw], GLProfile[GL2ES2/GL4.hw], GLProfile[GL4/GL4.hw], GLProfile[GLES3/GLES3.hw], GLProfile[GL4/GL4.hw], GLProfile[GL3/GL4.hw], GLProfile[GL2GL3/GL4.hw]]
    at processing.opengl.PSurfaceJOGL$2.run(PSurfaceJOGL.java:410)
    at java.lang.Thread.run(Thread.java:748)
RuntimeException: Profile GL4bc is not available on X11GraphicsDevice[type .x11, connection :0, unitID 0, handle 0x7f3f9c023ef0, owner true, ResourceToolkitLock[obj 0x6ba916fa, isOwner true, <6f968f57, 2a941cc1>[count 1, qsz 0, owner <main-FPSAWTAnimator#00-Timer0>]]], but: [GLProfile[GLES1/GLES1.hw], GLProfile[GLES2/GLES3.hw], GLProfile[GL2ES1/GLES1.hw], GLProfile[GL4ES3/GL4.hw], GLProfile[GL2ES2/GL4.hw], GLProfile[GL4/GL4.hw], GLProfile[GLES3/GLES3.hw], GLProfile[GL4/GL4.hw], GLProfile[GL3/GL4.hw], GLProfile[GL2GL3/GL4.hw]]

This is the Linux error with P3D in the second window

java.lang.RuntimeException: Profile GL4bc is not available on X11GraphicsDevice[type .x11, connection :0, unitID 0, handle 0x7f16e402a4d0, owner true, ResourceToolkitLock[obj 0x143cd6fd, isOwner true, <100340a2, 5501dcc6>[count 1, qsz 0, owner <Animation Thread-FPSAWTAnimator#00-Timer0>]]], but: [GLProfile[GLES1/GLES1.hw], GLProfile[GLES2/GLES3.hw], GLProfile[GL2ES1/GLES1.hw], GLProfile[GL4ES3/GL4.hw], GLProfile[GL2ES2/GL4.hw], GLProfile[GL4/GL4.hw], GLProfile[GLES3/GLES3.hw], GLProfile[GL4/GL4.hw], GLProfile[GL3/GL4.hw], GLProfile[GL2GL3/GL4.hw]]
    at processing.opengl.PSurfaceJOGL$2.run(PSurfaceJOGL.java:410)
RuntimeException: Profile GL4bc is not available on X11GraphicsDevice[type .x11, connection :0, unitID 0, handle 0x7f16e402a4d0, owner true, ResourceToolkitLock[obj 0x143cd6fd, isOwner true, <100340a2, 5501dcc6>[count 1, qsz 0, owner <Animation Thread-FPSAWTAnimator#00-Timer0>]]], but: [GLProfile[GLES1/GLES1.hw], GLProfile[GLES2/GLES3.hw], GLProfile[GL2ES1/GLES1.hw], GLProfile[GL4ES3/GL4.hw], GLProfile[GL2ES2/GL4.hw], GLProfile[GL4/GL4.hw], GLProfile[GLES3/GLES3.hw], GLProfile[GL4/GL4.hw], GLProfile[GL3/GL4.hw], GLProfile[GL2GL3/GL4.hw]]
    at java.lang.Thread.run(Thread.java:748)
@Devostated
Copy link
Author

Devostated commented Mar 2, 2022

I figured (thanks to th75) that on macOS you need frameRate(n); in both setups in order it to work, which is not the case on Windows. I have not tested Linux. Sadly it does not run everytime, most of the time I still get following error on macOS:

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>

@Devostated
Copy link
Author

Update:
It launches without any crashes on macOS with the Processing version 3.5.4
But I get is this console output:


    0   AppKit                              0x00007ff80d86d190 -[NSWindow(NSWindow_Theme) _postWindowNeedsToResetDragMarginsUnlessPostingDisabled] + 352
    1   AppKit                              0x00007ff80d858ee6 -[NSWindow _initContent:styleMask:backing:defer:contentView:] + 1287
    2   AppKit                              0x00007ff80d8589d9 -[NSWindow initWithContentRect:styleMask:backing:defer:] + 42
    3   libnativewindow_macosx.jnilib       0x000000012d2aa3fe Java_jogamp_nativewindow_macosx_OSXUtil_CreateNSWindow0 + 398
    4   ???                                 0x000000010e3eb4c8 0x0 + 4533957832
    ```

@Devostated
Copy link
Author

Update:
thanks to th75 again, I figured that processing 4 requires to initialize the second window on frame 1 or later, so it has to be in the draw and not the setup with a framecount if statement, so it doesn't open multiple times.

@HectorCarral
Copy link
Contributor

HectorCarral commented Apr 28, 2022

Using beta 8, this issue seems to persist on Apple Silicon but not Intel, despite, as mentioned in this Issue, specifying the frame rate on both setup() and launching the second window on frame 1 or later. Same error as indicated above, after hanging without properly launching for 5 seconds:

RuntimeException: Waited 5000ms for: <50925986, 5e55ade4>[count 2, qsz 0, owner <main-FPSAWTAnimator#00-Timer0>] - <main-FPSAWTAnimator#00-Timer0-FPSAWTAnimator#00-Timer1>
java.lang.RuntimeException: Waited 5000ms for: <50925986, 5e55ade4>[count 2, qsz 0, 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: <50925986, 5e55ade4>[count 2, qsz 0, owner <main-FPSAWTAnimator#00-Timer0>] - <main-FPSAWTAnimator#00-Timer0-FPSAWTAnimator#00-Timer1>

This is some code I'm using for testing:

SecondWindow secondWindow;

void setup() {
  size(200, 200, P3D);
  frameRate(60);
}

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

public class SecondWindow extends PApplet {
  public void settings() {
    size(100, 100);
  }
  
  public void setup() {
    frameRate(60);
  }
  
  public void draw() {
    background(255, 0, 0);
  }
}

This code seems to work well on Intel but not on Apple Silicon.

Indeed, putting P3D (or P2D) also in the second window seems to fix it. However, on the Intel version, this code seems to run well regardless of this (if specifying the frame rates and launching the second widow on frame 1 or later, although sometimes, only sometimes, it seems to work fine without doing this).

I'm guessing it's an issue with JOGL on Apple Silicon #370.

@benfry
Copy link
Owner

benfry commented Apr 29, 2022

This isn't something that's ever been supported, or part of the API, or that I'd even recommend. You can't start another sketch/animation thread from the animation thread of another, that's almost certainly going to cause a deadlock.

In 4.0 beta 3 there were updates made so that it was at least somewhat more possible to run multiple OpenGL sketches simultaneously, so that their rendering threads would not collide. But nothing about mixing sketches with different renderers, which is almost certain to break on different machines, platforms, Java versions, operating systems, graphics drivers, etc.

The correct approach for doing multiple OpenGL (P2D and P3D) sketches simultaneously is to call PApplet.main() to launch each separately, from the static public void main(String[] args) method of one of the sketches, or a separate Java class with a main() method that's launching all the sketches.

But again, running multiple sketches/windows is a very difficult configuration to support. It's not something that I build or test for, and if it's working it's more luck than anything else.

@benfry benfry closed this as completed Apr 29, 2022
@github-actions
Copy link

This issue has been automatically locked. To avoid confusion with reports that have already been resolved, closed issues are automatically locked 30 days after the last comment. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 30, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants