smcameron / space-nerds-in-space

Multi-player spaceship bridge simulator game. Captain your starship through adventures with your friends. See https://smcameron.github.io/space-nerds-in-space
GNU General Public License v2.0
724 stars 73 forks source link

Potential problem with SDL2 windows and multi-threading #324

Closed smcameron closed 1 year ago

smcameron commented 1 year ago

This page https://wiki.libsdl.org/CategoryThread says the following:

NOTE: You should not expect to be able to create a window, render, or receive events on any thread other than the main one. For platform-specific exceptions or complicated options ask on the forums/mailing list.

However, snis_client does create a window and render in that window in a 2nd thread in splash_screen_fn(), and I did run into some multi-threading issues between SDL_PollEvent() and SDL_DestroyWindow(), supposedly fixed by edd07b574 -- which since that commit I haven't had any further trouble that I know of -- but what I am doing with splash_screen_fn() is apparently still not kosher.

There is another conversation here which is interesting: https://discourse.libsdl.org/t/bug-libsdl-not-thread-safe/17052/6

smcameron commented 1 year ago

Hmm, just trying to put the splash screen rendering into the main loop does not work because the main loop does not start until after everything the splash screen is supposed to be monitoring is already completed.

smcameron commented 1 year ago

To fix this "properly", maybe the thing to do is to make the splash screen a separate process and communicate progress updates to it via a pipe. Seems kind of silly that that's what it would require though.

smcameron commented 1 year ago

Fixed by: 82edd5fb9a7b8ed62cd924cd9eac466ffe7acbe0 Use a separate process instead of a thread for the splash screen