coil-kt / coil

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

Error loading .svg image in Jetpack Compose for Desktop #2330

Open jdsdhp opened 4 days ago

jdsdhp commented 4 days ago

Describe the bug I am trying to load an image of type .svg in my app, but it is not allowed, and it returns an error in the onError callback. I am using Jetpack Compose for Desktop. Details are attached below.

To Reproduce

AsyncImage(
                    modifier = Modifier
                        .size(50.dp)
                        .padding(all = Paddings.tiny)
                        .clip(shape = MaterialTheme.shapes.small)
                        .border(
                            width = 2.dp,
                            color = MaterialTheme.colors.onSurface,
                            shape = MaterialTheme.shapes.small,
                        ),
                    model = workspace.avatar,
                    contentDescription = "Avatar",
                    placeholder = painterResource(Res.drawable.ic_image_placeholder),
                )

Logs/Screenshots Error(painter=null, result=ErrorResult(image=null, request=ImageRequest(context=coil3.PlatformContext$Companion$INSTANCE$1@7a121de9, data=https://bitbucket.org/workspaces/my-company/avatar/?ts=1715362523, target=coil3.compose.AsyncImagePainter$updateRequest$$inlined$target$default$1@39b9e0d1, listener=null, memoryCacheKey=null, memoryCacheKeyExtras={}, diskCacheKey=null, fileSystem=NioSystemFileSystem, fetcherFactory=null, decoderFactory=null, interceptorDispatcher=Dispatchers.Main.immediate, fetcherDispatcher=Dispatchers.IO, decoderDispatcher=Dispatchers.IO, memoryCachePolicy=ENABLED, diskCachePolicy=ENABLED, networkCachePolicy=ENABLED, placeholderMemoryCacheKey=null, placeholderFactory=interface kotlin.jvm.functions.Function1, errorFactory=interface kotlin.jvm.functions.Function1, fallbackFactory=interface kotlin.jvm.functions.Function1, sizeResolver=coil3.compose.internal.ConstraintsSizeResolver@136a3a04, scale=FIT, precision=INEXACT, extras=Extras(data={}), defined=Defined(interceptorDispatcher=null, fetcherDispatcher=null, decoderDispatcher=null, memoryCachePolicy=null, diskCachePolicy=null, networkCachePolicy=null, placeholderFactory=interface kotlin.jvm.functions.Function1, errorFactory=interface kotlin.jvm.functions.Function1, fallbackFactory=interface kotlin.jvm.functions.Function1, sizeResolver=coil3.compose.internal.ConstraintsSizeResolver@136a3a04, scale=FIT, precision=INEXACT), defaults=Defaults(fileSystem=NioSystemFileSystem, interceptorDispatcher=Dispatchers.Main.immediate, fetcherDispatcher=Dispatchers.IO, decoderDispatcher=Dispatchers.IO, memoryCachePolicy=ENABLED, diskCachePolicy=ENABLED, networkCachePolicy=ENABLED, placeholderFactory=interface kotlin.jvm.functions.Function1, errorFactory=interface kotlin.jvm.functions.Function1, fallbackFactory=interface kotlin.jvm.functions.Function1, precision=AUTOMATIC, extras=Extras(data={coil3.Extras$Key@133df82=kotlin.Unit}))), throwable=java.lang.IllegalArgumentException: Failed to Image::makeFromEncoded))

Version

    val coilVersion = "3.0.0-alpha06"
    implementation("io.coil-kt.coil3:coil-compose:$coilVersion")
    implementation("io.coil-kt.coil3:coil-compose-core:$coilVersion")
    implementation("io.coil-kt.coil3:coil-network-ktor:$coilVersion")
    implementation("io.coil-kt.coil3:coil:$coilVersion")
colinrtwhite commented 4 days ago

Can you post the failing image? java.lang.IllegalArgumentException: Failed to Image::makeFromEncoded) implies that the underlying Skia decoder failed to decode the image.

jdsdhp commented 4 days ago

Hi @colinrtwhite, thank you for your response. Later, I did some tests with other svg files, obtaining the same reslt. I believe this is not a bug caused by this specific svg image.

workspace_code

colinrtwhite commented 2 days ago

Does the image fail to decode when using the SVGDom class directly (see here)? If so the issue is with the underlying decoder and will need to be fixed in Skiko.