fix actors not freeing correctly if error in startup script

This commit is contained in:
2025-06-06 17:42:28 -05:00
parent adbaa92dd5
commit 83c816fd0e

View File

@@ -380,7 +380,6 @@ const char *register_actor(const char *id, cell_rt *actor, int mainthread, doubl
actor->main_thread_only = mainthread;
actor->id = strdup(id);
actor->ar_secs = ar;
actor->state = ACTOR_IDLE; // Initialize state!
shput(actors, id, actor);
SDL_UnlockMutex(actors_mutex);
return NULL;
@@ -635,7 +634,6 @@ void tracy_end_hook(JSContext *js, JSValue fn)
void actor_disrupt(cell_rt *crt)
{
crt->disrupt = 1;
if (crt->state != ACTOR_RUNNING)
actor_free(crt);
}
@@ -691,15 +689,16 @@ void script_startup(cell_rt *prt)
PHYSFS_close(eng);
data[stat.filesize] = 0;
prt->state = ACTOR_RUNNING;
JSValue v = JS_Eval(js, data, (size_t)stat.filesize, ENGINE, JS_EVAL_FLAG_STRICT);
uncaught_exception(js, v);
prt->state = ACTOR_IDLE;
}
int uncaught_exception(JSContext *js, JSValue v)
{
cell_rt *rt = JS_GetContextOpaque(js);
SDL_LockMutex(rt->mutex);
JS_FreeValue(js,v);
if (!JS_HasException(js)) {
JS_FreeValue(js,v);
@@ -708,10 +707,10 @@ int uncaught_exception(JSContext *js, JSValue v)
}
JSValue exp = JS_GetException(js);
JSValue ret = JS_Call(js, rt->on_exception, JS_UNDEFINED, 1, &exp);
JS_FreeValue(js,ret);
JS_FreeValue(js, exp);
JS_FreeValue(js,v);
SDL_UnlockMutex(rt->mutex);
return 0;
}
@@ -822,8 +821,6 @@ int main(int argc, char **argv)
exit(1);
}
printf("main thread is %d\n", SDL_GetThreadID(NULL));
#ifdef TRACY_ENABLE
tracy_profiling_enabled = profile_enabled;
#endif