Posted by
npryor on
Jul 12, 2018; 1:57am
URL: https://forum.jogamp.org/GLJPanel-Native-crash-when-sharing-context-of-offscreen-drawable-tp4039013.html
Here's my basic problem: I'm trying to share a context between an offscreen drawable (which will be the original drawable) and one or more GLJPanels. After hundreds of attempts of trial-and-errors and reading through the metadata for JOGL, I found a combination and ordering worked for all dozen of the machines I tested it against. And then when I got my new computer, lo and behold it gave a fatal native crash when trying to display the GLPanel. Here's code broken down into the smallest unit I can manage (Kotlin, but should be earily readable for Java users):
fun main( args: Array<String>) {
UIManager.setLookAndFeel( UIManager.getCrossPlatformLookAndFeelClassName())
val frame = JglpanelDemo()
frame.pack()
frame.setSize(100, 100)
frame.isLocationByPlatform = true
frame.isVisible = true
frame.defaultCloseOperation = WindowConstants.EXIT_ON_CLOSE
}
class JglpanelDemo : JFrame() {
init {
val profile = GLProfile.getDefault()
val fact = GLDrawableFactory.getFactory(profile)
val caps = GLCapabilities(profile)
val offscreenDrawable = fact.createOffscreenAutoDrawable(fact.defaultDevice,caps,DefaultGLCapabilitiesChooser(),1, 1)
offscreenDrawable.display()
val gljPanel = GLJPanel()
gljPanel.addGLEventListener(object : GLEventListener {
override fun reshape(drawable: GLAutoDrawable?, x: Int, y: Int, width: Int, height: Int) {}
override fun display(drawable: GLAutoDrawable) {
drawable.context.makeCurrent()
drawable.gl.gL2.glClearBufferfv(GL2.GL_COLOR, 0, FloatBuffer.wrap(floatArrayOf(1f,0f,0f,1f)))
drawable.context.release()
}
override fun init(drawable: GLAutoDrawable) {
// Disassociate default context and assosciate the context from the GLEngine
// (so they can share resources)
val primaryContext = offscreenDrawable.context
val unusedDefaultContext = drawable.context
unusedDefaultContext.makeCurrent()
drawable.setContext(null, true)
val subContext = drawable.createContext(primaryContext)
subContext.makeCurrent()
drawable.setContext(subContext, true)
}
override fun dispose(drawable: GLAutoDrawable?) {}
})
add(gljPanel)
}
}
When run on this machine it crashes at the end of GLJPanel's paintComponent with the relatively unhelpful message:
#
# A fatal error has been detected by the Java Runtime Environment:
#
# EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x000000002827fe80, pid=5556, tid=0x0000000000002b98
#
# JRE version: Java(TM) SE Runtime Environment (8.0_171-b11) (build 1.8.0_171-b11)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (25.171-b11 mixed mode windows-amd64 compressed oops)
# Problematic frame:
# C 0x000000002827fe80
#
# Failed to write core dump. Minidumps are not enabled by default on client versions of Windows
#
# An error report file with more information is saved as:
# C:\Documents\Programming\Kotlin\_Spirite\hs_err_pid5556.log
#
# If you would like to submit a bug report, please visit:
#
http://bugreport.java.com/bugreport/crash.jsp# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#
So Question #1 is how to get it to not crash.
Question #2 is: does there exist a tutorial / documentation explaining how to use contexts and shared contexts, when to create, when to makeCurrent, release, etc? I've done my best to piece together a working understanding from of metadata comments and other people's error questions, but judging by the sheer amount of device-dependent behavior I am encountering I clearly do not understand very well despite attempts to.