Skip to content

Rare crash "Cannot round NaN value" in SeekableTransitionState when predictive back gesture finishes #1012

Closed as not planned

Description

@PhilipDukhov

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)
    ...

Versions

  • Decompose: 3.5.0 (extensions-compose-experimental)
  • Compose BOM 2026.06.01 (animation-core 1.11.4)
  • Setup: stackAnimation(predictiveBackParams = { PredictiveBackParams(backHandler, onBack, animatable = { materialPredictiveBackAnimatable(it) /* custom fork */ }) })

Analysis

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.

Activity

  1. arkivanov commented on Jul 31, 2026

    @arkivanov
    Owner

    Thank you. I will take a look.

  2. added
    bug
    not decompose
    on Jul 31, 2026
  3. arkivanov commented on Aug 9, 2026

    @arkivanov
    Owner

    Decompose could avoid triggering it

    @PhilipDukhov could you please elaborate? How can Decompose help avoid the crash? Can you point to line of code?

  4. arkivanov commented on Sep 26, 2026

    @arkivanov
    Owner

    @arkivanov-bot please investigate this issue, try to reproduce and fix the crash.

  5. arkivanov-bot commented on Sep 26, 2026

    @arkivanov-bot
    Collaborator

    @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.

  6. arkivanov-bot commented on Sep 26, 2026

    @arkivanov-bot
    Collaborator

    @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() 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.

  7. arkivanov commented on Sep 26, 2026

    @arkivanov
    Owner

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugnot decompose

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions