无法在 Mac OS X 上显示 SWT
我正在运行 Mac OS X Snow Leopard,并且不想从 OSGi 捆绑包中的激活器访问显示器。
下面是我的激活器的启动方法:
@Override
public void start(BundleContext context) throws Exception {
ExecutorService service = Executors.newSingleThreadExecutor();
service.execute(new Runnable() {
@Override
public void run() {
Display display = Display.getDefault();
Shell shell = new Shell(display);
Text helloText = new Text(shell, SWT.CENTER);
helloText.setText("Hello SWT!");
helloText.pack();
shell.pack();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
});
}
在 Windows 环境中调用此代码工作正常,但在 Mac OS X 上部署时会得到以下输出:
2009-10-14 17:17:54.050 java[2010:10003] *** __NSAutoreleaseNoPool(): Object 0x101620d20 of class NSCFString autoreleased with no pool in place - just leaking 2009-10-14 17:17:54.081 java[2010:10003] *** __NSAutoreleaseNoPool(): Object 0x100119240 of class NSCFNumber autoreleased with no pool in place - just leaking 2009-10-14 17:17:54.084 java[2010:10003] *** __NSAutoreleaseNoPool(): Object 0x1001024b0 of class NSCFString autoreleased with no pool in place - just leaking 2009-10-14 17:17:54.086 java[2010:10003] *** __NSAutoreleaseNoPool(): Object 0x7fff701d7f70 of class NSCFString autoreleased with no pool in place - just leaking 2009-10-14 17:17:54.087 java[2010:10003] *** __NSAutoreleaseNoPool(): Object 0x100113330 of class NSCFString autoreleased with no pool in place - just leaking 2009-10-14 17:17:54.092 java[2010:10003] *** __NSAutoreleaseNoPool(): Object 0x101624540 of class NSCFData autoreleased with no pool in place - just leaking . . .
我使用了 -XstartOnFirstThread VM 参数,但没有任何运气。我使用的是 64 位 Cocoa,但我也尝试过 32 位 Cocoa。
尝试使用 Carbon 时,出现以下错误:
Invalid memory access of location 00000020 eip=9012337c
调试 Display 类时,我可以看到 Displays[] 数组仅包含空引用。
I'm running Mac OS X Snow Leopard and wan't to access the Display from the activator in an OSGi bundle.
Below is the start method for my activator:
@Override
public void start(BundleContext context) throws Exception {
ExecutorService service = Executors.newSingleThreadExecutor();
service.execute(new Runnable() {
@Override
public void run() {
Display display = Display.getDefault();
Shell shell = new Shell(display);
Text helloText = new Text(shell, SWT.CENTER);
helloText.setText("Hello SWT!");
helloText.pack();
shell.pack();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
});
}
Calling this code in a Windows environment works fine, but deploying on Mac OS X I get the following output:
2009-10-14 17:17:54.050 java[2010:10003] *** __NSAutoreleaseNoPool(): Object 0x101620d20 of class NSCFString autoreleased with no pool in place - just leaking 2009-10-14 17:17:54.081 java[2010:10003] *** __NSAutoreleaseNoPool(): Object 0x100119240 of class NSCFNumber autoreleased with no pool in place - just leaking 2009-10-14 17:17:54.084 java[2010:10003] *** __NSAutoreleaseNoPool(): Object 0x1001024b0 of class NSCFString autoreleased with no pool in place - just leaking 2009-10-14 17:17:54.086 java[2010:10003] *** __NSAutoreleaseNoPool(): Object 0x7fff701d7f70 of class NSCFString autoreleased with no pool in place - just leaking 2009-10-14 17:17:54.087 java[2010:10003] *** __NSAutoreleaseNoPool(): Object 0x100113330 of class NSCFString autoreleased with no pool in place - just leaking 2009-10-14 17:17:54.092 java[2010:10003] *** __NSAutoreleaseNoPool(): Object 0x101624540 of class NSCFData autoreleased with no pool in place - just leaking . . .
I've used the -XstartOnFirstThread VM argument without any luck. I'm on 64-bit Cocoa but I've also tried 32-bit Cocoa.
When trying on Carbon I get the following error:
Invalid memory access of location 00000020 eip=9012337c
When debugging into the Display class I can see that the Displays[] array only contains null references.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我可以确认,我们在 Mac OS X 上成功运行了 SWT Carbon,其事件循环由捆绑激活启动,因此这绝对是可能的!这是在启动 VM 时使用 -XstartOnFirstThread。
但是,使用 Cocoa SWT(64 位),我看到了同样的错误:(
看来,虽然我们运行 Carbon SWT 的方式有效,但它可能并不合规:我们正在驱动事件循环通过另一个线程,而不是您应该的主线程,这不再起作用,而且无论如何,
我可以在创建 Display 之前使用以下 hack 修复线程池错误。 (改编自 Cocoa SWT Device 构造函数):
但是,随后的事件循环挂起(即 display.readAndDispatch ()/display.sleep () 舞蹈),我怀疑它只是因为不是主线程而没有读取 UI 事件。
我不确定是否有一个彻底的方法来解决这个问题,在我的例子中,我们控制启动 OSGi 的主 JVM 线程,所以我正在考虑在其中添加一个可以在之后运行 SWT 事件循环的钩子。 OSGi 启动。
I can confirm that we successfully run SWT Carbon on Mac OS X in its own event loop kicked off by a bundle activation, so it's definitely possible! This is using -XstartOnFirstThread when launching the VM.
But, with Cocoa SWT (64-bit), I see the same error :(
It seems that, although the way we ran Carbon SWT worked, it was probably not kosher: we were driving the event loop through another thread, not the main one as you're supposed to. Under Cocoa SWT, this doesn't work any more, and it was probably dodgy practice anyway.
I can fix the thread pool errors with the following hack before creating the Display (adapted from the Cocoa SWT Device constructor):
However, the event loop that follows hangs (i.e. the display.readAndDispatch ()/display.sleep () dance). I suspect it's just not reading UI events due not being the main thread.
I'm not sure if there's a kosher way to fix this. In my case, we control the main JVM thread that launches OSGi, so I'm toying with the idea of adding a hook in there that can run the SWT event loop after OSGi launch.
我遇到的问题是,一旦调用“display.sleep()”,窗口就会冻结应用程序。如果其他人遇到同样的问题,对我有用的解决方案是添加:
-XstartOnFirstThread
到执行时的虚拟机。
我试图让 Areca Backup 软件在我的 Mac 上工作,并且知道它的工作原理:)
我的系统是:MacOsX Snow Leopard 10.6.2
再见,
丹尼尔·W.
I had the problem that as soon as "display.sleep()" was called the Window freezed the application. If somebody else hace the same problem, the solution that worked for me was to add:
-XstartOnFirstThread
to the VM at the moment of the execution.
I was trying to make Areca Backup software work on my Mac, and know its working :)
My system is: MacOsX Snow Leopard 10.6.2
Bye,
Daniel W.
我遇到了同样的问题,并通过添加
-d32
和-XstartOnFirstThread
解决了它I had the same issue and resolved it by adding both
-d32
and-XstartOnFirstThread
这段代码看起来很奇怪...这应该是一个 Eclipse 插件吗?你想做什么?我猜您正在尝试创建一个带有用户界面的 RCP 插件。如果是这样,答案是:不要这样做。您的 OSGi Activator 不负责创建 SWT 显示事件循环。
在您的plugin.xml 中创建应用程序扩展以声明方式创建SWT 引导程序。它看起来像这样:
然后创建 Application 类(无论你想怎么称呼它),看起来像这样:
显然,请确保清单和运行时中有可用的 SWT 插件 (org.eclipse.ui)。
我希望这有帮助。
This code looks very strange... is this supposed to be an Eclipse plugin? What are you trying to do? I'll guess that you are trying to create an RCP plugin with a User Interface. If so, here's the answer: Don't do that. Your OSGi Activator is not be responsible for creating the SWT display event loop.
Create an application extension in your plugin.xml to declaratively create the SWT bootstrap. It will look something like this:
Then create the Application class (call it whatever you want) to look something like this:
Obviously make sure you have the SWT plugins (org.eclipse.ui) available in your Manifest as well as the runtime.
I hope that helps.