build-macos: fix SDL input poll crash

macOS kills apps that interact with the UX
from anything but the main thread. Let the frontend
handle the inputs on macOS so this doesn't happen.
This commit is contained in:
sguo35
2022-03-29 00:09:50 -07:00
parent 8aecf77d77
commit fae50a3c75
2 changed files with 10 additions and 0 deletions

View File

@@ -419,7 +419,13 @@ SDLDriver::SDLDriver(std::string input_engine_) : InputEngine(std::move(input_en
SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_XBOX, "0");
// If the frontend is going to manage the event loop, then we don't start one here
#ifdef __APPLE__
// macOS will crash the application if any thread but the main one
// tries to interact with the UX in any way.
start_thread = false;
#else
start_thread = SDL_WasInit(SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER) == 0;
#endif
if (start_thread && SDL_Init(SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER) < 0) {
LOG_CRITICAL(Input, "SDL_Init failed with: {}", SDL_GetError());
return;

View File

@@ -296,7 +296,11 @@ GMainWindow::GMainWindow()
ui->action_Fullscreen->setChecked(false);
#if defined(HAVE_SDL2) && !defined(_WIN32)
#ifdef __APPLE__
SDL_InitSubSystem(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER);
#else
SDL_InitSubSystem(SDL_INIT_VIDEO);
#endif
// SDL disables the screen saver by default, and setting the hint
// SDL_HINT_VIDEO_ALLOW_SCREENSAVER doesn't seem to work, so we just enable the screen saver
// for now.