husker-dev / openglfx

OpenGL implementation for JavaFX
Apache License 2.0
80 stars 10 forks source link

Unexpected crash during regular usage #20

Closed jameshball closed 2 years ago

jameshball commented 2 years ago

As mentioned in prev issue, I'm having some issues with stability generally.

Below is an error log of a crash that occurred on macOS after initialization and whilst I was using the program. This has happened multiple times but I don't have any indication of what could have caused this, unfortunately!

hs_err_pid6291.log

The majority of the code is in Gui.java and Oscilloscope.java

I am running this as Direct mode IF_AVAILABLE since I get the following error on macOS when using NEVER:

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'NSWindow drag regions should only be invalidated on the Main Thread!'

If you want to test this locally, it's the software-oscilloscope branch of my project and it should be easily runnable by running from sh.ball.gui.Launcher.

As always, lmk if I can provide any extra info.

husker-dev commented 2 years ago

Can you show me the full stack trace of Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'NSWindow drag regions should only be invalidated on the Main Thread!'?


MacOS is very sensitive for threads. All UI related stuff must be executed from the main thread. Therefore, such errors may occur.

jameshball commented 2 years ago
2022-05-08 20:22:27.267 java[6377:213491] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'NSWindow drag regions should only be invalidated on the Main Thread!'
*** First throw call stack:
(
    0   CoreFoundation                      0x00007ff801b681e3 __exceptionPreprocess + 242
    1   libobjc.A.dylib                     0x00007ff8018c8c13 objc_exception_throw + 48
    2   CoreFoundation                      0x00007ff801b90aa6 -[NSException raise] + 9
    3   AppKit                              0x00007ff804539634 -[NSWindow(NSWindow_Theme) _postWindowNeedsToResetDragMarginsUnlessPostingDisabled] + 321
    4   AppKit                              0x00007ff80454388b -[NSView setFrameSize:] + 2304
    5   AppKit                              0x00007ff804585f83 -[NSTitlebarView setFrameSize:] + 86
    6   AppKit                              0x00007ff8045543d5 -[NSView setFrame:] + 404
    7   AppKit                              0x00007ff804585f26 -[NSTitlebarView resizeWithOldSuperviewSize:] + 95
    8   AppKit                              0x00007ff804565b04 -[NSView resizeSubviewsWithOldSize:] + 488
    9   AppKit                              0x00007ff804543602 -[NSView setFrameSize:] + 1655
    10  AppKit                              0x00007ff8045667ac -[NSTitlebarContainerView setFrameSize:] + 146
    11  AppKit                              0x00007ff8045543d5 -[NSView setFrame:] + 404
    12  AppKit                              0x00007ff804566185 -[NSView resizeWithOldSuperviewSize:] + 691
    13  AppKit                              0x00007ff804565b04 -[NSView resizeSubviewsWithOldSize:] + 488
    14  AppKit                              0x00007ff804543602 -[NSView setFrameSize:] + 1655
    15  AppKit                              0x00007ff804563ea1 -[NSThemeFrame setFrameSize:] + 482
    16  AppKit                              0x00007ff8045634f0 -[NSWindow _oldPlaceWindow:fromServer:] + 688
    17  AppKit                              0x00007ff80456197e -[NSWindow _setFrameCommon:display:fromServer:] + 1278
    18  libglfw.dylib                       0x00000001352b9d31 libglfw.dylib + 101681
    19  ???                                 0x0000000112d2c53a 0x0 + 4610770234
    20  ???                                 0x0000000112d2842b 0x0 + 4610753579
)
libc++abi: terminating with uncaught exception of type NSException
husker-dev commented 2 years ago

It seems to only show up on MacOS. All logs point to an error inside the native code, so I can't figure out what the problem is.

I ran your application on Windows using DirectX and OpenGL and it worked perfectly. But it was necessary to put DirectDrawPolicy.NEVER, otherwise the image was not updated.

Unfortunately, I don't have a MacBook, so I can't test it myself on MacOS

By the way, cool app, I'm deaf now

husker-dev commented 2 years ago

I'm currently reworking Direct mode (#17). It may fix your problem. But I don't know when the update will be released.

jameshball commented 2 years ago

Apologies for the ear damage!! You get used to it after a while lol

husker-dev commented 2 years ago

Try to add this parameter to the Java options:

-XstartOnFirstThread
jameshball commented 2 years ago

I haven't explicitly tried this yet, purely because I've tried this before when trying to use raw LWJGL with JavaFX and it doesn't work well with JavaFX - the window never opens. Will attempt again and let you know.

jameshball commented 2 years ago

Just did some tests on v2.9.1.

Tried running it on mac with DirectDrawPolicy.NEVER without -XstartOnFirstThread and I get the following stack trace:

Exception in Application start method
Exception in thread "main" java.lang.RuntimeException: Exception in Application start method
    at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:901)
    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:196)
    at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: java.lang.RuntimeException: Could not reflectively access Dispatch
    at com.huskerdev.openglfx.utils.OpenGLFXUtils$Companion.executeOnMainThread(OpenGLFXUtils.kt:32)
    at com.huskerdev.openglfx.lwjgl.universal.LWJGLUniversal.<init>(LWJGLUniversal.kt:50)
    at com.huskerdev.openglfx.lwjgl.LWJGLInitializer.createUniversal(LWJGLInitializer.kt:13)
    at com.huskerdev.openglfx.lwjgl.LWJGLInitializer.createUniversal(LWJGLInitializer.kt:7)
    at com.huskerdev.openglfx.OpenGLCanvas$Companion.create(OpenGLCanvas.kt:42)
    at com.huskerdev.openglfx.OpenGLCanvas.create(OpenGLCanvas.kt)
    at sh.ball.gui.Gui.startOscilloscope(Gui.java:123)
    at sh.ball.gui.Gui.start(Gui.java:113)
    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:847)
    at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:484)
    at com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:457)
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
    at com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:456)
    at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
Caused by: java.lang.ClassNotFoundException: com.apple.concurrent.Dispatch
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
    at java.base/java.lang.Class.forName0(Native Method)
    at java.base/java.lang.Class.forName(Class.java:375)
    at com.huskerdev.openglfx.utils.OpenGLFXUtils$Companion.executeOnMainThread(OpenGLFXUtils.kt:28)
    ... 13 more

When running it with -XstartOnFirstThread my main JavaFX window doesn't open at all (same behaviour I've had outside of using this library).

husker-dev commented 2 years ago

Now I understand the problem and know the solution - GLFW creates an OpenGL context, but it also creates a window that requires main thread.

I think I need to stop using GLFW, and create contexts manually. Fortunately, LWJGL has some native functions for each platform. I'm already working on it, and I hope to release a global update soon.

Looks like I'll have to stop JOGL support...

husker-dev commented 2 years ago

In addition, GLFW takes a very long time to load. Thus the initialization time can be reduced

jameshball commented 2 years ago

Amazing! Happy to help whatever I can on macos

husker-dev commented 2 years ago

Fixed in new release