JVM使用JOGL,顶点缓冲区对象崩溃,并尝试在finalize方法中释放vbo [英] JVM crashes using JOGL, vertex buffer objects, and trying to free the vbo in a finalize method

查看:115
本文介绍了JVM使用JOGL,顶点缓冲区对象崩溃,并尝试在finalize方法中释放vbo的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些我写的CAD软件。绘制的每个组件都有一组顶点缓冲区对象。如果组件被删除,我必须释放finalize方法中的顶点缓冲区对象,例如:

  if(gl!= null){
Integer [] keys = vbos.keySet()。toArray(new Integer [0]);
for(int i = 0; i< keys.length; i ++){
Integer tmp = keys [i];
if(tmp!= null){
if(gl.glIsBufferARB(tmp.intValue()));
gl.glDeteteBuffersARB(1,new int [] {tmp.intValue()},0);
}
}
}

但是我有时会得到一个SIGSEV和JVM崩溃。 hs_err日志文件指向gl.glIsBufferArb(tmp.intValue())。



我相信这意味着我的gl对象不再有效吗?

它应该仍然有效我认为。该方案仍在运行直到崩溃。有没有一种方法可以在没有存储对GL对象的引用的情况下释放glbuffer?

谢谢!

解决方案

你要在这里遇到的最明显的问题是,一个OpenGL上下文只能在它所活动的线程中被引用。一般来说,这将是你的渲染线程,意味着OpenGL上下文在JVM的终结器线程中将不可用。对我而言,这似乎是你错误的最可能原因。我建议你保留一个全球无效的维也纳国际组织的清单,并将finalize方法添加到该清单中。然后,您可以定期从渲染线程处理该列表,从而实际删除VBO,从而实现OpenGL调用。



您可以在多行显示中快速了解OpenGL的行为线程环境此处


I have some CAD software I've written. Each component being drawn has a set of vertex buffer objects. If the component gets deleted, I have to free the vertex buffer objects in the finalize method such as:

    if (gl != null) {
        Integer[] keys = vbos.keySet().toArray(new Integer[0]);
        for (int i = 0; i < keys.length; i++) {
            Integer tmp = keys[i];
            if (tmp != null) {
                if (gl.glIsBufferARB(tmp.intValue()));
                gl.glDeleteBuffersARB(1, new int[]{tmp.intValue()}, 0);
            }
        }
    }

however I sometimes get a SIGSEV and JVM crash. The hs_err log file points to gl.glIsBufferArb(tmp.intValue()).

I believe this means my gl object is no longer valid?

It should have been still valid I think. The program was still operating up until the crash. Is there a way to free a glbuffer without having stored a reference to the GL object?

Thank you!

解决方案

The most obvious issue you're going to run into here is that an OpenGL context can only be referenced in the thread it is active in. Generally speaking this will be your rendering thread, which means that the OpenGL context will not be available in the JVM's finalizer thread. That, to me, seems the most likely cause of your errors. I would recommend that you keep a global list of invalidated VBOs, and have the finalize method add ids to that list. You can then process that list periodically from your rendering threads, making the OpenGL calls necessary to actually delete the VBOs.

You can find a quick rundown on OpenGL's behavior in a multi-threaded environment here.

这篇关于JVM使用JOGL,顶点缓冲区对象崩溃,并尝试在finalize方法中释放vbo的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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