diff --git a/source/cell.c b/source/cell.c index a6beb946..a445062d 100644 --- a/source/cell.c +++ b/source/cell.c @@ -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