tags:

views:

280

answers:

1

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.

A: 

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();
Paul Lammertsma
You are right about the conflict of interest. However I'm unable to statically initialize LWJGL before actually trying to open a LWJGL Display window. There's a static constructor in Sys but that doesn't do anything substantial.
TomA
What happens when you launch a LWJGL window and then a SWT window?
Paul Lammertsma
I'm curious how it worked out for you!
Paul Lammertsma
It doesn't work. I have found endless threads about this problem, an Apple engineer trying to fix this for YEARS and not giving a solution. I have given up trying to do this at all.
TomA
Wow. I'm sorry to hear that!
Paul Lammertsma