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
16.01k stars 1.17k forks source link

Unexpected or incorrect use of the Compose internal runtime API (Start/end imbalance) #3989

Closed Gaubee closed 1 week ago

Gaubee commented 10 months ago

Describe the bug I try to move my compositionLocalContext to another Compose Context, but got this error.

Affected platforms

Versions

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

  1. I use ComposeUIViewController to create an new ComposeWindow-1
  2. In ComposeWindow-1 I got the currentCompositionLocalContext
  3. I use ComposeUIViewController to create an new ComposeWindow-2
  4. I move currentCompositionLocalContext from ComposeWindow-1 to ComposeWindow-2
  5. See error

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

Screenshots

androidx.compose.runtime.ComposeRuntimeError: Compose Runtime internal error. Unexpected or incorrect use of the Compose internal runtime API (Start/end imbalance). Please report to Google or use https://goo.gle/compose-feedback
    at 0   iosApp                              0x102549f43        kfun:kotlin.Throwable#<init>(){} + 95 
    at 1   iosApp                              0x1025431a7        kfun:kotlin.Exception#<init>(){} + 87 
    at 2   iosApp                              0x1025433c7        kfun:kotlin.RuntimeException#<init>(){} + 87 
    at 3   iosApp                              0x102543967        kfun:kotlin.IllegalStateException#<init>(){} + 87 
    at 4   iosApp                              0x100b41f43        kfun:androidx.compose.runtime.ComposeRuntimeError#<init>(kotlin.String){} + 87 
    at 5   iosApp                              0x100b42287        kfun:androidx.compose.runtime#composeRuntimeError(kotlin.String){}kotlin.Nothing + 399 
    at 6   iosApp                              0x100b31e0b        kfun:androidx.compose.runtime.ComposerImpl.finalizeCompose#internal + 303 
    at 7   iosApp                              0x100b1fcf7        kfun:androidx.compose.runtime.ComposerImpl.endRoot#internal + 211 
    at 8   iosApp                              0x100b2ed43        kfun:androidx.compose.runtime.ComposerImpl.doCompose#internal + 2575 
    at 9   iosApp                              0x100b2e29f        kfun:androidx.compose.runtime.ComposerImpl#recompose(androidx.compose.runtime.collection.IdentityArrayMap<androidx.compose.runtime.RecomposeScopeImpl,androidx.compose.runtime.collection.IdentityArraySet<kotlin.Any>?>){}kotlin.Boolean + 551 
    at 10  iosApp                              0x100b4a29f        kfun:androidx.compose.runtime.CompositionImpl#recompose(){}kotlin.Boolean + 599 
    at 11  iosApp                              0x100c2f03f        kfun:androidx.compose.runtime.ControlledComposition#recompose(){}kotlin.Boolean-trampoline + 91 
    at 12  iosApp                              0x100b69013        kfun:androidx.compose.runtime.Recomposer.performRecompose#internal + 1363 
    at 13  iosApp                              0x100b6e8f3        kfun:androidx.compose.runtime.Recomposer.runRecomposeAndApplyChanges$lambda$4$lambda$3#internal + 2395 
    at 14  iosApp                              0x100b730bf        kfun:androidx.compose.runtime.Recomposer.$runRecomposeAndApplyChanges$lambda$4$lambda$3$FUNCTION_REFERENCE$13.invoke#internal + 107 
    at 15  iosApp                              0x100b7329f        kfun:androidx.compose.runtime.Recomposer.$runRecomposeAndApplyChanges$lambda$4$lambda$3$FUNCTION_REFERENCE$13.$<bridge-UNNB>invoke(kotlin.Long){}#internal + 123 
    at 16  iosApp                              0x1026796bf        kfun:kotlin.Function1#invoke(1:0){}1:1-trampoline + 107 
    at 17  iosApp                              0x100b15e53        kfun:androidx.compose.runtime.BroadcastFrameClock.FrameAwaiter.resume#internal + 439 
    at 18  iosApp                              0x100b16727        kfun:androidx.compose.runtime.BroadcastFrameClock#sendFrame(kotlin.Long){} + 499 
    at 19  iosApp                              0x101597913        kfun:androidx.compose.ui.ComposeScene#render(org.jetbrains.skia.Canvas;kotlin.Long){} + 879 
    at 20  iosApp                              0x1015fcc2b        kfun:androidx.compose.ui.window.ComposeWindow.object-2.render#internal + 247 
    at 21  iosApp                              0x1016423cf        kfun:androidx.compose.ui.window.SkikoUIViewDelegate#render(org.jetbrains.skia.Canvas;kotlin.Double){}-trampoline + 107 
    at 22  iosApp                              0x10161a4eb        kfun:androidx.compose.ui.window.SkikoUIView.object-3.render#internal + 227 
    at 23  iosApp                              0x101641e13        kfun:androidx.compose.ui.window.MetalRedrawerCallbacks#render(org.jetbrains.skia.Canvas;kotlin.Double){}-trampoline + 107 
    at 24  iosApp                              0x10160a50f        kfun:androidx.compose.ui.window.MetalRedrawer.draw#internal + 2587 
    at 25  iosApp                              0x10160b4a3        kfun:androidx.compose.ui.window.MetalRedrawer.<init>$lambda$0#internal + 435 
    at 26  iosApp                              0x10160c62f        kfun:androidx.compose.ui.window.MetalRedrawer.$<init>$lambda$0$FUNCTION_REFERENCE$0.invoke#internal + 71 
    at 27  iosApp                              0x10160c6ff        kfun:androidx.compose.ui.window.MetalRedrawer.$<init>$lambda$0$FUNCTION_REFERENCE$0.$<bridge-UNN>invoke(){}#internal + 71 
    at 28  iosApp                              0x10267ac27        kfun:kotlin.Function0#invoke(){}1:0-trampoline + 99 
    at 29  iosApp                              0x10160d447        kfun:androidx.compose.ui.window.DisplayLinkProxy.handleDisplayLinkTick#internal + 151 
    at 30  iosApp                              0x10160d4fb        kfun:androidx.compose.ui.window.DisplayLinkProxy.$imp:handleDisplayLinkTick#internal + 143 
    at 31  QuartzCore                          0x189dc34ab        _ZN2CA7Display15DisplayLinkItem9dispatch_ERNS_8SignPost8IntervalILNS2_11CAEventCodeE835322056EEE + 43 
    at 32  QuartzCore                          0x189dc46d3        _ZN2CA7Display11DisplayLink14dispatch_itemsEyyy + 803 
    at 33  QuartzCore                          0x189dc429f        _ZN2CA7Display11DisplayLink8callbackEP15_CADisplayTimeryyybPv + 631 
    at 34  QuartzCore                          0x189ecab9b        _ZL22display_timer_callbackP12__CFMachPortPvlS1_ + 335 
    at 35  CoreFoundation                      0x1803b84e3        __CFMachPortPerform + 171 
    at 36  CoreFoundation                      0x1803eeddb        __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 55 
    at 37  CoreFoundation                      0x1803ee3ab        __CFRunLoopDoSource1 + 495 
    at 38  CoreFoundation                      0x1803e89bb        __CFRunLoopRun + 2175 
    at 39  CoreFoundation                      0x1803e7d27        CFRunLoopRunSpecific + 571 
    at 40  GraphicsServices                    0x18e7cdbbf        GSEventRunModal + 159 
    at 41  UIKitCore                           0x1852bafdb        -[UIApplication _run] + 867 
    at 42  UIKitCore                           0x1852bec53        UIApplicationMain + 123 
    at 43  SwiftUI                             0x1c4b04523        OUTLINED_FUNCTION_70 + 499 
    at 44  SwiftUI                             0x1c4b043c3        OUTLINED_FUNCTION_70 + 147 
    at 45  SwiftUI                             0x1c4816107        OUTLINED_FUNCTION_2 + 91 
    at 46  iosApp                              0x100a4715f        $s6iosApp6iOSAppV5$mainyyFZ + 39 
    at 47  iosApp                              0x100a48593        main + 11 (/Users/kzf/Development/GitHub/dweb_browser/next/kmp/app/iosApp/iosApp/iOSApp.swift:<unknown>)
    at 48  dyld                                0x106841557        0x0 + 4404286807 
    at 49  ???                                 0x10622a0df        0x0 + 4397899999 
    at 50  ???                                 0xd93effffffffffff 0x0 + -2792513243946418177 
    Suppressed: kotlinx.coroutines.internal.DiagnosticCoroutineContextException: [androidx.compose.runtime.BroadcastFrameClock@f95e160, StandaloneCoroutine{Cancelling}@11e1e8d8, FlushCoroutineDispatcher@1333adc0]
        at 0   iosApp                              0x102549dab        kfun:kotlin.Throwable#<init>(kotlin.String?){} + 119 
        at 1   iosApp                              0x10254322f        kfun:kotlin.Exception#<init>(kotlin.String?){} + 115 
        at 2   iosApp                              0x10254344f        kfun:kotlin.RuntimeException#<init>(kotlin.String?){} + 115 
        at 3   iosApp                              0x1027a112b        kfun:kotlinx.coroutines.internal.DiagnosticCoroutineContextException#<init>(kotlin.coroutines.CoroutineContext){} + 167 
        at 4   iosApp                              0x10277166f        kfun:kotlinx.coroutines.internal#handleUncaughtCoroutineException(kotlin.coroutines.CoroutineContext;kotlin.Throwable){} + 647 
        at 5   iosApp                              0x10270d89f        kfun:kotlinx.coroutines#handleCoroutineException(kotlin.coroutines.CoroutineContext;kotlin.Throwable){} + 515 
        at 6   iosApp                              0x102700957        kfun:kotlinx.coroutines.StandaloneCoroutine.handleJobException#internal + 167 
        at 7   iosApp                              0x1027a9697        kfun:kotlinx.coroutines.JobSupport#handleJobException(kotlin.Throwable){}kotlin.Boolean-trampoline + 59 
        at 8   iosApp                              0x102718737        kfun:kotlinx.coroutines.JobSupport.finalizeFinishingState#internal + 1211 
        at 9   iosApp                              0x1027215d7        kfun:kotlinx.coroutines.JobSupport.tryMakeCompletingSlowPath#internal + 2231 
        at 10  iosApp                              0x102720ce7        kfun:kotlinx.coroutines.JobSupport.tryMakeCompleting#internal + 755 
        at 11  iosApp                              0x102720817        kfun:kotlinx.coroutines.JobSupport#makeCompletingOnce(kotlin.Any?){}kotlin.Any? + 379 
        at 12  iosApp                              0x1026fe8e7        kfun:kotlinx.coroutines.AbstractCoroutine#resumeWith(kotlin.Result<1:0>){} + 211 
        at 13  iosApp                              0x10267e3db        kfun:kotlin.coroutines.Continuation#resumeWith(kotlin.Result<1:0>){}-trampoline + 99 
        at 14  iosApp                              0x10254ddcb        kfun:kotlin.coroutines.native.internal.BaseContinuationImpl#resumeWith(kotlin.Result<kotlin.Any?>){} + 1163 
        at 15  iosApp                              0x10267e3db        kfun:kotlin.coroutines.Continuation#resumeWith(kotlin.Result<1:0>){}-trampoline + 99 
        at 16  iosApp                              0x10279a153        kfun:kotlinx.coroutines.UndispatchedCoroutine#afterResume(kotlin.Any?){} + 243 
        at 17  iosApp                              0x1027a4b4b        kfun:kotlinx.coroutines.AbstractCoroutine#afterResume(kotlin.Any?){}-trampoline + 59 
        at 18  iosApp                              0x1026fe943        kfun:kotlinx.coroutines.AbstractCoroutine#resumeWith(kotlin.Result<1:0>){} + 303 
        at 19  iosApp                              0x10267e3db        kfun:kotlin.coroutines.Continuation#resumeWith(kotlin.Result<1:0>){}-trampoline + 99 
        at 20  iosApp                              0x10254ddcb        kfun:kotlin.coroutines.native.internal.BaseContinuationImpl#resumeWith(kotlin.Result<kotlin.Any?>){} + 1163 
        at 21  iosApp                              0x10267e3db        kfun:kotlin.coroutines.Continuation#resumeWith(kotlin.Result<1:0>){}-trampoline + 99 
        at 22  iosApp                              0x10277d417        kfun:kotlinx.coroutines.internal.ScopeCoroutine#afterResume(kotlin.Any?){} + 243 
        at 23  iosApp                              0x1027a4b4b        kfun:kotlinx.coroutines.AbstractCoroutine#afterResume(kotlin.Any?){}-trampoline + 59 
        at 24  iosApp                              0x1026fe943        kfun:kotlinx.coroutines.AbstractCoroutine#resumeWith(kotlin.Result<1:0>){} + 303 
        at 25  iosApp                              0x10267e3db        kfun:kotlin.coroutines.Continuation#resumeWith(kotlin.Result<1:0>){}-trampoline + 99 
        at 26  iosApp                              0x10254ddcb        kfun:kotlin.coroutines.native.internal.BaseContinuationImpl#resumeWith(kotlin.Result<kotlin.Any?>){} + 1163 
        at 27  iosApp                              0x10267e3db        kfun:kotlin.coroutines.Continuation#resumeWith(kotlin.Result<1:0>){}-trampoline + 99 
        at 28  iosApp                              0x102775a43        kfun:kotlinx.coroutines.DispatchedTask#run(){} + 1679 
        at 29  iosApp                              0x1027a7f03        kfun:kotlinx.coroutines.Runnable#run(){}-trampoline + 91 
        at 30  iosApp                              0x1015a832f        kfun:androidx.compose.ui.platform.FlushCoroutineDispatcher.dispatch$lambda$1$lambda$0#internal + 411 
        at 31  iosApp                              0x1015a97b7        kfun:androidx.compose.ui.platform.FlushCoroutineDispatcher.$dispatch$lambda$1$lambda$0$FUNCTION_REFERENCE$4.invoke#internal + 75 
        at 32  iosApp                              0x1015a98b3        kfun:androidx.compose.ui.platform.FlushCoroutineDispatcher.$dispatch$lambda$1$lambda$0$FUNCTION_REFERENCE$4.$<bridge-UNN>invoke(){}#internal + 71 
        at 33  iosApp                              0x10267ac27        kfun:kotlin.Function0#invoke(){}1:0-trampoline + 99 
        at 34  iosApp                              0x1015a7cd7        kfun:androidx.compose.ui.platform.FlushCoroutineDispatcher.performRun#internal + 303 
        at 35  iosApp                              0x1015a84b7        kfun:androidx.compose.ui.platform.FlushCoroutineDispatcher.dispatch$lambda$1#internal + 239 
        at 36  iosApp                              0x1015a9263        kfun:androidx.compose.ui.platform.FlushCoroutineDispatcher.$dispatch$lambda$1$FUNCTION_REFERENCE$0.invoke#internal + 139 
        at 37  iosApp                              0x10267e9df        kfun:kotlin.Function2#invoke(1:0;1:1){}1:2-trampoline + 115 
        at 38  iosApp                              0x102551443        kfun:kotlin.coroutines.intrinsics.object-4.invokeSuspend#internal + 731 
        at 39  iosApp                              0x10267e2fb        kfun:kotlin.coroutines.native.internal.BaseContinuationImpl#invokeSuspend(kotlin.Result<kotlin.Any?>){}kotlin.Any?-trampoline + 67 
        at 40  iosApp                              0x10254dbaf        kfun:kotlin.coroutines.native.internal.BaseContinuationImpl#resumeWith(kotlin.Result<kotlin.Any?>){} + 623 
        at 41  iosApp                              0x10267e3db        kfun:kotlin.coroutines.Continuation#resumeWith(kotlin.Result<1:0>){}-trampoline + 99 
        at 42  iosApp                              0x102775aff        kfun:kotlinx.coroutines.DispatchedTask#run(){} + 1867 
        at 43  iosApp                              0x1027a7f03        kfun:kotlinx.coroutines.Runnable#run(){}-trampoline + 91 
        at 44  iosApp                              0x1027a3637        kfun:kotlinx.coroutines.DarwinMainDispatcher.dispatch$lambda$0#internal + 67 
        at 45  iosApp                              0x1027a38b3        kfun:kotlinx.coroutines.DarwinMainDispatcher.$dispatch$lambda$0$FUNCTION_REFERENCE$1.invoke#internal + 71 
        at 46  iosApp                              0x1027a3983        kfun:kotlinx.coroutines.DarwinMainDispatcher.$dispatch$lambda$0$FUNCTION_REFERENCE$1.$<bridge-UNN>invoke(){}#internal + 71 
        at 47  iosApp                              0x10267ac27        kfun:kotlin.Function0#invoke(){}1:0-trampoline + 99 
        at 48  iosApp                              0x1027a48c7        _6f72672e6a6574627261696e732e6b6f746c696e783a6b6f746c696e782d636f726f7574696e65732d636f72652f6f70742f6275696c644167656e742f776f726b2f343465633665383530643563363366302f6b6f746c696e782d636f726f7574696e65732d636f72652f6e617469766544617277696e2f7372632f44697370617463686572732e6b74_knbridge13 + 191 
        at 49  libdispatch.dylib                   0x18016a4f3        _dispatch_call_block_and_release + 23 
        at 50  libdispatch.dylib                   0x18016bd3b        _dispatch_client_callout + 15 
        at 51  libdispatch.dylib                   0x18017ab23        _dispatch_main_queue_drain + 1271 
        at 52  libdispatch.dylib                   0x18017a61b        _dispatch_main_queue_callback_4CF + 39 
        at 53  CoreFoundation                      0x1803ee1b3        __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 11 
        at 54  CoreFoundation                      0x1803e88cb        __CFRunLoopRun + 1935 
        at 55  CoreFoundation                      0x1803e7d27        CFRunLoopRunSpecific + 571 
        ... and 11 more common stack frames skipped

image

Additional context

I have post this bug to compose-mutilplatform-core team: https://youtrack.jetbrains.com/issue/KT-63869/androidx.compose.runtime.ComposeRuntimeError-Compose-Runtime-internal-error.-Unexpected-or-incorrect-use-of-the-Compose-internal

mazunin-v-jb commented 10 months ago

Hello! Thanks for submitting the issue. Could you please send us a minimal reproducible example too?

okushnikov commented 2 months ago

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