we are facing a crash in lazy column which is excl...
# compose
k
we are facing a crash in lazy column which is exclusively happening on one plus and oppo devices which is happening due to some fling behaviour, there seems to be a google issue too for the same.. anyone found a workaround for it?
Copy code
Fatal Exception: java.lang.ArrayIndexOutOfBoundsException: length=101; index=-12
    at androidx.compose.animation.AndroidFlingSpline.flingPosition(SplineBasedDecay.kt:96)
    at androidx.compose.animation.FlingCalculator$FlingInfo.position(FlingCalculator.java:120)
    at androidx.compose.animation.SplineBasedFloatDecayAnimationSpec.getValueFromNanos(SplineBasedFloatDecayAnimationSpec.kt:51)
    at androidx.compose.animation.core.VectorizedFloatDecaySpec.getValueFromNanos(VectorizedFloatDecaySpec.java:144)
    at androidx.compose.animation.core.DecayAnimation.getValueFromNanos(Animation.kt:401)
Screenshot 2024-01-05 at 8.33.59 PM.png
d
If you have a reliable repro, that'll be helpful for our investigation. If you could reproduce the crash at all, even if not reliably, I'd recommend trying out the suggestion in comment #5 of the google issue to help confirm the potential cause.
k
Copy code
LaunchedEffect(key1 = Unit, block = {
    var lastFrameTime = 0L
    withFrameNanos { frameTimeNanos ->
        if (frameTimeNanos < lastFrameTime) {
            Timber.tag("compose_debug").v("last_frame_time: $lastFrameTime : current_frame_time: $frameTimeNanos : decreasing frame time")
        }

        lastFrameTime = frameTimeNanos
    }
})
something like this would work @Doris Liu?
d
We'll need a while-loop around
withFrameNanos
so that we can inspect consecutive frame callbacks during the animation. With that said, you might also want to time bound the while loop so that frame callbacks are only requested as needed (i.e. during the fling animation).
k
thank you. got it. but do we get any callback for fling? should we log this in when scroll is in progress? 🤔
d
should we log this in when scroll is in progress?
Logging based on
isScrollInProgress
might be the easier way to do it. The
LaunchedEffect
could key on it so the job gets canceled when scrolling finishes, like:
Copy code
LaunchedEffect(state.isScrollInProgress) {
   if (state.isScrollInProgress) { // while-loop goes here }
}
👍 1