在Mac上从SWT应用程序打开LWJGL窗口 [英] Opening a LWJGL window from a SWT app on Mac

查看:203
本文介绍了在Mac上从SWT应用程序打开LWJGL窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个SWT应用程序,可以在按下按钮后打开OpenGL窗口(使用LWJGL库).应该关闭它的主SWT窗口,并使用OpenGL上下文打开一个新窗口.在Windows上工作正常.在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

SWT窗口关闭,然后应用程序挂起,没有打开任何窗口.

The SWT window closes and then the app hangs, with no windows open.

SWT应用程序似乎没有完全关闭,并留下了与之关联的菜单条目,这阻止了LWJGL窗口打开. Mac OS X只需要一个应用程序菜单. SWT不会释放它自己的菜单,LWJGL想添加另一个菜单.

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.

事实:

  • 应该在SWT对话框中单击一个按钮以关闭对话框并打开LWJGL窗口(org.lwjgl.opengl.Display).

  • A button in the SWT dialog is supposed to close the dialog and open a LWJGL window (org.lwjgl.opengl.Display).

该按钮在应用程序中设置了一个静态变量,以告知它在关闭SWT窗口后下一步要做什么,因此不会直接从SWT回调中打开LWJGL窗口.

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.

该按钮随后关闭SWT窗口.我不知道执行此操作的正确方法,但是尝试了shell.close,shell.dispose,display.close和display.dispose的各种组合,但它们均无效.他们都关闭了窗口,但是每次都会发生错误.

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?

更新:这根本行不通,而且看来Apple永远不会修复它.唯一的解决方法是启动一个新的应用程序实例,并向其传递一个参数,该参数告诉它打开第二个窗口.

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.

更新2:在这种特殊情况下,我通过将SWT对话框用于应用程序的Windows版本和Mac版本来解决了这个问题,我编写了一个原生的Cocoa对话框来调用JVM并在需要时运行LWJGL应用.效果很好.

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.

推荐答案

在我看来,问题不在于SWT创建新窗口还是LWJGL实际上正在这样做.我认为问题在于,在Mac上,必须将应用程序菜单注册到进程中,并且由于某种原因,两者之间存在利益冲突.

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:

  • 首先创建LWJGL窗口,然后 创建SWT shell会发生什么?
  • 在创建SWT Shell之前静态初始化LWJGL,然后继续创建Shell并创建LWJGL窗口时,会发生什么情况?
  • 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?

顺便说一句,要关闭SWT窗口,您要做的就是丢弃Shell:

Incidentally, to close a SWT window, all you need to do is dispose of the Shell:

shell.dispose();

这篇关于在Mac上从SWT应用程序打开LWJGL窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