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

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

Closed
mbastian opened this issue Feb 25, 2023 · 4 comments · Fixed by #75
Closed

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

mbastian opened this issue Feb 25, 2023 · 4 comments · Fixed by #75

Comments

@mbastian
Copy link

mbastian commented Feb 25, 2023

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

  • M1 Pro (2021) aarch64
  • Mac OS Ventura 13.2.1 (22D68)
  • Version: 0.1.9-SNAPSHOT

Thanks in advance

@SWinxy
Copy link
Collaborator

SWinxy commented Mar 4, 2023

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

@tangmi
Copy link

tangmi commented Jan 5, 2024

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!

@Misha999777
Copy link
Contributor

Misha999777 commented Nov 10, 2024

Hi, I came across this library and also found out that the OpenGL part is not working on recent aarch64 macOS with the error provided in this issue.

I decided to investigate it and found out that the actual problem is not the [CATransaction flush] itself, but the [platformInfo setLayer:openglViewLayer] that is called using LWJGL's ObjCRuntime in PlatformMacOSXGLCanvas:


As the error suggests, it should be called on AppKit's main thread. I used performSelectorOnMainThread as the easiest way to achieve this. As a result, it now works on Mac (I attached system details and some screenshots below).

@SWinxy @httpdigest I opened a PR #75 with these changes and will be really happy if we could merge it and make a new release, as I want to use the library in an application which should work on macOS. Please ping me in case any changes are needed.

Details:
OS: macOS 15.1 Sequoia (24B83)
SOC: Apple M2
JDK: Temurin-21.0.4+7 (aarch64)
LWJGL: 3.3.4
OpenGL+AWT

@SWinxy
Copy link
Collaborator

SWinxy commented Nov 17, 2024

Merged and new version pushed!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants