Open SirVer opened 7 years ago
Interesting. I don't have ready access to any macs at the moment, but under Windows and Linux it works fine, I believe. I did most of the development on Linux, and I just tested it on Windows 10 right now. I'll try to get with someone who has a MacBook and see if I can reproduce the issue.
From testing this out on a friend's MacBook, the UI thread is inexplicably dying when it calls SDL2's event poll function. It's leaving no stack trace... it appears to be terminating in the C code of SDL2, from the few minutes that I had access to a Mac to look at this issue. Reading around, this seems similar to issues that are running rampant in the Ruby community since users upgraded to macOS High Sierra.
It could be unrelated to High Sierra, and it would be interesting to see if this issue is reproducible on earlier versions of macOS. Are you running High Sierra?
My code isn't fork
ing though, so I don't know. The only other thing I can think of is that maybe macOS will not allow a thread other than the main thread to handle UI stuff. If that's the case, that would be a huge problem.
I did not read the code, but are you using SDL2 according to its limitation? Basically, there are two rules that I know of:
Together they usually mean that all interactions with SDL2 besides audio must be made in the same thread or you run into issues on one platform or another.
I've been operating under the tested assumption that you just have to interact with SDL2 from only one thread, which works great on Windows and Linux. Number 2 is explicitly being handled correctly, since SDL2 is not thread safe. The poor ergonomics of requiring the user to run their own stuff in a secondary thread make me concerned about what fixing this issue might involve. The other alternative could be to just have a way to run everything synchronously, which would be a different ergonomic compromise over the current design.
As I don't have a Mac, testing this issue as changes are made to see if it is fixed is difficult.
According to here,
you can only call this function in the thread that set the video mode.
Since all SDL2 initialization and operations are running from a single background thread, it is surely that same thread which set the video mode, unless macOS does some kind of implicit video mode initialization for every program that runs prior to handing control over to that program.
If you can help with this issue, that would be great, but otherwise macOS support may not come until someone else helps.
I wanted to check out the examples, unfortunately they do not seem to work on OS X: