qdsfdhvh/compose-imageloader

Crash on iOS application

Closed this issue · 9 comments

Hello,
Thanks for the SDK. I'm using this beautiful imageLoader in my KMM android-ios project. The iOS application crashes when fast scrolling, but this situation does not occur when 'rememberCoroutineScope()' is passed to imageLoader for iOS consumer app.

The error report when I debug it with Xcode ,

MidJourney Images Compose Multiplatform`:
    0x1027e1378 <+92>:  bl     0x10312e9cc               ; EnterFrame
    0x1027e137c <+96>:  adrp   x8, 6570
    0x1027e1380 <+100>: add    x8, x8, #0xcdc            ; kotlin::mm::internal::gSuspensionRequested
    0x1027e1384 <+104>: ldarb  w8, [x8]
    0x1027e1388 <+108>: tbz    w8, #0x0, 0x1027e1398     ; <+124> at MetalRedrawer.ios.kt
    0x1027e138c <+112>: b      0x1027e1390               ; <+116> at MetalRedrawer.ios.kt:158:5
    0x1027e1390 <+116>: bl     0x103112df4               ; kotlin::mm::SuspendIfRequestedSlowPath()
->  0x1027e1394 <+120>: b      0x1027e1398               ; <+124> at MetalRedrawer.ios.kt
    0x1027e1398 <+124>: b      0x1027e139c               ; <+128> at MetalRedrawer.ios.kt
    0x1027e139c <+128>: ldr    x1, [sp, #0x10]
    0x1027e13a0 <+132>: ldur   x0, [x29, #-0x8]
    0x1027e13a4 <+136>: bl     0x1023affa0               ; interpretObjCPointer
    0x1027e13a8 <+140>: str    x0, [sp]
    0x1027e13ac <+144>: b      0x1027e13b0               ; <+148> at MetalRedrawer.ios.kt
    0x1027e13b0 <+148>: ldr    x0, [sp]
    0x1027e13b4 <+152>: bl     0x1027e11d0               ; kfun:org.jetbrains.skiko.redrawer.FrameTickListener.onDisplayLinkTick#internal at MetalRedrawer.ios.kt
    0x1027e13b8 <+156>: b      0x1027e13bc               ; <+160> at MetalRedrawer.ios.kt:160:6
    0x1027e13bc <+160>: b      0x1027e13c0               ; <+164> at MetalRedrawer.ios.kt
  0x1027e13c0 <+164>: ldr    x0, [sp, #0x8]
    0x1027e13c4 <+168>: mov    w1, #0x0
    0x1027e13c8 <+172>: mov    w2, #0x4
    0x1027e13cc <+176>: bl     0x10312ea18               ; LeaveFrame

Where could the error be originating from?
Any recommendations? Thanks 🙏

crash.mov

Hi, I've tried to fix it #150 but I'm not quite sure reason is(may be memory out), I'll release version 1.4.2 soon and you can test it.

Unfortunately, it persists with 1.4.2.
The same crash appears.

IsrememberCoroutineScope() still not crash? I'll research to see what difference in CoroutineContext 🤔 .

IsrememberCoroutineScope() still not crash? I'll research to see what the difference in CoroutineContext 🤔 .

Yes, on my emulator, when I put a coroutineScope.context like here, the application is not being crashed on the iOS side.

However, even in version 1.4.2, if I remove that coroutineScope, the application crashes after my fast scroll gesture.

Can you test Dispatchers.Default(or Main) & Dispatchers.IO? I think it's possible that Dispatchers.IO created too many threads at once and caused crash.

Main works without crashing, however, it experiences some laggy situations while loading and is not the recommended way, as you probably know. It blocks the main thread, causing little jumps while gesturing. On the other hand, IO is the default and can cause crashes.

ImageLoader(getDispatcherProvider().io) { components { setupDefaultComponents(imageScope) }

is equivalent to

ImageLoader { components { setupDefaultComponents(imageScope) }

Does Dispatchers.Default will be crash?

For 'Dispatchers.Default', it is better than 'Dispatchers.IO' as it is harder to reproduce this crash. However, after scrolling through more than 15 pages quickly, it still crashes.