1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
diff --git a/firmware/target/hosted/sdl/button-sdl.c b/firmware/target/hosted/sdl/button-sdl.c
index 629d3aa..e9fc037 100644
--- a/firmware/target/hosted/sdl/button-sdl.c
+++ b/firmware/target/hosted/sdl/button-sdl.c
@@ -176,7 +176,6 @@ void gui_message_loop(void)
             case SDL_QUIT:
             {
                 sim_exit_irq_handler();
-                SDL_Quit();
                 exit(EXIT_SUCCESS);
                 break;
             }
diff --git a/firmware/target/hosted/sdl/thread-sdl.c b/firmware/target/hosted/sdl/thread-sdl.c
index 28a9cb8..3b1df8c 100644
--- a/firmware/target/hosted/sdl/thread-sdl.c
+++ b/firmware/target/hosted/sdl/thread-sdl.c
@@ -566,7 +566,9 @@ void remove_thread(unsigned int thread_id)

 void thread_exit(void)
 {
-    remove_thread(THREAD_ID_CURRENT);
+    struct thread_entry *t = thread_id_entry(THREAD_ID_CURRENT);
+    if (t->context.t != NULL)
+        remove_thread(t->id);
 }

 void thread_wait(unsigned int thread_id)