From fae50a3c75413a4eb72cf1465551be9416f6bca0 Mon Sep 17 00:00:00 2001 From: sguo35 Date: Tue, 29 Mar 2022 00:09:50 -0700 Subject: [PATCH] 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. --- src/input_common/drivers/sdl_driver.cpp | 6 ++++++ src/yuzu/main.cpp | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/src/input_common/drivers/sdl_driver.cpp b/src/input_common/drivers/sdl_driver.cpp index c17ea305ef..41c335cc5c 100644 --- a/src/input_common/drivers/sdl_driver.cpp +++ b/src/input_common/drivers/sdl_driver.cpp @@ -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; diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index 3b7058a2bf..327d4de0e9 100644 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp @@ -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.