Hi,
I’m working on a project where I need to get working a program that “outputs” a texture via OpenGL with a Unity-based app that uses this texture on a solid 2D plane.
So I created a low level native plugin in C++ as explained in the manual, in this plugin there’s a setup function that create a OpenGL context (GLX since I’m on Linux), and declare the GLX context of Unity as “shared” (3rd argument of glXCreateContext) this way :
unityGLContext = glXGetCurrentContext();
display = glXGetCurrentDisplay();
// Create a helper OpenGL context
int scrnum = DefaultScreen (display);
int attrib[] = { GLX_RGBA,
GLX_RED_SIZE, 1,
GLX_GREEN_SIZE, 1,
GLX_BLUE_SIZE, 1,
GLX_DOUBLEBUFFER };
XVisualInfo* visinfo = glXChooseVisual (display, scrnum, attrib);
// Create a context with unityGLContext as shared lists
helperGLContext = glXCreateContext(display, visinfo, unityGLContext, true);
Later in my plugin, I use my helper GL context to do stuff, and render to a Unity’s texture with the ID of the texture (that I obtained with GetNativeTexturePtr()), it is possible because my helper GL context is created as “shared” with Unity OpenGL context.
And it works perfectly ! But only in the Editor…
When I try to compile and run the app, the Player crashes during the setup of my native plugin, and more precisely, it crashes at this line :
XVisualInfo* visinfo = glXChooseVisual (display, scrnum, attrib);
The stacktrace in the log file shows :
in my experience, an error with “Receiving unhandled NULL exception #0 0x007ffdebddf440 in funlockfile” happens when some blocking actions are made in the native plugin, Unity seem to dislike it, but here it works in the editor mode…
So, I don’t understand why it works perfectly on the Editor, but not with the Player
Do you have any clues for me ?
I’m using Unity 2017.1.0xf1 Linux Personal.
Thanks