Skip to content

Can't use MsgBox in worker #34

@ObserverOfTime

Description

@ObserverOfTime

I'm trying to run a background task using a worker and display a message when an exception is caught.

Here's a minimal reproducible example:

package example

import kotlin.native.concurrent.TransferMode
import kotlin.native.concurrent.Worker
import libui.ktx.*

fun main() = appWindow("Test", 800, 600) {
    vbox {
        button("Test") {
            action {
                Worker.start().execute(TransferMode.UNSAFE, {}) {
                    MsgBox("This doesn't work")
                }
            }
        }
    }
}

That fails with this error when clicking the button:

Uncaught Kotlin exception: kotlin.native.IncorrectDereferenceException: Trying to access top level value not marked as @ThreadLocal or @SharedImmutable from non-main thread
        at ThrowIncorrectDereferenceException (0x232c5c)
        at kfun:example.$<bridge-UNNN>main$lambda-2$<anonymous>_3_6$<anonymous>_5_8(kotlin.Unit)#internal (0x2485c0)
        at _ZN6Worker19processQueueElementEb (0x25d2ac)
        at _ZN12_GLOBAL__N_113workerRoutineEPv (0x25d96d)
        at  (0x7f70ac741422)
        at clone (0x7f70ac656bf3)
        at  ((nil))

  • platform: Linux x86_64
  • kotlin: 1.3.72
  • kotlin-libui: 0.1.7
  • coroutines: 1.3.5-native-mt

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions