Skip to content

Prevent frame-time regressions from crashing scene transitions - #228

Merged
isaac-udy merged 1 commit into
isaac-udy:mainfrom
dan-gamelocker:fix/non-monotonic-frame-time-nan
Oct 1, 2026
Merged

isaac-udy merged 1 commit into
isaac-udy:mainfrom
dan-gamelocker:fix/non-monotonic-frame-time-nan

Conversation

@dan-gamelocker

Copy link
Copy Markdown
Contributor

Crash

Fatal on Android, reported through Crashlytics from production Game Locker builds:

java.lang.IllegalArgumentException: Cannot round NaN value.
    at kotlin.math.MathKt__MathJVMKt.roundToLong(MathKt__MathJVM.kt:741)
    at androidx.compose.animation.core.SeekableTransitionState.seekToFraction(Transition.kt:733)
    at androidx.compose.animation.core.SeekableTransitionState.animateOneFrameLambda$lambda$0(SeekableTransitionState.java:325)
    at androidx.compose.runtime.BroadcastFrameClock$FrameAwaiter.resume(BroadcastFrameClock.java:56)
    ...

Root cause

Some devices (observed in the wild on Huawei and Honor) occasionally deliver a Choreographer frame time earlier than the previous frame's. SeekableTransitionState doesn't tolerate that: while animating a transition whose total duration is zero β€” a scene change with no enter/exit animations β€” the negative frame delta feeds lerp(0f, 1f, -Infinity)-style math, the internal fraction becomes NaN, and the next seekToFraction() throws Cannot round NaN value. In NavigationDisplay this fires when a predictive-back gesture settles (the animateTo after the gesture completes or cancels).

This is the same crash Decompose diagnosed and fixed in arkivanov/Decompose#1022 (report: arkivanov/Decompose#1012); the underlying androidx report is issuetracker.google.com/issues/540477169. No released compose-animation version guards against it (checked 1.12.0 β€” seekToFraction is unchanged).

Fix

NavigationDisplay now drives its SeekableTransitionState through a small NonDecreasingFrameTime guard: a MonotonicFrameClock wrapper that clamps frame times to be non-decreasing before they reach the animation. A single instance is shared across all three drive sites (the predictive-back seekTo, the animateTo, and the settle seekTo/snapTo), so a regression across a phase boundary β€” e.g. a predictive-back seek handing over to the settle animation, which is where the zero-duration animateTo runs β€” is caught too. On well-behaved devices the clock is a pass-through.

Tests

NonDecreasingFrameTimeTests (commonTest, passing on desktop): monotonic times pass through unchanged; a regression is clamped to the last seen frame time; the clamp is shared across separate invocations; and the guard degrades to a plain coroutineScope when no frame clock is in the context.

Note: :enro-runtime:linkDebugFrameworkIosArm64 currently fails on main with Shouldn't be exposed: deserialized class MetadataKey β€” pre-existing (reproduced on a clean checkout of 4876fb3), unrelated to this change. Kotlin/Native klib compilation for iOS passes with this change.

πŸ€– Generated with Claude Code

Some devices (observed on Huawei and Honor) occasionally deliver a
Choreographer frame time earlier than the previous frame's.
SeekableTransitionState does not tolerate this: while animating a
transition whose total duration is zero (a scene change with no
enter/exit animations), the negative frame delta produces a NaN
fraction and the next seek crashes with
"IllegalArgumentException: Cannot round NaN value" from
SeekableTransitionState.seekToFraction. In NavigationDisplay this
fires when a predictive-back gesture settles.

NavigationDisplay now drives its SeekableTransitionState through a
NonDecreasingFrameTime guard: a MonotonicFrameClock wrapper that clamps
frame times to be non-decreasing. One instance is shared across the
seek, animate and settle phases, so a regression across a phase
boundary (a predictive-back seek handing over to the settle animation)
is caught too.

Same class of fix as arkivanov/Decompose#1022 for the identical crash;
upstream report: https://issuetracker.google.com/issues/540477169

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@isaac-udy
isaac-udy merged commit 326239c into isaac-udy:main Oct 1, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants