initialize parts of SDL only when required, and return errors
Some checks failed
Build and Deploy / build-macos (push) Failing after 5s
Build and Deploy / build-windows (CLANG64) (push) Has been cancelled
Build and Deploy / package-dist (push) Has been cancelled
Build and Deploy / deploy-itch (push) Has been cancelled
Build and Deploy / deploy-gitea (push) Has been cancelled
Build and Deploy / build-linux (push) Has been cancelled

This commit is contained in:
2025-05-24 21:30:29 -05:00
parent e929f43a96
commit 0c9d78a3d3
2 changed files with 7 additions and 4 deletions

View File

@@ -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();

View File

@@ -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);