We are getting a crash due to illegal state read. ...
# compose
m
We are getting a crash due to illegal state read.
Copy code
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:
Copy code
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
There was just a long thread about this a couple scrolls up
m
@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
@Zach Klippenstein (he/him) [MOD] U mean this one?
z
That one looks possibly relevant, yea. Hard to say without seeing any code
Did you file a bug for this?
t
Not yet. Wanted to confirm if its a bug or not first. Should we create a new ticket in issuetracker?
z
It’s not clear, so better to just file
t
Sure.
z
How is the code that triggers this calling
animate
? Is it being called from a thread other than the main one?
a
(Could you please share here the bug number once filed? cheers!)
1
t
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
Just to confirm, you're seeing this in compose 1.1 right? Have you tried 1.2?
m
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
Sorry, do you mean it’s still happening on 1.2?
m
Not yet. We are checking. Will report shortly.
👍🏻 1
t
Reproducible with
1.2.0-beta01
too. Confirmed.
👍🏻 1
Here’s the stacktrace (compose
1.2.0-beta01
),
Copy code
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
Can you post that on the issue?
t
Sure
Done
🙏🏻 1