library: a throwing render-thread frame still answers the loop (#maprender)
- Commit
ca750d06e31ad19093641731dda530a350ba7be6- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-13 20:45 UTC (22 days ago)
- Parents
0fa011f
Follow-up to the render-thread move. The main thread's frame loop dispatches one frame at a time and waits for its answer (frameInFlight). MapRenderThread.post catches a throwing task so the thread survives, but a frame that threw never posted its result, which would leave frameInFlight set and the map frozen for the rest of the surface's life. MapNativeLink.frame now catches around drawFrame, logs, and answers FrameResult.NONE (not drawn), so the loop asks again on the next vsync exactly as for a skipped frame. On the main thread the same throw used to crash the app; now it costs a frame.
Diff
library/map/src/main/java/com/vayunmathur/library/map/MapNativeLink.kt
diff --git a/library/map/src/main/java/com/vayunmathur/library/map/MapNativeLink.kt b/library/map/src/main/java/com/vayunmathur/library/map/MapNativeLink.ktindex b1a762613d..47871ac29f 100644--- a/library/map/src/main/java/com/vayunmathur/library/map/MapNativeLink.kt+++ b/library/map/src/main/java/com/vayunmathur/library/map/MapNativeLink.kt@@ -136,7 +136,14 @@ internal class MapNativeLink { val issued = generation MapRenderThread.post { val h = nativeHandle- val result = if (h == 0L) FrameResult.NONE else drawFrame(h, snapshot, density, frameTimeNanos, pivotWanted, region)+ // Every dispatched frame must answer, or the main thread's loop waits on it forever+ // (`frameInFlight`); a throwing frame answers "not drawn" and the loop asks again.+ val result = try {+ if (h == 0L) FrameResult.NONE else drawFrame(h, snapshot, density, frameTimeNanos, pivotWanted, region)+ } catch (t: Throwable) {+ Log.error("MapNativeLink", "native frame threw", t)+ FrameResult.NONE+ } MapRenderThread.toMain { if (issued == generation) onDone(result) } } }