Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[citool] run MIDI input callback on kotlinx.coroutines UI thread.
It is not very ideal, but we run some non-UI code in UI context... Compose Compiler cannot seem to track JNI invocations. We use RtMidi input callbacks that runs JVM code through its C(++) callbacks. As a consequence, the Compose Compiler does not wrap any access to the composable code with UI thread dispatcher, and Awt threading error occurs on desktop. Any MidiAccess implementation could involve JNI invocations (e.g. AlsaMidiAccess) and the same kind of problem would occur. The error that could be dumped by this `runInUIContext`, removing `uiScope.launch { ...}` wrapper is like: ``` java.lang.IllegalStateException: Method should be called from AWT event dispatch thread at org.jetbrains.skiko.SkiaLayer.needRedraw(SkiaLayer.awt.kt:517) at androidx.compose.ui.awt.WindowComposeBridge.onComposeInvalidation(WindowComposeBridge.desktop.kt:108) at androidx.compose.ui.awt.ComposeBridge$scene$1.invoke(ComposeBridge.desktop.kt:164) at androidx.compose.ui.awt.ComposeBridge$scene$1.invoke(ComposeBridge.desktop.kt:163) at androidx.compose.ui.ComposeScene.invalidateIfNeeded(ComposeScene.skiko.kt:198) at androidx.compose.ui.ComposeScene.access$invalidateIfNeeded(ComposeScene.skiko.kt:68) at androidx.compose.ui.ComposeScene$snapshotChanges$1.invoke(ComposeScene.skiko.kt:359) at androidx.compose.ui.ComposeScene$snapshotChanges$1.invoke(ComposeScene.skiko.kt:359) at androidx.compose.ui.CommandList.add(CommandList.desktop.kt:51) at androidx.compose.ui.ComposeScene$attach$4.invoke(ComposeScene.skiko.kt:375) at androidx.compose.ui.ComposeScene$attach$4.invoke(ComposeScene.skiko.kt:375) at androidx.compose.ui.platform.SkiaBasedOwner$snapshotObserver$1.invoke(SkiaBasedOwner.skiko.kt:155) at androidx.compose.ui.platform.SkiaBasedOwner$snapshotObserver$1.invoke(SkiaBasedOwner.skiko.kt:154) at androidx.compose.runtime.snapshots.SnapshotStateObserver.sendNotifications(SnapshotStateObserver.kt:81) at androidx.compose.runtime.snapshots.SnapshotStateObserver.access$sendNotifications(SnapshotStateObserver.kt:41) at androidx.compose.runtime.snapshots.SnapshotStateObserver$applyObserver$1.invoke(SnapshotStateObserver.kt:48) at androidx.compose.runtime.snapshots.SnapshotStateObserver$applyObserver$1.invoke(SnapshotStateObserver.kt:46) at androidx.compose.runtime.snapshots.SnapshotKt.advanceGlobalSnapshot(Snapshot.kt:1825) at androidx.compose.runtime.snapshots.SnapshotKt.takeNewSnapshot(Snapshot.kt:1843) at androidx.compose.runtime.snapshots.SnapshotKt.access$takeNewSnapshot(Snapshot.kt:1) at androidx.compose.runtime.snapshots.GlobalSnapshot.takeNestedMutableSnapshot(Snapshot.kt:1352) at androidx.compose.runtime.snapshots.Snapshot$Companion.takeMutableSnapshot(Snapshot.kt:405) at androidx.compose.runtime.snapshots.Snapshot$Companion.takeMutableSnapshot$default(Snapshot.kt:401) at dev.atsushieno.ktmidi.citool.view.ViewModel$1.invoke(ViewModel.kt:96) ```
- Loading branch information