<another topic> Not sure if this is a bug or...
# compose
a
<another topic> Not sure if this is a bug or I did something illegal, but the stacktrace is hard to understand. I’m trying to dispose the ServiceConnection but the app crashes when the composable is disposed. Code and the exception in the thread 👇
Copy code
val serviceConnection = remember {
        object : ServiceConnection {
            override fun onServiceConnected(name: ComponentName?, service: IBinder?) {
                Timber.e("connected to service")
            }

            override fun onServiceDisconnected(name: ComponentName?) {
                Timber.e("disconnected to service")
            }
        }
    }
    DisposableEffect(serviceConnection) {
        onDispose {
            context.unbindService(serviceConnection)
        }
    }
Causes this weird crash
Copy code
E/AndroidRuntime: FATAL EXCEPTION: main
    Process: <http://com.example.app|com.example.app>, PID: 14693
    java.lang.IllegalStateException: pending composition has not been applied
        at androidx.compose.runtime.CompositionImpl.drainPendingModificationsForCompositionLocked(Composition.kt:420)
        at androidx.compose.runtime.CompositionImpl.composeContent(Composition.kt:452)
        at androidx.compose.runtime.Recomposer.composeInitial$runtime_release(Recomposer.kt:702)
        at androidx.compose.runtime.ComposerImpl$CompositionContextImpl.composeInitial$runtime_release(Composer.kt:2913)
        at androidx.compose.runtime.ComposerImpl$CompositionContextImpl.composeInitial$runtime_release(Composer.kt:2913)
        at androidx.compose.runtime.CompositionImpl.setContent(Composition.kt:409)
        at androidx.compose.ui.layout.SubcomposeLayoutState.subcomposeInto(SubcomposeLayout.kt:186)
        at androidx.compose.ui.layout.SubcomposeLayoutState.access$subcomposeInto(SubcomposeLayout.kt:108)
        at androidx.compose.ui.layout.SubcomposeLayoutState$subcompose$2.invoke(SubcomposeLayout.kt:162)
        at androidx.compose.ui.layout.SubcomposeLayoutState$subcompose$2.invoke(SubcomposeLayout.kt:160)
        at androidx.compose.runtime.snapshots.SnapshotStateObserver.withNoObservations(SnapshotStateObserver.kt:137)
        at androidx.compose.ui.node.OwnerSnapshotObserver.withNoSnapshotReadObservation$ui_release(OwnerSnapshotObserver.kt:49)
        at androidx.compose.ui.node.LayoutNode.withNoSnapshotReadObservation$ui_release(LayoutNode.kt:1054)
        at androidx.compose.ui.layout.SubcomposeLayoutState.subcompose(SubcomposeLayout.kt:160)
        at androidx.compose.ui.layout.SubcomposeLayoutState.subcompose$ui_release(SubcomposeLayout.kt:154)
        at androidx.compose.ui.layout.SubcomposeLayoutState$Scope.subcompose(SubcomposeLayout.kt:254)
        at androidx.compose.material.ScaffoldKt$ScaffoldLayout$1$1$1.invoke(Scaffold.kt:303)
        at androidx.compose.material.ScaffoldKt$ScaffoldLayout$1$1$1.invoke(Scaffold.kt:230)
        at androidx.compose.ui.layout.MeasureScope$layout$1.placeChildren(MeasureScope.kt:68)
        at androidx.compose.ui.layout.SubcomposeLayoutState$createMeasurePolicy$1$measure$1.placeChildren(SubcomposeLayout.kt:226)
        at androidx.compose.ui.node.LayoutNode$layoutChildren$1.invoke(LayoutNode.kt:902)
        at androidx.compose.ui.node.LayoutNode$layoutChildren$1.invoke(LayoutNode.kt:886)
        at androidx.compose.runtime.snapshots.Snapshot$Companion.observe(Snapshot.kt:1787)
        at androidx.compose.runtime.snapshots.SnapshotStateObserver.observeReads(SnapshotStateObserver.kt:116)
        at androidx.compose.ui.node.OwnerSnapshotObserver.observeReads$ui_release(OwnerSnapshotObserver.kt:75)
        at androidx.compose.ui.node.OwnerSnapshotObserver.observeLayoutSnapshotReads$ui_release(OwnerSnapshotObserver.kt:56)
        at androidx.compose.ui.node.LayoutNode.layoutChildren(LayoutNode.kt:886)
        at androidx.compose.ui.node.LayoutNode.onNodePlaced$ui_release(LayoutNode.kt:874)
        at androidx.compose.ui.node.InnerPlaceable.placeAt-f8xVGno(InnerPlaceable.kt:108)
        at androidx.compose.ui.layout.Placeable.access$placeAt-f8xVGno(Placeable.kt:31)
        at androidx.compose.ui.layout.Placeable$PlacementScope.place-70tqf50(Placeable.kt:358)
        at androidx.compose.ui.node.OuterMeasurablePlaceable.placeAt-f8xVGno(OuterMeasurablePlaceable.kt:149)
        at androidx.compose.ui.node.OuterMeasurablePlaceable.replace(OuterMeasurablePlaceable.kt:161)
        at androidx.compose.ui.node.LayoutNode.replace$ui_release(LayoutNode.kt:791)
        at androidx.compose.ui.node.MeasureAndLayoutDelegate.measureAndLayout(MeasureAndLayoutDelegate.kt:220)
        at androidx.compose.ui.platform.AndroidComposeView.measureAndLayout(AndroidComposeView.android.kt:508)
        at androidx.compose.ui.platform.AndroidComposeView.dispatchDraw(AndroidComposeView.android.kt:653)
        at android.view.View.draw(View.java:23904)
        at android.view.View.updateDisplayListIfDirty(View.java:22776)
        at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:5320)
        at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:5292)
        at android.view.View.updateDisplayListIfDirty(View.java:22731)
2021-05-14 03:30:15.922 14693-14693/com.example.app E/AndroidRuntime:     at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:5320)
        at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:5292)
        at android.view.View.updateDisplayListIfDirty(View.java:22731)
        at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:5320)
        at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:5292)
        at android.view.View.updateDisplayListIfDirty(View.java:22731)
        at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:5320)
        at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:5292)
        at android.view.View.updateDisplayListIfDirty(View.java:22731)
        at android.view.ThreadedRenderer.updateViewTreeDisplayList(ThreadedRenderer.java:579)
        at android.view.ThreadedRenderer.updateRootDisplayList(ThreadedRenderer.java:585)
        at android.view.ThreadedRenderer.draw(ThreadedRenderer.java:662)
        at android.view.ViewRootImpl.draw(ViewRootImpl.java:4994)
        at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:4701)
        at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:3818)
        at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:2575)
        at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:9910)
        at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1010)
        at android.view.Choreographer.doCallbacks(Choreographer.java:809)
        at android.view.Choreographer.doFrame(Choreographer.java:744)
        at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:995)
        at android.os.Handler.handleCallback(Handler.java:938)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:246)
        at android.app.ActivityThread.main(ActivityThread.java:8512)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)