Rok Oblak
09/12/2024, 1:59 PMval scope = rememberCoroutineScope()
val fileChooser = remember {
JFileChooser()
}
Button(onClick = {
scope.launch {
val result = fileChooser.showOpenDialog(null)
}
}, content = { Text("Click to crash") })
Fatal exception in coroutines machinery for DispatchedContinuation[FlushCoroutineDispatcher@478b4af6, Continuation at androidx.compose.foundation.gestures.TapGestureDetectorKt$detectTapAndPress$2$1$4.invokeSuspend(TapGestureDetector.kt)@40916d9b]. Please read KDoc to 'handleFatalException' method and report this incident to maintainers"
This started with Compose version 1.7.0 Beta02.
Coroutines 1.9.0-RC2
It only happens if I show the fileChoose dialog inside the scope. (The reason for the scope is other code that I have which I did not include).
Crashlog in thread.Rok Oblak
09/12/2024, 2:01 PMAlexander Maryanovsky
09/12/2024, 2:10 PMRok Oblak
09/12/2024, 2:13 PMtry {
scope.launch {
try {
val result = fileChooser.showOpenDialog(null)
} catch (e: Throwable) {
e.printStackTrace()
}
}
} catch (e: Throwable) {
e.printStackTrace()
}
Nope, neither catch caught anythingRok Oblak
09/12/2024, 5:09 PMscope.launch(<http://Dispatchers.IO|Dispatchers.IO>)
seems to solve the issue. Though I would consider it just a workaround...Alexander Maryanovsky
09/12/2024, 6:40 PMshowOpenDialog
blocks the calling thread, which in your case is the main event dispatching thread. It means all the UI is going to be “stuck” while your dialog is open. The exception is probably related to that, seeing as it goes away if you use a different thread.
I’d suggest to do it like this
fun main() = singleWindowApplication {
Column {
var showFileChooser by remember { mutableStateOf(false) }
Button(
onClick = { showFileChooser = true },
content = { Text("Click to crash") }
)
CircularProgressIndicator()
if (showFileChooser) {
DisposableEffect(Unit) {
val chooser = JFileChooser()
val thread = thread {
chooser.showOpenDialog(null)
}
onDispose {
chooser.cancelSelection()
thread.join()
}
}
}
}
}
Alexander Maryanovsky
09/12/2024, 6:41 PMRok Oblak
09/12/2024, 6:51 PM