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

Crash when loading a particular svg #3713

Closed
rosuH opened this issue Sep 20, 2023 · 4 comments
Closed

Crash when loading a particular svg #3713

rosuH opened this issue Sep 20, 2023 · 4 comments
Labels
bug Something isn't working desktop reproduced

Comments

@rosuH
Copy link

rosuH commented Sep 20, 2023

Describe the bug
When loading the following svg file, a crash occurs.

ic_refresh.svg.zip

The svg file is placed in compose-multiplatform-ios-android-template-main/shared/src/commonMain/resources/ic_refresh.svg.

IconButton(
    modifier = Modifier.align(Alignment.BottomCenter).padding(0.dp, 0.dp, 0.dp, 16.dp),
    onClick = {
    }
) {
    Icon(
        painter = painterResource("ic_refresh.svg"),
        contentDescription = "Refresh"
    )
}

Affected platforms
Select one of the platforms below:

  • All

Versions

  • Kotlin version*: 1.9.10
  • Compose Multiplatform version*: 1.5.1
  • OS version(s)* (required for Desktop and iOS issues):
  • OS architecture (x86 or arm64):
  • JDK (for desktop issues): 17

To Reproduce
Steps and/or the code snippet to reproduce the behavior:

  1. Go to '...'
  2. Click on '...'
  3. Scroll down to '...'
  4. See error

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots

FATAL EXCEPTION: main
	Process: com.myapplication.MyApplication, PID: 7791
	java.lang.NullPointerException: decodeByteArray(this, 0, size) must not be null
		at org.jetbrains.compose.resources.ComposableResource_androidKt.toAndroidBitmap(ComposableResource.android.kt:17)
		at org.jetbrains.compose.resources.ComposableResource_androidKt.toImageBitmap(ComposableResource.android.kt:14)
		at org.jetbrains.compose.resources.ComposeResource_commonKt.rememberImageBitmapSync(ComposeResource.common.kt:82)
		at org.jetbrains.compose.resources.ComposeResource_commonKt.access$rememberImageBitmapSync(ComposeResource.common.kt:1)
		at org.jetbrains.compose.resources.ComposeResource_commonKt$painterResource$1.invoke(ComposeResource.common.kt:120)
		at org.jetbrains.compose.resources.ComposeResource_commonKt$painterResource$1.invoke(ComposeResource.common.kt:120)
		at org.jetbrains.compose.resources.ComposeResource_commonKt.painterResource(ComposeResource.common.kt:102)
		at org.jetbrains.compose.resources.ComposeResource_commonKt.painterResource(ComposeResource.common.kt:120)
		at com.example.kmp.ComposableSingletons$AppKt$lambda-2$1.invoke(App.kt:103)
		at com.example.kmp.ComposableSingletons$AppKt$lambda-2$1.invoke(App.kt:101)
		at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:108)
		at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:35)
		at androidx.compose.runtime.CompositionLocalKt.CompositionLocalProvider(CompositionLocal.kt:228)
		at androidx.compose.material.IconButtonKt.IconButton(IconButton.kt:79)
		at com.example.kmp.AppKt.Content(App.kt:93)
		at com.example.kmp.AppKt.launchScreen(App.kt:77)
		at com.example.kmp.AppKt.access$launchScreen(App.kt:1)
		at com.example.kmp.ComposableSingletons$AppKt$lambda-1$1.invoke(App.kt:45)
		at com.example.kmp.ComposableSingletons$AppKt$lambda-1$1.invoke(App.kt:44)
		at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:108)
		at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:35)
		at androidx.compose.material.MaterialTheme_androidKt.PlatformMaterialTheme(MaterialTheme.android.kt:23)
		at androidx.compose.material.MaterialThemeKt$MaterialTheme$1$1.invoke(MaterialTheme.kt:82)
		at androidx.compose.material.MaterialThemeKt$MaterialTheme$1$1.invoke(MaterialTheme.kt:81)
		at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:108)
		at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:35)
		at androidx.compose.runtime.CompositionLocalKt.CompositionLocalProvider(CompositionLocal.kt:228)
		at androidx.compose.material.TextKt.ProvideTextStyle(Text.kt:396)
		at androidx.compose.material.MaterialThemeKt$MaterialTheme$1.invoke(MaterialTheme.kt:81)
		at androidx.compose.material.MaterialThemeKt$MaterialTheme$1.invoke(MaterialTheme.kt:80)
		at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:108)
		at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:35)
		at androidx.compose.runtime.CompositionLocalKt.CompositionLocalProvider(CompositionLocal.kt:228)
		at androidx.compose.material.MaterialThemeKt.MaterialTheme(MaterialTheme.kt:72)
		at com.example.kmp.AppKt.App(App.kt:44)
		at com.example.kmp.Main_androidKt.MainView(main.android.kt:12)
		at com.myapplication.ComposableSingletons$MainActivityKt$lambda-1$1.invoke(MainActivity.kt:13)
		at com.myapplication.ComposableSingletons$MainActivityKt$lambda-1$1.invoke(MainActivity.kt:12)
		at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:108)
		at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:35)
		at androidx.compose.ui.platform.ComposeView.Content(ComposeView.android.kt:428)
		at androidx.compose.ui.platform.AbstractComposeView$ensureCompositionCreated$1.invoke(ComposeView.android.kt:252)
