https://kotlinlang.org logo
Title
m

Manideep Polireddi

05/10/2022, 5:52 AM
We are getting a crash due to illegal state read.
java.lang.IllegalStateException: Reading a state that was created after the snapshot was taken or in a snapshot that has not yet been applied
But we are not able to figure out which part of our source is causing this problem since all of the stacktrace points to android framework, compose runtime and animation library. Full stacktrace in the 🧵 Note: the crash is intermittent and we are able to reproduce it a few times, when the app is changing orientation from landscape back to portrait. Can anyone help us figure out how we can get to the root cause for this crash?
:plus-one: 3
Full Stacktrace:
AndroidRuntime: FATAL EXCEPTION: main
AndroidRuntime: Process: com.disneyplus.mea, PID: 17381
AndroidRuntime: java.lang.IllegalStateException: Reading a state that was created after the snapshot was taken or in a snapshot that has not yet been applied
AndroidRuntime: 	at androidx.compose.runtime.snapshots.SnapshotKt.readError(Snapshot.kt:1646)
AndroidRuntime: 	at androidx.compose.runtime.snapshots.SnapshotKt.readable(Snapshot.kt:1641)
AndroidRuntime: 	at androidx.compose.runtime.snapshots.SnapshotKt.readable(Snapshot.kt:1632)
AndroidRuntime: 	at androidx.compose.runtime.SnapshotMutableStateImpl.getValue(SnapshotState.kt:130)
AndroidRuntime: 	at androidx.compose.animation.core.AnimationScope.isRunning(AnimationState.kt:337)
AndroidRuntime: 	at androidx.compose.animation.core.SuspendAnimationKt.animate(SuspendAnimation.kt:260)
AndroidRuntime: 	at androidx.compose.animation.core.SuspendAnimationKt$animate$4.invokeSuspend(Unknown Source:17)
AndroidRuntime: 	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
AndroidRuntime: 	at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
AndroidRuntime: 	at androidx.compose.ui.platform.AndroidUiDispatcher.performTrampolineDispatch(AndroidUiDispatcher.android.kt:81)
AndroidRuntime: 	at androidx.compose.ui.platform.AndroidUiDispatcher.access$performTrampolineDispatch(AndroidUiDispatcher.android.kt:41)
AndroidRuntime: 	at androidx.compose.ui.platform.AndroidUiDispatcher$dispatchCallback$1.doFrame(AndroidUiDispatcher.android.kt:68)
AndroidRuntime: 	at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1278)
AndroidRuntime: 	at android.view.Choreographer.doCallbacks(Choreographer.java:1019)
AndroidRuntime: 	at android.view.Choreographer.doFrame(Choreographer.java:907)
AndroidRuntime: 	at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1248)
AndroidRuntime: 	at android.os.Handler.handleCallback(Handler.java:900)
AndroidRuntime: 	at android.os.Handler.dispatchMessage(Handler.java:103)
AndroidRuntime: 	at android.os.Looper.loop(Looper.java:219)
AndroidRuntime: 	at android.app.ActivityThread.main(ActivityThread.java:8668)
AndroidRuntime: 	at java.lang.reflect.Method.invoke(Native Method)
AndroidRuntime: 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513)
AndroidRuntime: 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1109)
z

Zach Klippenstein (he/him) [MOD]

05/10/2022, 3:18 PM
There was just a long thread about this a couple scrolls up
m

Manideep Polireddi

05/10/2022, 3:27 PM
@Zach Klippenstein (he/him) [MOD] I was suggested to create a different thread, since the root cause looked to be different with the same exception https://kotlinlang.slack.com/archives/CJLTWPH7S/p1652118699337529?thread_ts=1652084646.064769&cid=CJLTWPH7S
t

theapache64

05/11/2022, 7:48 AM
@Zach Klippenstein (he/him) [MOD] U mean this one?
z

Zach Klippenstein (he/him) [MOD]

05/24/2022, 5:37 PM
That one looks possibly relevant, yea. Hard to say without seeing any code
Did you file a bug for this?
t

theapache64

05/24/2022, 5:46 PM
Not yet. Wanted to confirm if its a bug or not first. Should we create a new ticket in issuetracker?
z

Zach Klippenstein (he/him) [MOD]

05/24/2022, 5:46 PM
It’s not clear, so better to just file
t

theapache64

05/24/2022, 5:46 PM
Sure.
z

Zach Klippenstein (he/him) [MOD]

05/24/2022, 5:51 PM
How is the code that triggers this calling
animate
? Is it being called from a thread other than the main one?
a

Ale Stamato

05/24/2022, 6:01 PM
(Could you please share here the bug number once filed? cheers!)
1
t

theapache64

05/25/2022, 4:15 AM
How is the code that triggers this calling
animate
? Is it being called from a thread other than the main one?
@Zach Klippenstein (he/him) [MOD] No. All UI stuffs (like animation) or update
State
are on main thread. We double checked this.
z

Zach Klippenstein (he/him) [MOD]

05/25/2022, 3:09 PM
Just to confirm, you're seeing this in compose 1.1 right? Have you tried 1.2?
m

Manideep Polireddi

05/25/2022, 3:11 PM
Yes 1.1. Trying out 1.2. Doing the changes. Will report back our findings. cc @theapache64
1
Our current reproduction steps (inconsistent) include change of orientation back and forth. Triggered from our own code.
z

Zach Klippenstein (he/him) [MOD]

05/25/2022, 4:07 PM
Sorry, do you mean it’s still happening on 1.2?
m

Manideep Polireddi

05/25/2022, 4:08 PM
Not yet. We are checking. Will report shortly.
👍🏻 1
t

theapache64

05/25/2022, 4:32 PM
Reproducible with
1.2.0-beta01
too. Confirmed.
👍🏻 1
Here’s the stacktrace (compose
1.2.0-beta01
),
Fatal Exception: java.lang.IllegalStateException: Reading a state that was created after the snapshot was taken or in a snapshot that has not yet been applied
       at androidx.compose.runtime.snapshots.SnapshotKt.readError(Snapshot.kt:1826)
       at androidx.compose.runtime.snapshots.SnapshotKt.readable(Snapshot.kt:1821)
       at androidx.compose.runtime.snapshots.SnapshotKt.readable(Snapshot.kt:1812)
       at androidx.compose.runtime.SnapshotMutableStateImpl.getValue(SnapshotState.kt:130)
       at androidx.compose.animation.core.AnimationScope.isRunning(AnimationScope.java:337)
       at androidx.compose.animation.core.SuspendAnimationKt.animate(SuspendAnimation.kt:260)
       at androidx.compose.animation.core.SuspendAnimationKt$animate$4.invokeSuspend(SuspendAnimation.kt:15)
       at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
       at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
       at androidx.compose.ui.platform.AndroidUiDispatcher.performTrampolineDispatch(AndroidUiDispatcher.android.kt:81)
       at androidx.compose.ui.platform.AndroidUiDispatcher.access$performTrampolineDispatch(AndroidUiDispatcher.android.kt:41)
       at androidx.compose.ui.platform.AndroidUiDispatcher$dispatchCallback$1.run(AndroidUiDispatcher.android.kt:57)
       at android.os.Handler.handleCallback(Handler.java:938)
       at android.os.Handler.dispatchMessage(Handler.java:99)
       at android.os.Looper.loop(Looper.java:223)
       at android.app.ActivityThread.main(ActivityThread.java:7664)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
z

Zach Klippenstein (he/him) [MOD]

05/25/2022, 4:55 PM
Can you post that on the issue?
t

theapache64

05/25/2022, 4:56 PM
Sure
Done
🙏🏻 1