Opening a LWJGL window from a SWT app on Mac
I have a SWT app that opens a OpenGL window (using the LWJGL library) after a button is pressed. It is supposed to close it's main SWT window and open a new one with an OpenGL context. Works fine on Windows. On Mac, I get this error:
2010-03-05 02:28:25.315 java[1315:a07] [Java CocoaComponent compatibility mode]: Enabled
2010-03-05 02:28:25.316 java[1315:a07] [Java CocoaComponent compatibility mode]: Setting timeout for SWT to 0.100000
2010-03-05 02:28:25.317 java[1315:a07] Apple AWT Startup Exception : _createMenuRef called with existing principal MenuRef already associated with menu
2010-03-05 02:28:25.318 java[1315:a07] Apple AWT Restarting Native Event Thread
The SWT window closes and then the app hangs, with no windows open.
It looks like the SWT app doesn't shut down cleanly and leaves it's menu entries associated with it, which prevents the LWJGL window from opening. Mac OS X only wants one application menu. SWT doesn't free it's own menu and LWJGL wants to add another.
Facts:
A button in the SWT dialog is supposed to close the dialog and open a LWJGL window (org.lwjgl.opengl.Display).
The button sets a static variable in the app to tell it what to do next after the SWT window is closed, so the LWJGL window is NOT being opened from a SWT callback directly.
The button then closes the SWT window. I don't know the correct way of doing this but tried various combinations of shell.close, shell.dispose, display.close and display.dispose, none of them worked. They all close the window but the error occurs every time.
Does anyone know what could be done to make this work?
UPDATE: This simply does not work and it seems that Apple will not fix it, ever. The only way around it is to开发者_运维百科 launch a new app instance and pass it a parameter that tells it to open the second window.
UPDATE 2: In this particular case, I solved the problem by using the SWT dialog for the Windows version of the app and for the Mac version, I wrote a native Cocoa dialog which invokes the JVM and runs the LWJGL app when needed. That works pretty well.
It would appear to me that the problem is not SWT creating a new window or LWJGL actually doing so. I believe the problem lies in the fact that under Mac, the application menu must be registered to the process, and for some reason or another, there is a conflict of interest between the two.
You might have some better luck juggling things around a little:
- What happens when you create a LWJGL window first, then create a SWT shell?
- What happens when you initialize LWJGL statically before creating a SWT shell, then proceed to create the shell and create an LWJGL window?
Incidentally, to close a SWT window, all you need to do is dispose of the Shell
:
shell.dispose();
精彩评论