Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

java.lang.IllegalStateException: Reading a state that was created after the snapshot was taken or in a snapshot that has not yet been applied #2346

Closed
kamgurgul opened this issue Jun 30, 2024 · 4 comments · Fixed by #2356

Comments

@kamgurgul
Copy link

After upgrade from version 3.0.0-alpha06 to 3.0.0-alpha07 this crash starts to occur on Android (tested on 14):

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:2033)
                 	at androidx.compose.runtime.snapshots.SnapshotKt.current(Snapshot.kt:2378)
                 	at androidx.compose.runtime.SnapshotMutableStateImpl.setValue(SnapshotState.kt:308)
                 	at coil3.compose.AsyncImagePainter.setPainter(AsyncImagePainter.kt:420)
                 	at coil3.compose.AsyncImagePainter.updateState(AsyncImagePainter.kt:307)
                 	at coil3.compose.AsyncImagePainter.access$updateState(AsyncImagePainter.kt:181)
                 	at coil3.compose.AsyncImagePainter$onRemembered$1$1.invokeSuspend$updateState(AsyncImagePainter.kt:253)
                 	at coil3.compose.AsyncImagePainter$onRemembered$1$1.access$invokeSuspend$updateState(Unknown Source:0)
                 	at coil3.compose.AsyncImagePainter$onRemembered$1$1$3.emit(AsyncImagePainter.kt:253)
                 	at coil3.compose.AsyncImagePainter$onRemembered$1$1$3.emit(AsyncImagePainter.kt:253)
                 	at kotlinx.coroutines.flow.FlowKt__ChannelsKt.emitAllImpl$FlowKt__ChannelsKt(Channels.kt:33)
                 	at kotlinx.coroutines.flow.FlowKt__ChannelsKt.access$emitAllImpl$FlowKt__ChannelsKt(Channels.kt:1)
                 	at kotlinx.coroutines.flow.FlowKt__ChannelsKt$emitAllImpl$1.invokeSuspend(Unknown Source:14)
                 	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
                 	at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:102)
                 	at kotlinx.coroutines.EventLoop.processUnconfinedEvent(EventLoop.common.kt:65)
                 	at kotlinx.coroutines.internal.DispatchedContinuationKt.resumeCancellableWith(DispatchedContinuation.kt:369)
                 	at kotlinx.coroutines.internal.DispatchedContinuationKt.resumeCancellableWith$default(DispatchedContinuation.kt:271)
                 	at kotlinx.coroutines.DispatchedCoroutine.afterResume(Builders.common.kt:255)
                 	at kotlinx.coroutines.AbstractCoroutine.resumeWith(AbstractCoroutine.kt:100)
                 	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:46)
                 	at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:102)
                 	at kotlinx.coroutines.internal.LimitedDispatcher$Worker.run(LimitedDispatcher.kt:113)
                 	at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:96)
                 	at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:589)
                 	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:816)
                 	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:720)
                 	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:707)
                 	Suppressed: kotlinx.coroutines.internal.DiagnosticCoroutineContextException: [androidx.compose.ui.platform.MotionDurationScaleImpl@391b699, androidx.compose.runtime.BroadcastFrameClock@e038d5e, StandaloneCoroutine{Cancelling}@14a053f, Dispatchers.Unconfined]

Affected code:

AsyncImage(
    model = ImageRequest.Builder(LocalPlatformContext.current)
        .data(appData.appIconUri)
        .crossfade(true)
        .build(),
     contentDescription = null,
     modifier = Modifier.size(50.dp),
)

App icon URI is created like that:

private fun getAppIconUri(packageName: String): String {
        return Uri.Builder()
            .scheme(ContentResolver.SCHEME_ANDROID_RESOURCE)
            .authority(packageName)
            .path(getResourceId(packageName).toString())
            .build()
            .toString()
    }

Compose multiplatform version: 1.6.11

@colinrtwhite
Copy link
Member

colinrtwhite commented Jun 30, 2024

Do you do anything special with threading or use a custom ImageLoader? If so, what's the config? Also does it occur every time or only sometimes? Are you able to reproduce this with a small code sample? Thanks!

For context, I ran into this issue during development, can't reproduce it any more locally (i.e. in the samples:compose project in this repo).

@kamgurgul
Copy link
Author

There is no custom ImageLoader. It occurs all the time and fully working sample could be found here https://github.com/kamgurgul/cpu-info/blob/master/shared/src/commonMain/kotlin/com/kgurgul/cpuinfo/features/applications/ApplicationsScreen.kt
Data are just loaded as a flow with Dispatchers.IO (based on multiplatform implementation) - https://github.com/kamgurgul/cpu-info/blob/master/shared/src/commonMain/kotlin/com/kgurgul/cpuinfo/domain/observable/ApplicationsDataObservable.kt#L14

If needed I could try to simplify this example.

@Caij
Copy link

Caij commented Jul 2, 2024

Yes, I also encountered this problem, Coil 3.0.0-alpha06 version has no problem

@colinrtwhite
Copy link
Member

@kamgurgul Thanks I'm able to repro it locally with your project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants