From 8158b54f72ea80ef332a7165be137ca894260ea3 Mon Sep 17 00:00:00 2001 From: Vasiliy Tereshkov Date: Fri, 5 Jul 2024 23:14:45 +0200 Subject: [PATCH] Fix #187 and #188 --- demos/space-shooter/main.um | 2 +- demos/space-shooter/score | 2 +- src/main.c | 24 +++++++++++++++--------- src/window.c | 11 ++++++----- 4 files changed, 23 insertions(+), 16 deletions(-) diff --git a/demos/space-shooter/main.um b/demos/space-shooter/main.um index 088c5328..a71ccfe5 100644 --- a/demos/space-shooter/main.um +++ b/demos/space-shooter/main.um @@ -44,7 +44,7 @@ fn init*() { case global::GAME: game::handle() case global::NONE: - exit(0) + window::requestExit() } }) } diff --git a/demos/space-shooter/score b/demos/space-shooter/score index 405e0570..f70d7bba 100644 --- a/demos/space-shooter/score +++ b/demos/space-shooter/score @@ -1 +1 @@ -127 \ No newline at end of file +42 \ No newline at end of file diff --git a/src/main.c b/src/main.c index 2029afb9..ac843bae 100644 --- a/src/main.c +++ b/src/main.c @@ -122,11 +122,14 @@ th_deinit() umprofPrintInfo(stdout, arr, len); } } - + UmkaStackSlot s; - umkaCall(thg->umka, thg->umth_destroy_callback, 0, &s, &s); + if (umkaAlive(thg->umka)) + umkaCall(thg->umka, thg->umth_destroy_callback, 0, &s, &s); + if (umkaAlive(thg->umka)) + umkaRun(thg->umka); + - umkaRun(thg->umka); umkaFree(thg->umka); th_audio_deinit(); @@ -145,8 +148,10 @@ run_playground(const char *src) UmkaStackSlot s; if (thg->umka) { - umkaCall(thg->umka, thg->umth_destroy_callback, 0, &s, &s); - umkaRun(thg->umka); + if (umkaAlive(thg->umka)) + umkaCall(thg->umka, thg->umth_destroy_callback, 0, &s, &s); + if (umkaAlive(thg->umka)) + umkaRun(thg->umka); umkaFree(thg->umka); thg->umka = NULL; } @@ -155,10 +160,11 @@ run_playground(const char *src) return 1; } - int code = - umkaCall(thg->umka, umkaGetFunc(thg->umka, "tophat_main.um", "__th_init"), 0, &s, &s); - if (!umkaAlive(thg->umka)) { - th_print_umka_error_and_quit(code); + if (umkaAlive(thg->umka)) { + int code = umkaCall(thg->umka, umkaGetFunc(thg->umka, "tophat_main.um", "__th_init"), 0, &s, &s); + if (!umkaAlive(thg->umka)) { + th_print_umka_error_and_quit(code); + } } fprintf(stderr, "inited\n"); diff --git a/src/window.c b/src/window.c index afeb6bbd..f61d405f 100644 --- a/src/window.c +++ b/src/window.c @@ -66,10 +66,11 @@ init() UmkaStackSlot s; - int code = - umkaCall(thg->umka, umkaGetFunc(thg->umka, "tophat_main.um", "__th_init"), 0, &s, &s); - if (!umkaAlive(thg->umka)) { - th_print_umka_error_and_quit(code); + if (umkaAlive(thg->umka)) { + int code = umkaCall(thg->umka, umkaGetFunc(thg->umka, "tophat_main.um", "__th_init"), 0, &s, &s); + if (!umkaAlive(thg->umka)) { + th_print_umka_error_and_quit(code); + } } } @@ -97,7 +98,7 @@ frame() thg->target_size = (th_vf2){.w = window_width, .h = window_height}; UmkaStackSlot s; - if (thg->umth_frame_callback != -1) { + if (thg->umka && umkaAlive(thg->umka) && thg->umth_frame_callback != -1) { s.realVal = sapp_frame_duration(); int code = umkaCall(thg->umka, thg->umth_frame_callback, 1, &s, &s);