2023-09-20 19:14:17.659  7791-7791  AndroidRuntime                      com...ication.MyApplication  E  	at androidx.compose.ui.platform.AbstractComposeView$ensureCompositionCreated$1.invoke(ComposeView.android.kt:251)
		at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:108)
		at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:35)
		at androidx.compose.runtime.CompositionLocalKt.CompositionLocalProvider(CompositionLocal.kt:228)
		at androidx.compose.ui.platform.CompositionLocalsKt.ProvideCommonCompositionLocals(CompositionLocals.kt:195)
		at androidx.compose.ui.platform.AndroidCompositionLocals_androidKt$ProvideAndroidCompositionLocals$3.invoke(AndroidCompositionLocals.android.kt:119)
		at androidx.compose.ui.platform.AndroidCompositionLocals_androidKt$ProvideAndroidCompositionLocals$3.invoke(AndroidCompositionLocals.android.kt:118)
		at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:108)
		at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:35)
		at androidx.compose.runtime.CompositionLocalKt.CompositionLocalProvider(CompositionLocal.kt:228)
		at androidx.compose.ui.platform.AndroidCompositionLocals_androidKt.ProvideAndroidCompositionLocals(AndroidCompositionLocals.android.kt:110)
		at androidx.compose.ui.platform.WrappedComposition$setContent$1$1$2.invoke(Wrapper.android.kt:158)
		at androidx.compose.ui.platform.WrappedComposition$setContent$1$1$2.invoke(Wrapper.android.kt:157)
		at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:108)
		at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:35)
		at androidx.compose.runtime.CompositionLocalKt.CompositionLocalProvider(CompositionLocal.kt:228)
		at androidx.compose.ui.platform.WrappedComposition$setContent$1$1.invoke(Wrapper.android.kt:157)
		at androidx.compose.ui.platform.WrappedComposition$setContent$1$1.invoke(Wrapper.android.kt:142)
		at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:108)
		at androidx.compose.runtime.internal.ComposableLambdaImpl.invoke(ComposableLambda.jvm.kt:35)
		at androidx.compose.runtime.ActualJvm_jvmKt.invokeComposable(ActualJvm.jvm.kt:78)
		at androidx.compose.runtime.ComposerImpl.doCompose(Composer.kt:3340)
		at androidx.compose.runtime.ComposerImpl.composeContent$runtime_release(Composer.kt:3273)
		at androidx.compose.runtime.CompositionImpl.composeContent(Composition.kt:588)
		at androidx.compose.runtime.Recomposer.composeInitial$runtime_release(Recomposer.kt:1013)
		at androidx.compose.runtime.CompositionImpl.setContent(Composition.kt:520)
		at androidx.compose.ui.platform.WrappedComposition$setContent$1.invoke(Wrapper.android.kt:142)
		at androidx.compose.ui.platform.WrappedComposition$setContent$1.invoke(Wrapper.android.kt:133)
		at androidx.compose.ui.platform.AndroidComposeView.setOnViewTreeOwnersAvailable(AndroidComposeView.android.kt:1191)
		at androidx.compose.ui.platform.WrappedComposition.setContent(Wrapper.android.kt:133)
		at androidx.compose.ui.platform.WrappedComposition.onStateChanged(Wrapper.android.kt:183)
		at androidx.lifecycle.LifecycleRegistry$ObserverWithState.dispatchEvent(LifecycleRegistry.kt:314)
		at androidx.lifecycle.LifecycleRegistry.addObserver(LifecycleRegistry.kt:192)
		at androidx.compose.ui.platform.WrappedComposition$setContent$1.invoke(Wrapper.android.kt:140)
		at androidx.compose.ui.platform.WrappedComposition$setContent$1.invoke(Wrapper.android.kt:133)
		at androidx.compose.ui.platform.AndroidComposeView.onAttachedToWindow(AndroidComposeView.android.kt:1266)
		at android.view.View.dispatchAttachedToWindow(View.java:21357)
		at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3491)
		at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3498)
		at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3498)
		at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3498)
		at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3498)
		at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3498)
		at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3498)
		at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2900)
		at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:2371)
		at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:9297)
		at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1231)
		at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1239)
		at android.view.Choreographer.doCallbacks(Choreographer.java:899)
		at android.view.Choreographer.doFrame(Choreographer.java:832)
		at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1214)
		at android.os.Handler.handleCallback(Handler.java:942)
		at android.os.Handler.dispatchMessage(Handler.java:99)
		at android.os.Looper.loopOnce(Looper.java:201)
		at android.os.Looper.loop(Looper.java:288)
		at android.app.ActivityThread.main(ActivityThread.java:7924)
		at java.lang.reflect.Method.invoke(Native Method)
		at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
		at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)

Additional context
Add any other context about the problem here.

@rosuH rosuH added bug Something isn't working submitted labels Sep 20, 2023
@rosuH rosuH changed the title Crash when loading svg Crash when loading a particular svg Sep 20, 2023
@eric-ampire
Copy link

I was having the same issue, but I've convert the svg file to xml and the problem was solved

@dima-avdeev-jb dima-avdeev-jb added wait for reply Further information is requested desktop and removed submitted labels Sep 23, 2023
@dima-avdeev-jb
Copy link
Contributor

@rosuH
I can't reproduce your issue here: https://github.com/dima-avdeev-jb/issue-3713
Can you please check it in my repository too.

@rosuH
Copy link
Author

rosuH commented Sep 23, 2023

Thank you for your reply, I have modified the code in order to reproduce the error.
You can check dima-avdeev-jb/issue-3713@5a797de to check the changes.
Also below is the project zip for easy and direct running.

MyApplication.zip

@dima-avdeev-jb dima-avdeev-jb added reproduced and removed wait for reply Further information is requested labels Sep 23, 2023
@dima-avdeev-jb
Copy link
Contributor

For now resources library supports only xml vector drawables and other raster formats (png, jpg. webp)
You shoud convert svg to xml in AndroidStudio:

You can do so with AndroidStudio in androidApp res folder:

image

And choose Local file

image

After that - copy xml file to shared module

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working desktop reproduced
Projects
None yet
Development

No branches or pull requests

3 participants