JVM crashes using JOGL, vertex buffer objects, and trying to free the vbo in a finalize method

北慕城南 提交于 2019-12-11 06:45:47

问题


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!


回答1:


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.



来源:https://stackoverflow.com/questions/8406612/jvm-crashes-using-jogl-vertex-buffer-objects-and-trying-to-free-the-vbo-in-a-f

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!