gpt4 book ai didi

java - 将 SWT 与 JOGL 结合使用时随机崩溃(竞争条件?)

转载 作者:行者123 更新时间:2023-12-02 09:36:58 24 4
gpt4 key购买 nike

我正在使用 JOGL 和 SWT/AWT 桥编写一个 SWT 应用程序,并且尝试在 Composite 内创建多个 GLCanvas 对象,我'然后我尝试将其放入选项卡中。当它工作时,它看起来像这样:

Working correctly

但大多数时候(大约 75% 可能是随机的)它会崩溃并显示以下错误消息:

A fatal error has been detected by the Java Runtime Environment:
SIGSEGV (0xb) at pc=0x0024843a, pid=8618, tid=2345560944

JRE version: 6.0_22-b22
Java VM: OpenJDK Server VM (20.0-b11 mixed mode linux-x86 )
Derivative: IcedTea6 1.10.2
Distribution: Ubuntu 11.04, package 6b22-1.10.2-0ubuntu1~11.04.1
Problematic frame: C
[libpthread.so.0+0x843a] __pthread_mutex_lock+0x11a

我也尝试过只使用一张 Canvas 而不是两张,但仍然遇到相同的随机崩溃。有时,我会收到以下错误消息:

java: tpp.c:63: __pthread_tpp_change_priority: Assertion `new_prio == -1 || (new_prio >= __sched_fifo_min_prio && new_prio <= __sched_fifo_max_prio)' failed.

大概存在线程问题,也许是竞争条件?奇怪的是,如果我尝试将复合 Material 直接放在外壳上而不是放在选项卡上,它工作正常(或者至少我没有看到它崩溃)。

相关代码如下所示:

tabFolder = new CTabFolder(shell, SWT.BORDER);
tabFolder.setSimple(false);

final Composite composite = new Composite(tabFolder, SWT.NONE);
composite.setLayout(new FillLayout());
new VisualizerCanvas(composite, MeshFactory.loadObj("meshes/teapot_sealed.obj"));
new VisualizerCanvas(composite, MeshFactory.loadObj("meshes/duck.obj"));

final CTabItem item = new CTabItem(tabFolder, SWT.CLOSE);
item.setText("Test");
item.setImage(new Image(display, "img/test.jpg"));
item.setControl(composite);

VisualizerCanvas 构造函数如下所示:

public VisualizerCanvas(Composite parent, Mesh mesh)
{
// Set up the canvas
GLProfile glProfile = GLProfile.getDefault();
GLCapabilities glCapabilities = new GLCapabilities(glProfile);
glCapabilities.setDoubleBuffered(true);
glCapabilities.setHardwareAccelerated(true);
glCanvas = new GLCanvas(glCapabilities);
glCanvas.addGLEventListener(this);

// Create the embedded AWT frame using the SWT/AWT bridge
Composite composite = new Composite(parent, SWT.EMBEDDED | SWT.BORDER | SWT.NO_BACKGROUND);
composite.setLayout(new FillLayout());
Frame frame = SWT_AWT.new_Frame(composite);
frame.add(glCanvas);

// Add an animator to automatically update the canvas at 30fps
animator = new FPSAnimator(glCanvas, 30);
animator.add(glCanvas);
animator.start();

this.mesh = MeshFactory.normalizeMesh(mesh);
}

我是否使用 SWT 小部件/复合 Material 做了一些不应该做的事情?

最佳答案

终于自己解决了这个问题。事实证明这确实是一个竞争条件 - 我正在 Linux 上的 Eclipse 中进行开发,我需要以下代码来防止 Linux 窗口事件丢失:

static {
GLProfile.initSingleton(false);
}

我已经将其放入我的 VisualizerCanvas 类中,但未放入我的 Visualizer 类中(第一段代码)。据推测,GLProfileVisualizerCanvas 正在争夺 JVM 加载的机会,GLProfile 有时会获胜,从而导致崩溃。

关于java - 将 SWT 与 JOGL 结合使用时随机崩溃(竞争条件?),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6738017/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com