Adding SPM dependency crashes Compose Multiplatform project
Version
3.30.1
Steps to Reproduce
The only step to reproduce is to add https://github.com/PostHog/posthog-ios.git through SPM to my Compose Multiplatform project. It happens regardless of whether the client is initialized - just adding the dependency breaks my app. It crashes every single time a specific screen is shown - it's not random.
The issue is Thread 1: EXC_BAD_ACCESS (code=1, address=0x0), but it talks about the Canvas.kt file not being found. To me, Canvas.kt sounds like a red herring - it might be bad memory management (a leak or bad access).
...
0x10e91d6ac <+536>: bl 0x10e9c7e6c ; kfun:org.jetbrains.skia.impl#getPtr(org.jetbrains.skia.impl.Native?){}kotlin.native.internal.NativePtr at Native.kt
0x10e91d6b0 <+540>: str x0, [sp, #0x30]
0x10e91d6b4 <+544>: b 0x10e91d6b8 ; <+548> at Canvas.kt
0x10e91d6b8 <+548>: ldr x4, [sp, #0x30]
0x10e91d6bc <+552>: ldr w3, [sp, #0x38]
0x10e91d6c0 <+556>: ldr w2, [sp, #0x3c]
0x10e91d6c4 <+560>: ldr s7, [sp, #0x40]
0x10e91d6c8 <+564>: ldr s6, [sp, #0x44]
0x10e91d6cc <+568>: ldr s5, [sp, #0x48]
0x10e91d6d0 <+572>: ldr s4, [sp, #0x4c]
0x10e91d6d4 <+576>: ldr s3, [sp, #0x50]
0x10e91d6d8 <+580>: ldr s2, [sp, #0x54]
0x10e91d6dc <+584>: ldr s1, [sp, #0x58]
0x10e91d6e0 <+588>: ldr s0, [sp, #0x5c]
0x10e91d6e4 <+592>: ldr x1, [sp, #0x60]
0x10e91d6e8 <+596>: ldr x0, [sp, #0x68]
0x10e91d6ec <+600>: ldurb w5, [x29, #-0x11]
0x10e91d6f0 <+604>: bl 0x10ef88fdc ; org_jetbrains_skia_Canvas__1nDrawImageRect
-> 0x10e91d6f4 <+608>: b 0x10e91d6f8 ; <+612> at Canvas.kt:484:14
0x10e91d6f8 <+612>: b 0x10e91d6fc ; <+616> at Canvas.kt
0x10e91d6fc <+616>: ldr x8, [sp, #0x88]
0x10e91d700 <+620>: ldr x0, [x8]
0x10e91d704 <+624>: bl 0x10e9f1af4 ; kfun:org.jetbrains.skia.impl#reachabilityBarrier(kotlin.Any?){} at Native.native.kt
0x10e91d708 <+628>: b 0x10e91d70c ; <+632> at Canvas.kt
0x10e91d70c <+632>: ldr x8, [sp, #0xa8]
0x10e91d710 <+636>: ldr x0, [x8]
0x10e91d714 <+640>: bl 0x10e9f1af4 ; kfun:org.jetbrains.skia.impl#reachabilityBarrier(kotlin.Any?){} at Native.native.kt
0x10e91d718 <+644>: b 0x10e91d71c ; <+648> at Canvas.kt
0x10e91d71c <+648>: ldr x8, [sp, #0x80]
0x10e91d720 <+652>: ldr x0, [x8]
0x10e91d724 <+656>: bl 0x10e9f1af4 ; kfun:org.jetbrains.skia.impl#reachabilityBarrier(kotlin.Any?){} at Native.native.kt
0x10e91d728 <+660>: b 0x10e91d72c ; <+664> at Canvas.kt
0x10e91d72c <+664>: ldr x8, [sp, #0x80]
0x10e91d730 <+668>: ldr x0, [x8]
0x10e91d734 <+672>: str x0, [sp, #0x28]
0x10e91d738 <+676>: b 0x10e91d7c8 ; <+820> at Canvas.kt
0x10e91d73c <+680>: mov x1, x0
0x10e91d740 <+684>: ldr x0, [sp, #0x78]
0x10e91d744 <+688>: str x1, [sp, #0x10]
0x10e91d748 <+692>: bl 0x10e5d128c ; SetCurrentFrame
0x10e91d74c <+696>: ldr x0, [sp, #0x10]
0x10e91d750 <+700>: bl 0x11027114c ; symbol stub for: __cxa_begin_catch
0x10e91d754 <+704>: ldr x1, [sp, #0xb8]
0x10e91d758 <+708>: bl 0x10e5ad3a8 ; Kotlin_getExceptionObject
0x10e91d75c <+712>: str x0, [sp, #0x18]
0x10e91d760 <+716>: bl 0x110271170 ; symbol stub for: __cxa_end_catch
0x10e91d764 <+720>: ldr x0, [sp, #0x18]
0x10e91d768 <+724>: str x0, [sp, #0x20]
0x10e91d76c <+728>: b 0x10e91d770 ; <+732> at Canvas.kt
0x10e91d770 <+732>: ldr x0, [sp, #0xc0]
0x10e91d774 <+736>: ldr x1, [sp, #0x20]
0x10e91d778 <+740>: bl 0x10e5ae9e4 ; UpdateStackRef
0x10e91d77c <+744>: ldr x0, [sp, #0x78]
0x10e91d780 <+748>: bl 0x10e5aea40 ; CheckCurrentFrame
0x10e91d784 <+752>: ldr x8, [sp, #0x88]
0x10e91d788 <+756>: ldr x0, [x8]
0x10e91d78c <+760>: bl 0x10e9f1af4 ; kfun:org.jetbrains.skia.impl#reachabilityBarrier(kotlin.Any?){} at Native.native.kt
...
I also see this warning in the console:
Can't show file for stack frame : <DBGLLDBStackFrame: 0x349ba2320> - stackNumber:13 - name:kfun:org.jetbrains.skia.Canvas#drawImageRect(org.jetbrains.skia.Image;org.jetbrains.skia.Rect;org.jetbrains.skia.Rect;org.jetbrains.skia.SamplingMode;org.jetbrains.skia.Paint?;kotlin.Boolean){}org.jetbrains.skia.Canvas. The file path does not exist on the file system: /Users/admin/buildAgent/work/a64d3aa477d12f6b/skiko/src/commonMain/kotlin/org/jetbrains/skia/Canvas.kt
Unfortunately, my app is closed source so I can't share the full code. Maybe this can be reproduced on a sample project. This only happens on a composable screen I have that's roughly the following:
@Composable
private fun CustomPlanScreenInner() {
Column(
modifier = Modifier
.fillMaxWidth()
) {
LazyColumn(
modifier = Modifier
.weight(1f),
horizontalAlignment = Alignment.CenterHorizontally,
) {
item {
Header(
modifier = Modifier.padding(top = 48.dp, start = 24.dp, end = 24.dp)
)
Spacer(Modifier.height(25.dp))
}
item {
DailyAverageComparison(modifier = Modifier.padding(horizontal = 24.dp))
}
}
}
}
For some reason, commenting out DailyAverageComparison prevents the crash. It's a pretty normal composable, so I doubt that's the root cause. Even if I remove everything except for the row, it still crashes (so the composables inside of it shouldn't matter). This is what makes me think it's just a memory issue - the rest of this screen also has images and other things that use Canvas.kt.
@Composable
private fun DailyAverageComparison(modifier: Modifier = Modifier) {
Row(
modifier = modifier
.fillMaxWidth(),
horizontalArrangement = Arrangement.Center
) {
DailyAverageItem(
title = "some text",
average = "some text",
drawable = Res.drawable.onboarding_time_chart1,
)
GradientVerticalDivider(modifier = Modifier.padding(horizontal = 8.dp))
DailyAverageItem(
title = "title",
average = "some text",
drawable = Res.drawable.onboarding_time_chart2,
)
}
}
Interestingly, this doesn't happen if I install the package through the Podfile. Note that I'm using the built-in assistant in XCode to add the dependency, not through Package.swift. This is because my project's structure is what Compose Multiplatform recommended, and no other dependencies require a Package.swift anyway.
Expected Result
The application shouldn't crash
Actual Result
The application crashes
@ioannisj any ideas? @marioortizmanero thanks for raising this. could you maybe provide an MRE? that seems to be very specific, so an MRE would help us to narrow down/reproduce the issue right away
@ioannisj any ideas? @marioortizmanero thanks for raising this. could you maybe provide an MRE? that seems to be very specific, so an MRE would help us to narrow down/reproduce the issue right away
@marandaneto - No, not really at first read. I'll try to reproduce even though I never worked with Compose Multiplatform before, just KMP, so I imagine it may take a while to reproduce. @marioortizmanero I feel that an MRE would really give us a head start with this one tbh
whats the outcome here @ioannisj ?
whats the outcome here @ioannisj ?
Ah missed this notification sorry. Tbh this took a back seat since KMP/CMP not really something we fully support. Initial thoughts is that maybe view swizzling or screen capture may be interfering with skia, but the fact that this doesn't happen when installing via Podfile confused me a bit
@marioortizmanero, waiting for an MRE just to see if I can pick up something obvious.
@ioannisj sorry, we ended up moving to Amplitude as we had to finish our analytics integration very soon
Closing the issue as a part of large repository cleanup, due to it being inactive and/or outdated. Please do not hesitate to ping me if it is still relevant, and I will happily reopen and work on it. Cheers!