LWJGLX / lwjgl3-awt

AWT support for LWJGL3
MIT License
115 stars 26 forks source link

JVM crash with "NSOpenGLContext setView: must be called from the main thread" #60

Open mbastian opened 1 year ago

mbastian commented 1 year ago

Hi folks,

I'm experiencing reproducible JVM crash when running AWTTest on Mac OS aarch64.

The JVM crash immediately with the message

Crashed Thread:        29  Java: AWT-EventQueue-0

Exception Type:        EXC_BREAKPOINT (SIGTRAP)
Exception Codes:       0x0000000000000001, 0x00000001a693be80

Termination Reason:    Namespace SIGNAL, Code 5 Trace/BPT trap: 5
Terminating Process:   exc handler [556]

Application Specific Information:
-[NSOpenGLContext setView:] must be called from the main thread.

I tried a variety of JDK (Azul 13, Temurin 11, Temurin 17, Correto 15) and it happens for all. No specific JVM parameters.

Config

Thanks in advance

SWinxy commented 1 year ago

OK I'm able to reproduce it. This may relate to #51. Thanks for the report.

tangmi commented 9 months ago

Hi, I'm also seeing this same issue on macOS 14 (Sonoma) on an M1 MBA w/ Correto 17 on 0.1.9-SNAPSHOT.

From what I gather, macOS 10.15 deprecated OpenGL and changed GL functions to require being called from the main thread. I'm not sure if there's a way to get a task runner for the com.apple.main-thread as it seems that Java's notion of its "main thread" isn't the actual main thread.

It looks like LWJGL2 solved this by implementing its own NSView, where setView and friends are presumably called by CoreAnimation on the correct thread via one of NSView's overloaded functions. I'm not sure if porting over the old LWJGL2 Display code is necessarily a fix but if there's no way around the thread restrictions of NSOpenGLContext, it might be an option.

Thanks for your time!