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

Examples assume they run on a single thread #16

Closed
strangebroadcasts opened this issue Oct 10, 2017 · 3 comments
Closed

Examples assume they run on a single thread #16

strangebroadcasts opened this issue Oct 10, 2017 · 3 comments

Comments

@strangebroadcasts
Copy link

strangebroadcasts commented Oct 10, 2017

Raylib drawing commands aren't thread-safe - which isn't a huge deal, since OpenGL isn't to begin with - but since the examples don't lock an OS thread, drawing commands could potentially be issued on a different thread after garbage collection (as in this issue).

The quick and dirty way of fixing this would be to manually call runtime.LockOSThread in the examples. However, this seems like a common enough gotcha with Go and graphics libraries that it might be a good idea to handle it in the binding somehow - possibly by providing a mainthread-style helper?

@gen2brain
Copy link
Owner

There is this page that can be linked from README https://github.com/golang/go/wiki/LockOSThread . SDL bindings has this helper veandco/go-sdl2@bc9d5d1 with some examples how to use it https://github.com/veandco/go-sdl2/blob/master/examples/render_goroutines/render_goroutines.go but now sure if that can work here, will need some time to test.

@strangebroadcasts
Copy link
Author

strangebroadcasts commented Oct 11, 2017

An alternative to the helper would be to create a Context struct (or similar) maintaining an internal work queue, similar to what mobile/gl does, with all raylib functions being defined as methods on that struct. That'd be a little more work, but it would remove the need to wrap everything in Do calls.

e: thinking on it a bit, I think it should be possible to fork and lock a thread in InitWindow, make it listen on a package-level work queue, with functions rewritten to enqueue work on that thread. That would allow 100% API compatibility at the cost of adding communication overhead. Will try to get a proof of concept running when I have the time.

@JupiterRider
Copy link
Contributor

@gen2brain
I think we can close this issue after nearly 6 years.
Its fixed with using runtime.LockOSThread(): https://github.com/gen2brain/raylib-go/blob/master/raylib/raylib.go#L51

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

No branches or pull requests

3 participants