coil-kt / coil

Image loading for Android and Compose Multiplatform.
https://coil-kt.github.io/coil/
Apache License 2.0
10.79k stars 660 forks source link

LazyColumn + AsyncImage loads the image, and when an error occurs during fast scrolling #2096

Closed SheTieJun closed 8 months ago

SheTieJun commented 9 months ago

Version coil3 = "3.0.0-alpha03“

Describe the bug

LazyColumn + AsyncImage loads the image, and when an error occurs during fast scrolling, there is no callback onError.


To Reproduce

LazyColumn {
            items(20) {
                val url =  "https://tvax3.sinaimg.cn/large/008kBpBlgy1h2kw4940scj304605s0sr.jpg"
                AsyncImage(
                    model = ImageRequest.Builder(LocalPlatformContext.current)
                        .placeholderMemoryCacheKey(url.md5())
                        .data(url)
                        .build(),
                    contentDescription = null,
                    imageLoader = SingletonImageLoader.get(LocalPlatformContext.current),
                    modifier =  Modifier.width(200.dp)
                        .height(120.dp)
                        .clip(shape = RoundedCornerShape(10.dp)),
                    onError = {
                        println("load error")
                    },
                    onLoading = {
                        println("load onLoading")
                    },
                    onSuccess = {
                        println("load onSuccess")
                    }
                )
                Divider(modifier = Modifier.height(10.dp).background(Color.Transparent))
            }
        }

Logs/Screenshots image

🧠 Successful (MEMORY_CACHE) - https://xxxx.jpg
load onLoading
load onSuccess
Exception in thread "JavaFX Application Thread" 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:1930)
    at androidx.compose.runtime.snapshots.SnapshotKt.readable(Snapshot.kt:1914)
    at androidx.compose.runtime.SnapshotMutableStateImpl.getValue(SnapshotState.kt:135)
    at coil3.compose.AsyncImagePainter.getRequest(AsyncImagePainter.kt:433)
    at coil3.compose.AsyncImagePainter$onRemembered$1$1.invoke(AsyncImagePainter.kt:268)
    at coil3.compose.AsyncImagePainter$onRemembered$1$1.invoke(AsyncImagePainter.kt:268)
    at androidx.compose.runtime.SnapshotStateKt__SnapshotFlowKt$snapshotFlow$1.invokeSuspend(SnapshotFlow.kt:181)
    at androidx.compose.runtime.SnapshotStateKt__SnapshotFlowKt$snapshotFlow$1.invoke(SnapshotFlow.kt)
    at androidx.compose.runtime.SnapshotStateKt__SnapshotFlowKt$snapshotFlow$1.invoke(SnapshotFlow.kt)
    at kotlinx.coroutines.flow.SafeFlow.collectSafely(Builders.kt:61)
    at kotlinx.coroutines.flow.AbstractFlow.collect(Flow.kt:230)
    at kotlinx.coroutines.flow.internal.ChannelFlowTransformLatest$flowCollect$3.invokeSuspend(Merge.kt:27)
    at kotlinx.coroutines.flow.internal.ChannelFlowTransformLatest$flowCollect$3.invoke(Merge.kt)
    at kotlinx.coroutines.flow.internal.ChannelFlowTransformLatest$flowCollect$3.invoke(Merge.kt)
    at kotlinx.coroutines.intrinsics.UndispatchedKt.startUndispatchedOrReturn(Undispatched.kt:65)
    at kotlinx.coroutines.CoroutineScopeKt.coroutineScope(CoroutineScope.kt:264)
    at kotlinx.coroutines.flow.internal.ChannelFlowTransformLatest.flowCollect(Merge.kt:25)
    at kotlinx.coroutines.flow.internal.ChannelFlowOperator.collectTo$suspendImpl(ChannelFlow.kt:157)
    at kotlinx.coroutines.flow.internal.ChannelFlowOperator.collectTo(ChannelFlow.kt)
    at kotlinx.coroutines.flow.internal.ChannelFlow$collectToFun$1.invokeSuspend(ChannelFlow.kt:60)
    at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
    at kotlinx.coroutines.internal.DispatchedContinuation.resumeWith(DispatchedContinuation.kt:204)
    at kotlin.coroutines.ContinuationKt.startCoroutine(Continuation.kt:129)
    at kotlinx.coroutines.CoroutineStart.invoke(CoroutineStart.kt:92)
    at kotlinx.coroutines.AbstractCoroutine.start(AbstractCoroutine.kt:126)
    at kotlinx.coroutines.channels.ProduceKt.produce(Produce.kt:132)
    at kotlinx.coroutines.channels.ProduceKt.produce$default(Produce.kt:120)
    at kotlinx.coroutines.flow.internal.ChannelFlow.produceImpl(ChannelFlow.kt:119)
    at kotlinx.coroutines.flow.internal.ChannelFlow$collect$2.invokeSuspend(ChannelFlow.kt:123)
    at kotlinx.coroutines.flow.internal.ChannelFlow$collect$2.invoke(ChannelFlow.kt)
    at kotlinx.coroutines.flow.internal.ChannelFlow$collect$2.invoke(ChannelFlow.kt)
    at kotlinx.coroutines.intrinsics.UndispatchedKt.startUndispatchedOrReturn(Undispatched.kt:65)
    at kotlinx.coroutines.CoroutineScopeKt.coroutineScope(CoroutineScope.kt:264)
    at kotlinx.coroutines.flow.internal.ChannelFlow.collect$suspendImpl(ChannelFlow.kt:122)
    at kotlinx.coroutines.flow.internal.ChannelFlow.collect(ChannelFlow.kt)
    at kotlinx.coroutines.flow.internal.ChannelFlowOperator.collect$suspendImpl(ChannelFlow.kt:173)
    at kotlinx.coroutines.flow.internal.ChannelFlowOperator.collect(ChannelFlow.kt)
    at coil3.compose.AsyncImagePainter$onRemembered$1.invokeSuspend(AsyncImagePainter.kt:270)
    at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
    at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:108)
    at com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:457)
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
    at com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:456)
    at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
    at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:184)
    at java.base/java.lang.Thread.run(Thread.java:833)
    Suppressed: kotlinx.coroutines.internal.DiagnosticCoroutineContextException: [StandaloneCoroutine{Cancelling}@29325d88, Dispatchers.Main.immediate]
colinrtwhite commented 9 months ago

@SheTieJun Can you test again with alpha04? I think this may be fixed

SheTieJun commented 9 months ago

I'm sorry, because I went back to my hometown during the Chinese New Year, and I only brought my Mac computer, but when the same project was run on Mac, there was an error Exception in thread "main" java.lang.NoSuchMethodError: 'void androidx.compose. ui.graphics.SkiaBackedCanvas_skikoKt.setAlphaMultiplier, I tried some methods, such as api("org.jetbrains.compose.ui:ui-graphics-desktop:1.6.0-beat01"), but it was not solved. So ~ may need to wait until after the Chinese New Year before you can verify it.

SheTieJun commented 8 months ago

@colinrtwhite I have tested it in Windows, and still get the same error. At the same time, sometimes the program gets stuck and cannot perform any operations, including closing.

image

SheTieJun commented 8 months ago

It should be a problem with my project configuration. I tried Coil's Simple and it was normal. I'll compare the differences first.

SheTieJun commented 8 months ago

Because of org.openjfx:javafx, I used JavaFx's Video and Webview. When I remove JavaFx, it's OK