You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Rare crash "Cannot round NaN value" in SeekableTransitionState when predictive back gesture finishes #1012
We're seeing a rare production crash (4 events / 3 users over ~2 months, so far only Huawei/Honor devices: PTP-N49, PTP-AN00, BRP-NX3) when a predictive back gesture completes on a ChildStack using the experimental stackAnimation with a custom PredictiveBackAnimatable:
java.lang.IllegalArgumentException: Cannot round NaN value.
at kotlin.math.MathKt__MathJVMKt.roundToLong(MathJVM.kt:741)
at androidx.compose.animation.core.SeekableTransitionState.seekToFraction(Transition.kt:733)
at androidx.compose.animation.core.SeekableTransitionState.animateOneFrameLambda$lambda$0(Transition.kt:325)
at androidx.compose.runtime.BroadcastFrameClock$FrameAwaiter.resume(BroadcastFrameClock.kt:56)
at androidx.compose.runtime.BroadcastFrameClock.sendFrame$lambda$0(BroadcastFrameClock.java:71)
at androidx.compose.runtime.AwaiterQueue.flushAndDispatchAwaiters(AwaiterQueue.kt:89)
at androidx.compose.runtime.BroadcastFrameClock.sendFrame(BroadcastFrameClock.java:71)
at androidx.compose.runtime.Recomposer$runRecomposeAndApplyChanges$2$2.invokeSuspend$lambda$2(Recomposer.kt:633)
...
It looks like a Compose bug, I've reported it here but Decompose could avoid triggering it: when a custom PredictiveBackAnimatable is used, the seekable transition states are known to have zero total duration, so finish() could snapTo() (or skip the animateTo()) instead of animating zero-duration transitions — which would also sidestep the crash on current Compose versions.
@arkivanov On it — I'm investigating the Cannot round NaN value crash in SeekableTransitionState (Decompose + animation-core sources) and will try to reproduce it. I'll follow up here with findings and a PR if I find a safe fix.
Root cause (SeekableTransitionState; the code is identical in animation-core 1.9.4 and 1.11.4, and the line numbers are from 1.11.4)
animateTo() sets animationSpecDuration = totalDurationNanos * (1 - fraction). That's 0 when the transition has zero total duration.
animateOneFrameLambda (L303) computes deltaPlayTimeNanos = (frameTime - lastFrameTime) / durationScale. Then recalculateAnimationValue (L398) does if (playTime >= duration) 1f else lerp(start, 1f, playTime.toFloat() / duration). With duration == 0 and a negative play time, that's lerp(0, 1, -Inf), which is NaN. seekToFraction() (L733) then throws Cannot round NaN value.
So two things have to happen together: (1) a zero-duration transition, and (2) a frame time lower than the one captured on the previous frame.
(1) happens in Decompose when a custom PredictiveBackAnimatable is used. SimpleStackAnimator doesn't add animations to the transition, so unless the content has its own transition animations, AnimationHandler.finish() calls animateTo() on zero-duration states.
(2) is the device-specific part. My best guess is a vendor-modified Choreographer on Huawei/Honor (AOSP skips frames whose time goes backwards), but I haven't confirmed that.
Reproduced: yes, on JVM. I didn't have a device. A test runs the full DefaultStackAnimation predictive back flow with a custom PredictiveBackAnimatable in ImageComposeScene and makes the frame time go backwards after back(). It crashes every time with the same exception and a matching stack trace (Recomposer → BroadcastFrameClock.sendFrame → animateOneFrameLambda → seekToFraction), and the stack is never popped. It doesn't crash when frame times are monotonic, or when the content has a transition animation (non-zero duration).
Fix (#1022):finish() now runs the two animateTo() calls with a MonotonicFrameClock wrapper that never reports a frame time lower than one it already reported. When frame times are already monotonic, nothing changes. I didn't go with the snapTo() suggestion: StackAnimationScope is an AnimatedVisibilityScope, so content can have transition animations (animateFloat, animateEnterExit, shared elements) whose duration isn't known until the new target state has been composed. Snapping based on duration could skip real animations. The new regression test fails without the fix and passes with it. All 276 module JVM tests pass, and the Android, JS and Wasm targets compile and pass apiCheck. This hasn't been verified on an affected Huawei/Honor device.
Activity
arkivanov commentedon Jul 31, 2026
Thank you. I will take a look.
arkivanov commentedon Aug 9, 2026
@PhilipDukhov could you please elaborate? How can Decompose help avoid the crash? Can you point to line of code?
arkivanov commentedon Sep 26, 2026
@arkivanov-bot please investigate this issue, try to reproduce and fix the crash.
arkivanov-bot commentedon Sep 26, 2026
@arkivanov On it — I'm investigating the
Cannot round NaN valuecrash inSeekableTransitionState(Decompose + animation-core sources) and will try to reproduce it. I'll follow up here with findings and a PR if I find a safe fix.arkivanov-bot commentedon Sep 26, 2026
@arkivanov Here's what I found. I've opened a fix in #1022.
Root cause (
SeekableTransitionState; the code is identical in animation-core 1.9.4 and 1.11.4, and the line numbers are from 1.11.4)animateTo()setsanimationSpecDuration = totalDurationNanos * (1 - fraction). That's0when the transition has zero total duration.animateOneFrameLambda(L303) computesdeltaPlayTimeNanos = (frameTime - lastFrameTime) / durationScale. ThenrecalculateAnimationValue(L398) doesif (playTime >= duration) 1f else lerp(start, 1f, playTime.toFloat() / duration). Withduration == 0and a negative play time, that'slerp(0, 1, -Inf), which isNaN.seekToFraction()(L733) then throwsCannot round NaN value.PredictiveBackAnimatableis used.SimpleStackAnimatordoesn't add animations to the transition, so unless the content has its own transition animations,AnimationHandler.finish()callsanimateTo()on zero-duration states.Choreographeron Huawei/Honor (AOSP skips frames whose time goes backwards), but I haven't confirmed that.Reproduced: yes, on JVM. I didn't have a device. A test runs the full
DefaultStackAnimationpredictive back flow with a customPredictiveBackAnimatableinImageComposeSceneand makes the frame time go backwards afterback(). It crashes every time with the same exception and a matching stack trace (Recomposer→BroadcastFrameClock.sendFrame→animateOneFrameLambda→seekToFraction), and the stack is never popped. It doesn't crash when frame times are monotonic, or when the content has a transition animation (non-zero duration).Fix (#1022):
finish()now runs the twoanimateTo()calls with aMonotonicFrameClockwrapper that never reports a frame time lower than one it already reported. When frame times are already monotonic, nothing changes. I didn't go with thesnapTo()suggestion:StackAnimationScopeis anAnimatedVisibilityScope, so content can have transition animations (animateFloat,animateEnterExit, shared elements) whose duration isn't known until the new target state has been composed. Snapping based on duration could skip real animations. The new regression test fails without the fix and passes with it. All 276 module JVM tests pass, and the Android, JS and Wasm targets compile and passapiCheck. This hasn't been verified on an affected Huawei/Honor device.arkivanov commentedon Sep 26, 2026
The reported bug (https://issuetracker.google.com/issues/540477169) was marked as a duplicate of https://issuetracker.google.com/issues/555294641, which was marked as fixed. The actual fix seem to be this: https://android-review.googlesource.com/c/platform/frameworks/support/+/4276642. Closing this issue now. The crash should go away after the Compose fix is released.