From 0a8be0d09dfda8f6a86e5f7a97ecb0814f12095f Mon Sep 17 00:00:00 2001 From: MediaPipe Team Date: Mon, 1 May 2023 18:38:20 -0700 Subject: [PATCH] Internal change PiperOrigin-RevId: 528632873 --- .../framework/jni/graph_texture_frame_jni.cc | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/mediapipe/java/com/google/mediapipe/framework/jni/graph_texture_frame_jni.cc b/mediapipe/java/com/google/mediapipe/framework/jni/graph_texture_frame_jni.cc index dd99cccd4..b3bcd14dd 100644 --- a/mediapipe/java/com/google/mediapipe/framework/jni/graph_texture_frame_jni.cc +++ b/mediapipe/java/com/google/mediapipe/framework/jni/graph_texture_frame_jni.cc @@ -14,6 +14,7 @@ #include "mediapipe/java/com/google/mediapipe/framework/jni/graph_texture_frame_jni.h" +#include "absl/strings/str_format.h" #include "mediapipe/gpu/gl_calculator_helper.h" #include "mediapipe/gpu/gl_context.h" #include "mediapipe/gpu/gl_texture_buffer.h" @@ -89,9 +90,20 @@ JNIEXPORT jlong JNICALL GRAPH_TEXTURE_FRAME_METHOD( JNIEXPORT void JNICALL GRAPH_TEXTURE_FRAME_METHOD(nativeDidRead)( JNIEnv* env, jobject thiz, jlong nativeHandle, jlong consumerSyncToken) { + if (!consumerSyncToken) return; + GlTextureBufferSharedPtr* buffer = reinterpret_cast(nativeHandle); mediapipe::GlSyncToken& token = *reinterpret_cast(consumerSyncToken); + // The below check attempts to detect when an invalid or already deleted + // `consumerSyncToken` is passed. (That results in undefined behavior. + // However, `DidRead` may succeed resulting in a later crash and masking the + // actual problem.) + if (token.use_count() == 0) { + LOG_FIRST_N(ERROR, 5) << absl::StrFormat("invalid sync token ref: %d", + consumerSyncToken); + return; + } (*buffer)->DidRead(token); }