From 4c59498f14d0ee684ca5a69a9e3b79abf274c88a Mon Sep 17 00:00:00 2001 From: Andrew Alderwick Date: Sat, 9 Apr 2022 12:22:24 +0100 Subject: [PATCH] (Windows) Fix uxnemu freezing on exit. --- src/uxnemu.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/uxnemu.c b/src/uxnemu.c index 05568a9..f6614d9 100644 --- a/src/uxnemu.c +++ b/src/uxnemu.c @@ -16,6 +16,9 @@ #include "devices/controller.h" #include "devices/mouse.h" #include "devices/datetime.h" +#ifdef _WIN32 +#include +#endif #pragma GCC diagnostic pop #pragma clang diagnostic pop @@ -40,6 +43,7 @@ static SDL_Texture *gTexture; static SDL_Renderer *gRenderer; static SDL_AudioDeviceID audio_id; static SDL_Rect gRect; +static SDL_Thread *stdin_thread; /* devices */ @@ -179,7 +183,7 @@ init(void) audio0_event = SDL_RegisterEvents(POLYPHONY); redraw_event = SDL_RegisterEvents(1); interrupt_event = SDL_RegisterEvents(1); - SDL_DetachThread(SDL_CreateThread(stdin_handler, "stdin", NULL)); + SDL_DetachThread(stdin_thread = SDL_CreateThread(stdin_handler, "stdin", NULL)); SDL_DetachThread(SDL_CreateThread(redraw_handler, "redraw", NULL)); SDL_StartTextInput(); SDL_ShowCursor(SDL_DISABLE); @@ -507,7 +511,12 @@ main(int argc, char **argv) if(!loaded && !start(&u, "launcher.rom")) return error("usage", "uxnemu [-s scale] file.rom"); run(&u); +#ifdef _WIN32 +#pragma GCC diagnostic ignored "-Wint-to-pointer-cast" + TerminateThread((HANDLE)SDL_GetThreadID(stdin_thread), 0); +#else close(0); /* make stdin thread exit */ +#endif SDL_Quit(); return 0; }