From 42d42a5ea199a20eb9176b712e46078cb737b076 Mon Sep 17 00:00:00 2001 From: MediaPipe Team Date: Fri, 17 Nov 2023 14:44:35 -0800 Subject: [PATCH] Ensure that releaseGl() is called if prepapreGl throws Without this logic, we might have resources created within prepareGl() leaking, since they will never be released. PiperOrigin-RevId: 583491569 --- mediapipe/java/com/google/mediapipe/glutil/GlThread.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mediapipe/java/com/google/mediapipe/glutil/GlThread.java b/mediapipe/java/com/google/mediapipe/glutil/GlThread.java index 24b8ca094..b8d4fa636 100644 --- a/mediapipe/java/com/google/mediapipe/glutil/GlThread.java +++ b/mediapipe/java/com/google/mediapipe/glutil/GlThread.java @@ -128,6 +128,10 @@ public class GlThread extends Thread { prepareGl(); startedSuccessfully = true; + } catch (RuntimeException e) { + releaseGl(); + eglManager.release(); + throw e; } finally { // Always stop waitUntilReady here, even if we got an exception. // Otherwise the main thread may be stuck waiting.