diff --git a/mediapipe/java/com/google/mediapipe/framework/GraphTextureFrame.java b/mediapipe/java/com/google/mediapipe/framework/GraphTextureFrame.java index 6a2c97b94..a253a8289 100644 --- a/mediapipe/java/com/google/mediapipe/framework/GraphTextureFrame.java +++ b/mediapipe/java/com/google/mediapipe/framework/GraphTextureFrame.java @@ -66,7 +66,8 @@ public class GraphTextureFrame implements TextureFrame { if (nativeBufferHandle == 0) { return 0; } - if (activeConsumerContextHandleSet.add(nativeGetCurrentExternalContextHandle())) { + long contextHandle = nativeGetCurrentExternalContextHandle(); + if (contextHandle != 0 && activeConsumerContextHandleSet.add(contextHandle)) { // Gpu wait only if deferredSync is true, such as when this GraphTextureFrame is created using // PacketGetter.getTextureFrameDeferredSync(). if (deferredSync) { @@ -116,7 +117,14 @@ public class GraphTextureFrame implements TextureFrame { GlSyncToken consumerToken = null; // Note that this remove should be moved to the other overload of release when b/68808951 is // addressed. - if (activeConsumerContextHandleSet.remove(nativeGetCurrentExternalContextHandle())) { + final long contextHandle = nativeGetCurrentExternalContextHandle(); + if (contextHandle == 0 && !activeConsumerContextHandleSet.isEmpty()) { + logger.atWarning().log( + "GraphTextureFrame is being released on non GL thread while having active consumers," + + " which may lead to external / internal GL contexts synchronization issues."); + } + + if (contextHandle != 0 && activeConsumerContextHandleSet.remove(contextHandle)) { consumerToken = new GraphGlSyncToken(nativeCreateSyncTokenForCurrentExternalContext(nativeBufferHandle)); } @@ -169,7 +177,9 @@ public class GraphTextureFrame implements TextureFrame { private native void nativeReleaseBuffer(long nativeHandle); private native int nativeGetTextureName(long nativeHandle); + private native int nativeGetWidth(long nativeHandle); + private native int nativeGetHeight(long nativeHandle); private native void nativeGpuWait(long nativeHandle);