- Home /
No OpenGL Context in Unity above 2017.1.2f1
Hi!
I am working on Android plugin which should load textures natively in OpenGL from Java code. I know that whole this OpenGL context thing is tricky. This is Java code:
public static int Load(byte[] textureData)
{
final int[] textureHandle = new int[1];
GLES30.glGenTextures(1, textureHandle, 0);
if (textureHandle[0] != 0)
{
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inScaled = false; // No pre-scaling
// Read in the resource
final Bitmap bitmap = BitmapFactory.decodeByteArray(textureData, 0, textureData.length, options);
// Bind to the texture in OpenGL
GLES30.glBindTexture(GLES30.GL_TEXTURE_2D, textureHandle[0]);
// Set filtering
GLES30.glTexParameteri(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_MIN_FILTER, GLES30.GL_NEAREST);
GLES30.glTexParameteri(GLES30.GL_TEXTURE_2D, GLES30.GL_TEXTURE_MAG_FILTER, GLES30.GL_NEAREST);
// Load the bitmap into the bound texture.
GLUtils.texImage2D(GLES30.GL_TEXTURE_2D, 0, bitmap, 0);
// Recycle the bitmap, since its data has been loaded into OpenGL.
bitmap.recycle();
}
if (textureHandle[0] == 0)
{
throw new RuntimeException("Error loading texture.");
}
return textureHandle[0];
}
If it's called from e.g button onclick event it will throw an exception :
call to OpenGL ES API with no current context (logged once per thread)
After some googling I found a way to fix that. When calling my Java code from MonoBehaviour.OnRenderObject it works perfectly fine. Texture is being loaded, everyone is happy. I made such sample program in Unity 2017.1.2f1
Then, when I updated to 2017.2.0f3 it throws
again, even though I haven't made any changes and Java code is still called from MonoBehaviour.OnRenderObject . I tried to update to 2017.3 beta but it also throws an exception... Any ideas what changed? I'm kind of blocked now. I found no information about changes that might cause that in release notes.call to OpenGL ES API with no current context (logged once per thread)
Comment