From 123cbf06e7512baea7a4e48b3736d18cdfb040b9 Mon Sep 17 00:00:00 2001 From: PJ Date: Fri, 17 Apr 2026 23:39:11 +0700 Subject: [PATCH] fix(sdk-android): post frame callbacks via main looper Choreographer.getInstance() is per-thread and throws on threads without a Looper. The previous impl called it from the SocketClient reader thread, which surfaced as snapshot failures with empty state during the sample-app round trip. Now the reader thread posts a Runnable to the main Handler that, on the main thread, gets the Choreographer and posts the frame callback. --- .../src/main/kotlin/dev/uatu/sdk/ChoreographerPoster.kt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/sdk/android/src/main/kotlin/dev/uatu/sdk/ChoreographerPoster.kt b/sdk/android/src/main/kotlin/dev/uatu/sdk/ChoreographerPoster.kt index 87b1700..f05eb69 100644 --- a/sdk/android/src/main/kotlin/dev/uatu/sdk/ChoreographerPoster.kt +++ b/sdk/android/src/main/kotlin/dev/uatu/sdk/ChoreographerPoster.kt @@ -1,9 +1,15 @@ package dev.uatu.sdk +import android.os.Handler +import android.os.Looper import android.view.Choreographer class ChoreographerPoster : FrameCallbackPoster { + private val mainHandler = Handler(Looper.getMainLooper()) + override fun postFrameCallback(callback: () -> Unit) { - Choreographer.getInstance().postFrameCallback { callback() } + mainHandler.post { + Choreographer.getInstance().postFrameCallback { callback() } + } } }