JetBrains / compose-multiplatform

Compose Multiplatform, a modern UI framework for Kotlin that makes building performant and beautiful user interfaces easy and enjoyable.
https://jetbrains.com/lp/compose-multiplatform
Apache License 2.0
15.86k stars 1.15k forks source link

Crash when loading some special XML drawable resources (1.6.0-rc03) #4363

Closed ssttkkl closed 6 months ago

ssttkkl commented 6 months ago

Describe the bug Crash when loading some special XML drawable resources.

Like this one: https://github.com/ssttkkl/compose-multiplatform-bug-reproducer/blob/master/composeApp/src/commonMain/composeResources/drawable/icon_arrow_outward.xml

And this one: https://github.com/ssttkkl/compose-multiplatform-bug-reproducer/blob/master/composeApp/src/commonMain/composeResources/drawable/icon_drag_handle.xml

I got the .svg files from Google Fonts, and convert them to .xml by this way: https://github.com/JetBrains/compose-multiplatform/issues/3713#issuecomment-1733615888

Desktop stacktrace:

Exception in thread "main" java.lang.IllegalArgumentException: Failed to Image::makeFromEncoded
    at org.jetbrains.skia.Image$Companion.makeFromEncoded(Image.kt:137)
    at org.jetbrains.compose.resources.ImageResources_skikoKt.toImageBitmap(ImageResources.skiko.kt:8)
    at org.jetbrains.compose.resources.ImageResourcesKt$imageResource$imageBitmap$3$cached$1.invoke(ImageResources.kt:77)
    at org.jetbrains.compose.resources.ImageResourcesKt$imageResource$imageBitmap$3$cached$1.invoke(ImageResources.kt:76)
    at org.jetbrains.compose.resources.ImageResourcesKt$loadImage$2$deferred$1$1$1.invokeSuspend(ImageResources.kt:134)
    at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
    at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:108)
    at kotlinx.coroutines.EventLoopImplBase.processNextEvent(EventLoop.common.kt:280)
    at kotlinx.coroutines.BlockingCoroutine.joinBlocking(Builders.kt:85)
    at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking(Builders.kt:59)
    at kotlinx.coroutines.BuildersKt.runBlocking(Unknown Source)
    at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking$default(Builders.kt:38)
    at kotlinx.coroutines.BuildersKt.runBlocking$default(Unknown Source)
    at org.jetbrains.compose.resources.ResourceState_blockingKt.rememberResourceState(ResourceState.blocking.kt:15)
    at org.jetbrains.compose.resources.ImageResourcesKt.imageResource(ImageResources.kt:74)
    at ComposableSingletons$AppKt$lambda-1$1.invoke(App.kt:20)
    at ComposableSingletons$AppKt$lambda-1$1.invoke(App.kt:18)
    ......

Android stacktrace:

                                                                                                    java.lang.NullPointerException: decodeByteArray(...) must not be null
                                                                                                        at org.jetbrains.compose.resources.ImageResources_androidKt.toImageBitmap(ImageResources.android.kt:8)
                                                                                                        at org.jetbrains.compose.resources.ImageResourcesKt$imageResource$imageBitmap$3$cached$1.invoke(ImageResources.kt:77)
                                                                                                        at org.jetbrains.compose.resources.ImageResourcesKt$imageResource$imageBitmap$3$cached$1.invoke(ImageResources.kt:76)
                                                                                                        at org.jetbrains.compose.resources.ImageResourcesKt$loadImage$2$deferred$1$1$1.invokeSuspend(ImageResources.kt:134)
                                                                                                        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
                                                                                                        at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:108)
                                                                                                        at kotlinx.coroutines.EventLoopImplBase.processNextEvent(EventLoop.common.kt:280)
                                                                                                        at kotlinx.coroutines.BlockingCoroutine.joinBlocking(Builders.kt:85)
                                                                                                        at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking(Builders.kt:59)
                                                                                                        at kotlinx.coroutines.BuildersKt.runBlocking(Unknown Source:1)
                                                                                                        at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking$default(Builders.kt:38)
                                                                                                        at kotlinx.coroutines.BuildersKt.runBlocking$default(Unknown Source:1)
                                                                                                        at org.jetbrains.compose.resources.ResourceState_blockingKt.rememberResourceState(ResourceState.blocking.kt:15)
                                                                                                        at org.jetbrains.compose.resources.ImageResourcesKt.imageResource(ImageResources.kt:74)
                                                                                                        at ComposableSingletons$AppKt$lambda-1$1.invoke(App.kt:20)
                                                                                                        at ComposableSingletons$AppKt$lambda-1$1.invoke(App.kt:18)
    ......

Affected platforms Select one of the platforms below:

Versions

To Reproduce

This repository contains a reproducer project: https://github.com/ssttkkl/compose-multiplatform-bug-reproducer, just simply run then it crashes.

Expected behavior

Drawable resources can be loaded successfully.

ssttkkl commented 6 months ago

Sorry, I am wrong. I use imageResources to load a vector drawable so it crashes. Everything works after I use painterResource.

This issue can be closed I think.

okushnikov commented 1 week ago

Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks.