STREGAsGate / Raylib

A Swift package for Raylib. Builds Raylib from source so no need to fiddle with libraries. Just add as a dependency in you game package and go!
MIT License
106 stars 13 forks source link

program quits when using async/await #15

Open amnykon opened 11 months ago

amnykon commented 11 months ago

When using async/await, The program quits. I have tried only using Raylib commands on the Main Actor and main thread. Still crashes if there is an await.

I got it working with the following work around; however, this ties up the main thread with a semaphore.

    @MainActor static func main() {
        Raylib.initWindow(800, 450, "test")
        Raylib.setTargetFPS(60)

        while Raylib.windowShouldClose == false {
            let semaphore = DispatchSemaphore(value: 0)
            DispatchQueue.global().async {
                Task {
                    await update()
                    semaphore.signal()
                }
            }
            semaphore.wait()
            draw()
        }

        Raylib.closeWindow()
    }
7ombie commented 2 weeks ago

This sounds like it could be a pretty serious issue. Swift is big on concurrency. It'd be nice to know more at least.