adrielcafe / voyager

🛸 A pragmatic navigation library for Jetpack Compose
https://voyager.adriel.cafe
MIT License
2.31k stars 109 forks source link

App Crashes on iOS when navigating, after upgrading to Kotlin 1.9.20 #244

Closed Vaibhav2002 closed 6 months ago

Vaibhav2002 commented 7 months ago

Crash on iOS When Navigating, after upgrade to Kotlin 1.9.20

After upgrading to Kotlin 1.9.20 App is crashing in iOS, when it navigates On Android, its working fine

Stack Trace:

Fatal Exception: kotlin.ConcurrentModificationException
0  Medial                         0xdcc10 kfun:kotlin.collections.HashMap.Itr#checkForComodification(){} + 587 (HashMap.kt:587)
1  Medial                         0xdce70 kfun:kotlin.collections.HashMap.EntriesItr#next(){}kotlin.collections.HashMap.EntryRef<1:0,1:1> + 618 (HashMap.kt:618)
2  Medial                         0x911354 kfun:kotlin.collections.Iterator#next(){}1:0-trampoline + 18 (Iterator.kt:18)
3  Medial                         0x1177cc kfun:kotlin.sequences.FilteringSequence.object-1.calcNext#internal + 170 (Sequences.kt:170)
4  Medial                         0x11796c kfun:kotlin.sequences.FilteringSequence.object-1.hasNext#internal + 195 (Sequences.kt:195)
5  Medial                         0x637764 kfun:cafe.adriel.voyager.core.model.ScreenModelStore.onEach#internal + 1313 (_Sequences.kt:1313)
6  Medial                         0x74be54 kfun:cafe.adriel.voyager.navigator.Navigator#dispose(cafe.adriel.voyager.core.screen.Screen){} + 1 (ScreenLifecycleStore.kt:1)
7  Medial                         0x750eb8 kfun:cafe.adriel.voyager.navigator.internal.object-2.dispose#internal + 1855 (_Collections.kt:1855)
8  Medial                         0x1f2fe4 kfun:androidx.compose.runtime.DisposableEffectImpl.onForgotten#internal + 86 (Effects.kt:86)
9  Medial                         0x1edca4 kfun:androidx.compose.runtime.CompositionImpl.RememberEventDispatcher.dispatchRememberObservers#internal (Composition.kt)
10 Medial                         0x1ebdbc kfun:androidx.compose.runtime.CompositionImpl.applyChangesInLocked#internal + 828 (Composition.kt:828)
11 Medial                         0x1ec2ec kfun:androidx.compose.runtime.CompositionImpl#applyChanges(){} + 850 (Composition.kt:850)
12 Medial                         0x1fa6e8 kfun:androidx.compose.runtime.Recomposer.$runRecomposeAndApplyChanges$lambda$4$lambda$3$FUNCTION_REFERENCE$12.$<bridge-UNNB>invoke(kotlin.Long){}#internal (ListUtils.kt)
13 Medial                         0x90d828 kfun:kotlin.Function1#invoke(1:0){}1:1-trampoline + 1 ([K][Suspend]Functions:1)
14 Medial                         0x1d534c kfun:androidx.compose.runtime.BroadcastFrameClock#sendFrame(kotlin.Long){} + 42 (BroadcastFrameClock.kt:42)
15 Medial                         0x3b8580 kfun:androidx.compose.ui.window.ComposeWindow.object-2.render#internal + 512 (ComposeScene.skiko.kt:512)
16 Medial                         0x3ce164 kfun:androidx.compose.ui.window.SkikoUIView.object-3.render#internal + 93 (SkikoUIView.kt:93)
17 Medial                         0x3c45f8 kfun:androidx.compose.ui.window.MetalRedrawer.draw#internal + 341 (MetalRedrawer.kt:341)
18 Medial                         0x3c59d4 kfun:androidx.compose.ui.window.MetalRedrawer.$<init>$lambda$0$FUNCTION_REFERENCE$0.$<bridge-UNN>invoke(){}#internal + 253 (MetalRedrawer.kt:253)
19 Medial                         0x90dea8 kfun:kotlin.Function0#invoke(){}1:0-trampoline + 1 ([K][Suspend]Functions:1)
20 Medial                         0x3c7fa0 kfun:androidx.compose.ui.window.DisplayLinkProxy.$imp:handleDisplayLinkTick#internal + 454 (MetalRedrawer.kt:454)
21 QuartzCore                     0x29328 CA::Display::DisplayLink::dispatch_items(unsigned long long, unsigned long long, unsigned long long)
22 QuartzCore                     0x146e68 CA::Display::DisplayLink::dispatch_deferred_display_links(unsigned int)
23 UIKitCore                      0x64dd94 _UIUpdateSequenceRun
24 UIKitCore                      0xcb2894 schedulerStepScheduledMainSection
25 UIKitCore                      0xcb1df0 runloopSourceCallback
26 CoreFoundation                 0xd3128 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__
27 CoreFoundation                 0xdf7b4 __CFRunLoopDoSource0
28 CoreFoundation                 0x645e8 __CFRunLoopDoSources0
29 CoreFoundation                 0x7a0d4 __CFRunLoopRun
30 CoreFoundation                 0x7f3ec CFRunLoopRunSpecific
31 GraphicsServices               0x135c GSEventRunModal
32 UIKitCore                      0x39cf58 -[UIApplication _run]
33 UIKitCore                      0x39cbbc UIApplicationMain
34 SwiftUI                        0x1bcc50 OUTLINED_FUNCTION_895
35 SwiftUI                        0x1231ec block_copy_helper.1
36 SwiftUI                        0x10d294 OUTLINED_FUNCTION_901
37 Medial                         0x8340 main (iOSApp.swift)
38 ???                            0x1a9a00dec (Missing)
DevSrSouza commented 7 months ago

On 1.0.0-rc08 this onEach function does not exist anymore. Could you try to update it to see if this fixes? If it does not fix, can you share the report on the new version?

I will investigate it. Can you also share your Navigator setup? Describe more how you are using Voyager.

The ScreenModelStore uses a ThreadSafeMap so kotlin.ConcurrentModificationException should not be happening unless our ThreadSafeMap is not working properly

DevSrSouza commented 7 months ago

Can you try this PR? https://github.com/adrielcafe/voyager/pull/245

Just checkout to the branch and run ./gradlew -Pversion="1.0.0-SNAPSHOT" publishToMavenLocal

Vaibhav2002 commented 7 months ago

Sure, I'll check it

Vaibhav2002 commented 7 months ago

On 1.0.0-rc08 this onEach function does not exist anymore. Could you try to update it to see if this fixes? If it does not fix, can you share the report on the new version?

I will investigate it. Can you also share your Navigator setup? Describe more how you are using Voyager.

The ScreenModelStore uses a ThreadSafeMap so kotlin.ConcurrentModificationException should not be happening unless our ThreadSafeMap is not working properly

It crashed on rc-08 as well This is my Navigator Setup

Navigator(startScreen) {
    this.navigator = it

    Scaffold(
        modifier = modifier,
        content = {
            Box(modifier = Modifier.padding(it)) {
                CurrentScreen()
            }
        },
        topBar = {
            if (it.lastItem.key in screensWithoutAppBar) return@Scaffold
            if (it.lastItem.key == SearchScreen.key)
                searchBarData?.let { data -> SearchBar(data) } ?: MedialAppBar(scrollBehavior)
            else MedialAppBar(scrollBehavior)
        },
    )
}
Vaibhav2002 commented 7 months ago

Can you try this PR? #245

Just checkout to the branch and run ./gradlew -Pversion="1.0.0-SNAPSHOT" publishToMavenLocal

Running this task fails

> Task :buildSrc:compileKotlin FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':buildSrc:compileKotlin'.
> Error while evaluating property 'compilerOptions.jvmTarget' of task ':buildSrc:compileKotlin'.
   > Failed to calculate the value of property 'jvmTarget'.
      > Unknown Kotlin JVM target: 21

I've even tried changing my java version, gradle JDK version to 21, nothing works

xuegao-tzx commented 6 months ago

I also have this problem when using the latest version of the library. How to solve it?

DevSrSouza commented 6 months ago

Fixed in 1.0.0-rc09, can you folks validate?

xuegao-tzx commented 6 months ago

Fixed in 1.0.0-rc09, can you folks validate?

Unfortunately, this bug does not seem to be resolved

Uncaught Kotlin exception: kotlin.ConcurrentModificationException
    at 0   Chat                               0x10538b9af        kfun:kotlin.Exception#<init>(kotlin.String?;kotlin.Throwable?){} + 143 
    at 1   Chat                               0x10538bbcf        kfun:kotlin.RuntimeException#<init>(kotlin.String?;kotlin.Throwable?){} + 143 
    at 2   Chat                               0x10538cc77        kfun:kotlin.ConcurrentModificationException#<init>(kotlin.String?;kotlin.Throwable?){} + 143 
    at 3   Chat                               0x10538cceb        kfun:kotlin.ConcurrentModificationException#<init>(){} + 95 
    at 4   Chat                               0x1053f1f97        kfun:kotlin.collections.HashMap.Itr#checkForComodification(){} + 243 
    at 5   Chat                               0x1053f211f        kfun:kotlin.collections.HashMap.KeysItr#next(){}1:0 + 203 
    at 6   Chat                               0x1054997ff        kfun:kotlin.collections.Iterator#next(){}1:0-trampoline + 99 
    at 7   Chat                               0x105473a13        kfun:kotlin.sequences.FilteringSequence.object-1.calcNext#internal + 223 
    at 8   Chat                               0x105473d5f        kfun:kotlin.sequences.FilteringSequence.object-1.hasNext#internal + 123 
    at 9   Chat                               0x10549972f        kfun:kotlin.collections.Iterator#hasNext(){}kotlin.Boolean-trampoline + 91 
    at 10  Chat                               0x1056f342f        kfun:cafe.adriel.voyager.navigator.Navigator#dispose(cafe.adriel.voyager.core.screen.Screen){} + 703 
    at 11  Chat                               0x1056fbda3        kfun:cafe.adriel.voyager.navigator.internal.object-2.dispose#internal + 1331 
    at 12  Chat                               0x1056d7acb        kfun:androidx.compose.runtime.DisposableEffectResult#dispose(){}-trampoline + 91 
    at 13  Chat                               0x10560314f        kfun:androidx.compose.runtime.DisposableEffectImpl.onForgotten#internal + 183 
withContext(Dispatchers.Main.immediate) {

            navigator.replaceAll(LoginSceen())
        }
or
navigator.replaceAll(LoginSceen())

Will report an error

DevSrSouza commented 6 months ago

Now it is broken in another place :S It will be fixed soon.

@InternalVoyagerApi
    public fun dispose(
        screen: Screen
    ) {
        ScreenLifecycleStore.remove(screen)
        stateKeys
            .toMutableSet() // Copy
            .filter { it.startsWith(screen.key) }
            .forEach { key ->
                stateHolder.removeState(key)
                stateKeys -= key
            }
    }
zeromod commented 6 months ago

Thanks for the fix @DevSrSouza , looking forward to the release 🙂. I am still not sure why is this crash related to 1.9.20 kotlin update, if anyone can explain the solution that would be great for learning.

Abadaar commented 6 months ago

Ah, this would fix the crash that I'm seeing. Also looking forward to the next release since I'm on Kotlin 1.9.20. :)

DevSrSouza commented 6 months ago

I have reproduced here and fix it on #249 .

DevSrSouza commented 6 months ago

Fixed on 1.0.0-rc10