Unity IllegalStateException Unable to update texture contents

Viewed 25

I am trying to display a native view on top of the Unity object by updating the surface using the Plugin.

I have created the Texture2D in Unity and passed the Native Ptr to Android Plugin. While trying to update SurfaceTexture by calling surfaceTexture.updateTexImage() it is throwing IllegalStateException.

java.lang.IllegalStateException: Unable to update texture contents (see logcat for details)
        at android.graphics.SurfaceTexture.nativeUpdateTexImage(Native Method)
        at android.graphics.SurfaceTexture.updateTexImage(SurfaceTexture.java:249)

In Unity:

var texture = new Texture2D(
                width,
                height,
                TextureFormat.RGBA32,
                false,
                false
            );
#if UNITY_2020_2_OR_NEWER
            texture = Texture2D.CreateExternalTexture(
                width,
                height,
                TextureFormat.RGBA32,
                false,
                false,
                texture.GetNativeTexturePtr()
            );
#endif

In Android Plugin:

private SurfaceTexture surfaceTexture;

private void init(int openGlTexture) {
    surfaceTexture = new SurfaceTexture(openGLTexture); // Pointer received from Unity
}

@Override
public void onFrameAvailable(SurfaceTexture surfaceTexture) {
    renderTexture();
}

private void renderTexture() {
    surfaceTexture.updateTexImage();
}

Should I create the Texture in Native Plugin instead?

0 Answers
Related