Properly exit event loop thread on exit

This commit is contained in:
rainmakerv3 2025-06-26 10:50:39 +08:00
parent f1b6342313
commit 06407be5a7
2 changed files with 9 additions and 2 deletions

View File

@ -124,8 +124,9 @@ ControlSettings::ControlSettings(std::shared_ptr<GameInfoClass> game_info_get, b
QObject::connect(RemapWrapper, &SdlEventWrapper::Wrapper::SDLEvent, this, QObject::connect(RemapWrapper, &SdlEventWrapper::Wrapper::SDLEvent, this,
&ControlSettings::processSDLEvents); &ControlSettings::processSDLEvents);
if (!GameRunning) if (!GameRunning) {
QFuture<void> future = QtConcurrent::run(&ControlSettings::pollSDLEvents, this); Polling = QtConcurrent::run(&ControlSettings::pollSDLEvents, this);
}
} }
void ControlSettings::SaveControllerConfig(bool CloseOnSave) { void ControlSettings::SaveControllerConfig(bool CloseOnSave) {
@ -926,6 +927,11 @@ void ControlSettings::Cleanup() {
SDL_CloseGamepad(gamepad); SDL_CloseGamepad(gamepad);
if (!GameRunning) { if (!GameRunning) {
SDL_Event quitLoop{};
quitLoop.type = SDL_EVENT_QUIT;
SDL_PushEvent(&quitLoop);
Polling.waitForFinished();
SDL_QuitSubSystem(SDL_INIT_GAMEPAD); SDL_QuitSubSystem(SDL_INIT_GAMEPAD);
SDL_QuitSubSystem(SDL_INIT_EVENTS); SDL_QuitSubSystem(SDL_INIT_EVENTS);
SDL_Quit(); SDL_Quit();

View File

@ -63,6 +63,7 @@ private:
QPushButton* MappingButton; QPushButton* MappingButton;
SDL_Gamepad* gamepad = nullptr; SDL_Gamepad* gamepad = nullptr;
SdlEventWrapper::Wrapper* RemapWrapper; SdlEventWrapper::Wrapper* RemapWrapper;
QFuture<void> Polling;
const std::vector<std::string> ControllerInputs = { const std::vector<std::string> ControllerInputs = {
"cross", "circle", "square", "triangle", "l1", "cross", "circle", "square", "triangle", "l1",