From 0c9d78a3d38173a2e55913f72a72c77b1bdb476b Mon Sep 17 00:00:00 2001 From: John Alanbrook Date: Sat, 24 May 2025 21:30:29 -0500 Subject: [PATCH] initialize parts of SDL only when required, and return errors --- source/prosperon.c | 8 ++++---- source/qjs_sdl.c | 3 +++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/source/prosperon.c b/source/prosperon.c index 8e25bd38..6c9b06be 100644 --- a/source/prosperon.c +++ b/source/prosperon.c @@ -506,7 +506,6 @@ void actor_free(prosperon_rt *actor) /* Timer callback adds an event to the queue under evt_mutex. */ Uint32 actor_timer_cb(prosperon_rt *actor, SDL_TimerID id, Uint32 interval) { - printf("firing timer %u\n", id); SDL_LockMutex(actor->msg_mutex); int idx = hmgeti(actor->timers, id); if (idx == -1) goto END; @@ -541,8 +540,6 @@ JSValue js_actor_delay(JSContext *js, JSValue self, int argc, JSValue *argv) Uint32 id = SDL_AddTimerNS(ns, actor_timer_cb, actor); - printf("started timer %u for %g secs\n", id, seconds); - SDL_LockMutex(actor->msg_mutex); JSValue cb = JS_DupValue(js, argv[0]); hmput(actor->timers, id, cb); @@ -1343,7 +1340,10 @@ int main(int argc, char **argv) } } - SDL_Init(SDL_INIT_EVENTS);// | SDL_INIT_VIDEO | SDL_INIT_AUDIO); + if (!SDL_Init(SDL_INIT_EVENTS)) { + printf("CRITICAL ERROR: %s\n", SDL_GetError()); + exit(1); + } queue_event = SDL_RegisterEvents(1); int cores = SDL_GetNumLogicalCPUCores(); diff --git a/source/qjs_sdl.c b/source/qjs_sdl.c index 6cb0b1e6..15d73bdf 100644 --- a/source/qjs_sdl.c +++ b/source/qjs_sdl.c @@ -465,6 +465,9 @@ static const JSCFunctionListEntry js_SDL_AudioStream_funcs[] = { }; JSValue js_sdl_audio_use(JSContext *js) { + if (!SDL_Init(SDL_INIT_AUDIO)) + return JS_ThrowInternalError(js, "Unable to initialize audio subsystem: %s", SDL_GetError()); + QJSCLASSPREP_FUNCS(SDL_AudioStream) JSValue mod = JS_NewObject(js);