From 4480fbf787e7b2de91b48efd6019e80b57148a7b Mon Sep 17 00:00:00 2001 From: 21pages Date: Wed, 1 Nov 2023 16:07:45 +0800 Subject: [PATCH] Revert "fix android ci, replace use with try-finally" This reverts commit dfe96eb30c4dfd34c424c0c297e672a8aca4904a. --- .../main/kotlin/com/carriez/flutter_hbb/MainService.kt | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/flutter/android/app/src/main/kotlin/com/carriez/flutter_hbb/MainService.kt b/flutter/android/app/src/main/kotlin/com/carriez/flutter_hbb/MainService.kt index 51a72b41a..535a3f8c3 100644 --- a/flutter/android/app/src/main/kotlin/com/carriez/flutter_hbb/MainService.kt +++ b/flutter/android/app/src/main/kotlin/com/carriez/flutter_hbb/MainService.kt @@ -349,17 +349,12 @@ class MainService : Service() { ).apply { setOnImageAvailableListener({ imageReader: ImageReader -> try { - // https://stackoverflow.com/questions/35136715/try-with-resources-use-extension-function-in-kotlin-does-not-always-work - // https://stackoverflow.com/questions/72537045/kotlin-use-with-autocloseable-type-and-a-lambda-returning-boolean - val image = imageReader.acquireLatestImage() - if (image == null) return@setOnImageAvailableListener - try { + imageReader.acquireLatestImage().use { image -> + if (image == null) return@setOnImageAvailableListener val planes = image.planes val buffer = planes[0].buffer buffer.rewind() onVideoFrameUpdate(buffer) - } finally { - image.close() } } catch (ignored: java.lang.Exception) { }