diff --git a/demos/space-shooter/main.um b/demos/space-shooter/main.um index 088c532..a71ccfe 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 405e057..f70d7bb 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 2029afb..ac843ba 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 afeb6bb..f61d405 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);