Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Async works with linux+gtk, same code fails with windows native #174

Open
arkanoid87 opened this issue Apr 21, 2023 · 0 comments
Open

Async works with linux+gtk, same code fails with windows native #174

arkanoid87 opened this issue Apr 21, 2023 · 0 comments

Comments

@arkanoid87
Copy link

By polling the global dispatcher from the queueMain hook I can successfully implement async logic in GUI thread.

This works nicely on linux with GTK, but on windows native the canvas doesn't update and remains completely black for some reason

here a minimal test

$ nim c winfail.nim # compiles and run correctly on linux, compiles but GUI hangs on windows (yet app queueMain is called)
$ nim r -d:mingw --cpu:i386 winfail.nim # same result when cross compiling

winfail.nim

import asyncdispatch, random
import nigui


var
    window: Window
    thread: Thread[void]
    asyncQueue: seq[proc () {.async.}] = @[]


proc delayAlert {.async.} =
    await sleepAsync(3000)
    window.alert("Hello, World!")


proc main {.async.} =
    var body = newLayoutContainer(Layout_Vertical)
    window.add(body)

    var fooButton = newButton("fooButton")
    body.add(fooButton)
    fooButton.onClick = proc(event: ClickEvent) =
        asyncQueue.add delayAlert

    var fooLabel = newLabel("fooLabel")
    body.add(fooLabel)

    while true:
        let ransString = $rand(0..100)
        echo ransString
        fooLabel.text = ransString
        await sleepAsync 100


proc keepWheelSpinning*() {.async.} =
    while true:
        echo "spinning"
        for asyncProc in asyncQueue:
            asyncCheck asyncProc()
        asyncQueue.setLen(0)
        await sleepAsync 100



app.init()
window = newWindow("Test")
window.show()


proc asyncPoll() =
    {.gcsafe.}:
        poll()
        app.queueMain(asyncPoll)

proc asyncStart() =
    {.gcsafe.}:
        app.queueMain(asyncPoll)

createThread(thread, asyncStart)
asyncCheck keepWheelSpinning()
asyncQueue.add main

app.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants