From b0e718876a3ae3fb4b23d7edb296c22f6526b4bd Mon Sep 17 00:00:00 2001 From: veclavtalica Date: Sun, 26 Jan 2025 02:56:00 +0300 Subject: [PATCH] show time limit in sanity timer --- src/system/linux/twn_timer.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/system/linux/twn_timer.c b/src/system/linux/twn_timer.c index ad7fb77..be26538 100644 --- a/src/system/linux/twn_timer.c +++ b/src/system/linux/twn_timer.c @@ -15,14 +15,18 @@ static struct sigaction sa; static struct sigevent sev; static bool created; +static uint64_t used_milliseconds_to_expire; +#define SANITY_TIMER_MESSAGE_FMT "Game tick exeeded its allocated time (%lu milliseconds), application is closing" /* stop application */ static void sanity_timer_handler(int sig, siginfo_t *si, void *uc) { (void)uc; (void)sig; (void)si; - SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, - "sanity timer", "Your game tick exceeded its allocated time, application is closing", - ctx.window); + size_t text_str_len = snprintf(NULL, 0, SANITY_TIMER_MESSAGE_FMT, used_milliseconds_to_expire) + 1; + char *text_str = SDL_malloc(text_str_len); + snprintf(text_str, text_str_len, SANITY_TIMER_MESSAGE_FMT, used_milliseconds_to_expire); + SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "sanity timer", text_str, ctx.window); + SDL_free(text_str); raise(SIGKILL); } @@ -55,6 +59,8 @@ bool start_sanity_timer(uint64_t milliseconds_to_expire) { if (timer_settime(timerid, 0, &its, NULL) == -1) return false; + used_milliseconds_to_expire = milliseconds_to_expire; + return true; }