saket / telephoto

Building blocks for designing media experiences in Compose UI
https://saket.github.io/telephoto/
Apache License 2.0
998 stars 33 forks source link

Crash: IllegalStateException Invalid velocity = (NaN, NaN) px/sec #97

Closed SimonMarquis closed 2 months ago

SimonMarquis commented 3 months ago

This crash (2,038 crash events affecting 1,235 users) is very similar to this issue that was fixed:

The difference is in the values (±Infinity vs NaN).

It is happening in versions 0.11.2 and 0.12.0 (0.12.1 was not tested), no specific Android version or manufacturer.

saket commented 3 months ago

Huh. Can you share the full stacktrace?

SimonMarquis commented 3 months ago
me.saket.telephoto.zoomable.RealZoomableState.fling-BMRW4eQ$zoomable_release (RealZoomableState.java:152)
me.saket.telephoto.zoomable.ZoomableNode$onTransformStopped$1$1.invokeSuspend (Zoomable.kt:152)
kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith (ContinuationImpl.kt:9)
kotlinx.coroutines.DispatchedTask.run (DispatchedTask.kt:93)
androidx.compose.ui.platform.AndroidUiDispatcher.performTrampolineDispatch (AndroidUiDispatcher.android.kt:15)
androidx.compose.ui.platform.AndroidUiDispatcher.access$performTrampolineDispatch (AndroidUiDispatcher.android.kt:15)
androidx.compose.ui.platform.AndroidUiDispatcher$dispatchCallback$1.run (AndroidUiDispatcher.android.kt:3)
android.os.Handler.handleCallback (Handler.java:907)
android.os.Handler.dispatchMessage (Handler.java:105)
android.os.Looper.loop (Looper.java:216)
android.app.ActivityThread.main (ActivityThread.java:7625)
java.lang.reflect.Method.invoke (Method.java)
com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:524)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:987)
irinamankov commented 2 months ago

We also experience this bug in our project, but I have some additional info:

  1. Firstly we had compose-ui:1.6.4 and telephoto:0.7.1 and everything was fine
  2. Then we updated compose-ui up to 1.7.0-beta01 and started to receive this crash
  3. Finally, we decided to rollback compose-ui to 1.6.4 and update telephoto to 1.12.1 and crashes stopped to occur.

I was able to reproduce crash by zooming and tapping for a long time, but it is very difficult to catch. But users experienced it quite often.

So, in my case the reason was in 1.7.0 compose-ui version. I compared VelocityTracker's source code and saw that it was the same in 1.6.4-1.6.8 versions, but changed in 1.7.0, so may be problem is here

SimonMarquis commented 2 months ago

I was wondering if we could try to detect (and drop) invalid Velocity earlier and not send them to prevent crashes in consumer code?

https://github.com/saket/telephoto/blob/9bab84a2dff94fa70bfcb4f4d0f3fb7262bd2ee6/zoomable/src/commonMain/kotlin/me/saket/telephoto/zoomable/internal/transformable.kt#L157-L161

saket commented 2 months ago

Yep let's do that. VelocityTracker#calculateVelocity() only protects from large values, but not NaN.

saket commented 1 week ago

0.14.0 is out with a fix: https://github.com/saket/telephoto/releases/tag/0.14.0