fixed memory leak on thread exit
Some checks failed
Build and Deploy / build-linux (push) Failing after 1m41s
Build and Deploy / build-windows (CLANG64) (push) Failing after 6m16s
Build and Deploy / package-dist (push) Has been skipped
Build and Deploy / deploy-itch (push) Has been skipped
Build and Deploy / deploy-gitea (push) Has been skipped
Some checks failed
Build and Deploy / build-linux (push) Failing after 1m41s
Build and Deploy / build-windows (CLANG64) (push) Failing after 6m16s
Build and Deploy / package-dist (push) Has been skipped
Build and Deploy / deploy-itch (push) Has been skipped
Build and Deploy / deploy-gitea (push) Has been skipped
This commit is contained in:
@@ -405,6 +405,8 @@ function cant_kill() {
|
||||
throw Error("Can't kill an object in its spawning code. Move the kill command to awake.")
|
||||
}
|
||||
|
||||
// OK if return here
|
||||
|
||||
actor.toString = function() { return this[FILE] }
|
||||
|
||||
actor.spawn = function spawn(script, config, callback) {
|
||||
@@ -554,8 +556,8 @@ var enet = use('enet')
|
||||
var util = use('util')
|
||||
var math = use('math')
|
||||
var crypto = use('crypto')
|
||||
var nota = use('nota')
|
||||
var wota = use('wota')
|
||||
var nota = use('nota')
|
||||
|
||||
var HEADER = Symbol()
|
||||
|
||||
@@ -587,6 +589,8 @@ function create_actor(data = {}) {
|
||||
return newactor
|
||||
}
|
||||
|
||||
// break if return here
|
||||
|
||||
var $_ = create_actor()
|
||||
|
||||
$_.random = crypto.random
|
||||
@@ -721,7 +725,15 @@ $_.start = function(cb, prg, arg) {
|
||||
$_.start[prosperon.DOC] = "The start function creates a new actor..."
|
||||
|
||||
$_.stop = function(actor) {
|
||||
if (!actor) destroyself()
|
||||
if (!actor) {
|
||||
destroyself()
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
if (!$_.is_actor(actor))
|
||||
throw new Error('Can only call stop on an actor.')
|
||||
|
||||
if (!underlings.has(actor.__ACTORDATA__.id))
|
||||
throw new Error('Can only call stop on an underling or self.')
|
||||
|
||||
@@ -840,7 +852,7 @@ var unneeded_timer = $_.delay($_.stop, ar)
|
||||
function destroyself() {
|
||||
console.log(`Got the message to destroy self.`)
|
||||
if (overling) actor_send(overling, { type: "stopped", id: prosperon.id })
|
||||
os.exit(0)
|
||||
doexit = true
|
||||
}
|
||||
|
||||
function handle_actor_disconnect(id) {
|
||||
@@ -914,7 +926,8 @@ function handle_message(msg) {
|
||||
var hang = 0.01
|
||||
var last_t = os.now()
|
||||
|
||||
while (1) {
|
||||
var doexit = false
|
||||
while (!doexit) {
|
||||
if (portal) portal.service(handle_host, hang)
|
||||
if (contactor) contactor.service(handle_host, hang)
|
||||
os.mailbox_service(prosperon.id, handle_local)
|
||||
|
||||
@@ -77,14 +77,6 @@ static Uint32 timer_cb_event;
|
||||
//#include <cblas.h>
|
||||
#endif
|
||||
|
||||
#define STATE_VECTOR_LENGTH 624
|
||||
#define STATE_VECTOR_M 397 /* changes to STATE_VECTOR_LENGTH also require changes to this */
|
||||
|
||||
typedef struct tagMTRand {
|
||||
uint32_t mt[STATE_VECTOR_LENGTH];
|
||||
int32_t index;
|
||||
} MTRand;
|
||||
|
||||
#define UPPER_MASK 0x80000000
|
||||
#define LOWER_MASK 0x7fffffff
|
||||
#define TEMPERING_MASK_B 0x9d2c5680
|
||||
@@ -336,22 +328,6 @@ struct lrtb {
|
||||
float b;
|
||||
};
|
||||
|
||||
typedef JSValue (*MODULEFN)(JSContext *js);
|
||||
|
||||
typedef struct {
|
||||
const char *name;
|
||||
MODULEFN fn;
|
||||
} ModuleEntry;
|
||||
|
||||
typedef struct prosperon_rt {
|
||||
MTRand mrand;
|
||||
JSValue cycle_fn;
|
||||
JSValue idx_buffer;
|
||||
int idx_count;
|
||||
ModuleEntry *module_registry;
|
||||
JSValue *js_swapchains;
|
||||
} prosperon_rt;
|
||||
|
||||
static SDL_GPUDevice *global_gpu;
|
||||
static SDL_Window *global_window;
|
||||
|
||||
@@ -6538,7 +6514,7 @@ void script_report_gc_time(double t, double startmem, double mem)
|
||||
gc_startmem = startmem;
|
||||
}
|
||||
|
||||
JSC_SSCALL(os_eval, return ret = script_eval(js,str, str2))
|
||||
JSC_SSCALL(os_eval, ret = script_eval(js,str, str2))
|
||||
JSC_CCALL(os_make_timer, return timer2js(js,timer_make(js,argv[0])))
|
||||
JSC_CCALL(os_update_timers, timer_update(js, js2number(js,argv[0])))
|
||||
|
||||
@@ -7117,6 +7093,9 @@ typedef struct {
|
||||
int create_new_runtime(cmdargs *data)
|
||||
{
|
||||
script_startup(data->argc, data->argv);
|
||||
|
||||
printf("THREAD IS STOPPING\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
JSC_CCALL(os_createthread,
|
||||
@@ -7717,8 +7696,8 @@ static void signal_handler(int sig) {
|
||||
|
||||
static void exit_handler()
|
||||
{
|
||||
JSContext *js = SDL_GetTLS(&js_id);
|
||||
script_evalf(js, "prosperon.dispatch('exit')");
|
||||
// JSContext *js = SDL_GetTLS(&js_id);
|
||||
// script_evalf(js, "prosperon.dispatch('exit')");
|
||||
}
|
||||
|
||||
#include "monocypher.h"
|
||||
@@ -7959,6 +7938,7 @@ void ffi_load(JSContext *js, int argc, char **argv) {
|
||||
prosperon_rt *rt = calloc(1,sizeof(*rt));
|
||||
JS_SetContextOpaque(js, rt);
|
||||
m_seedRand(&rt->mrand, time(NULL));
|
||||
|
||||
arrput(rt->module_registry, MISTLINE(io));
|
||||
arrput(rt->module_registry, MISTLINE(os));
|
||||
arrput(rt->module_registry, MISTLINE(input));
|
||||
@@ -7991,6 +7971,7 @@ void ffi_load(JSContext *js, int argc, char **argv) {
|
||||
JSValue globalThis = JS_GetGlobalObject(js);
|
||||
|
||||
JSValue prosp = JS_NewObject(js);
|
||||
JS_SetPropertyStr(js,globalThis,"prosperon", prosp);
|
||||
JSValue c_types = JS_NewObject(js);
|
||||
JS_SetPropertyStr(js,prosp, "c_types", c_types);
|
||||
|
||||
@@ -8023,6 +8004,8 @@ void ffi_load(JSContext *js, int argc, char **argv) {
|
||||
QJSCLASSPREP_FUNCS(font);
|
||||
QJSCLASSPREP_FUNCS(datastream);
|
||||
QJSCLASSPREP_FUNCS(timer);
|
||||
|
||||
|
||||
|
||||
timer_cb_event = SDL_RegisterEvents(1);
|
||||
|
||||
@@ -8047,7 +8030,7 @@ void ffi_load(JSContext *js, int argc, char **argv) {
|
||||
JS_SetPropertyFunctionList(js, number_proto, js_number_funcs, countof(js_number_funcs));
|
||||
JS_FreeValue(js,jsnumber);
|
||||
JS_FreeValue(js,number_proto);
|
||||
|
||||
|
||||
signal(SIGINT, signal_handler);
|
||||
signal(SIGTERM, signal_handler);
|
||||
signal(SIGSEGV, signal_handler);
|
||||
@@ -8063,8 +8046,6 @@ void ffi_load(JSContext *js, int argc, char **argv) {
|
||||
JS_SetPropertyStr(js,prosp,"revision",JS_NewString(js,PROSPERON_COMMIT));
|
||||
JS_SetPropertyStr(js,prosp,"engine_start", JS_NewCFunction(js,js_os_engine_start, "engine_start", 1));
|
||||
|
||||
JS_SetPropertyStr(js,globalThis,"prosperon", prosp);
|
||||
|
||||
JS_FreeValue(js,globalThis);
|
||||
|
||||
SDL_Init(SDL_INIT_EVENTS);
|
||||
|
||||
@@ -109,5 +109,6 @@ int main(int argc, char **argv) {
|
||||
}
|
||||
|
||||
script_startup(argc, argv); // runs engine.js
|
||||
printf("MADE IT HERE AT BOTTOM OF MAIN\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -55,8 +55,6 @@ static JSValue apply_replacer(NotaEncodeContext *enc, JSValueConst holder, JSVal
|
||||
return result;
|
||||
}
|
||||
|
||||
JSValue number;
|
||||
|
||||
char *js_do_nota_decode(JSContext *js, JSValue *tmp, char *nota, JSValue holder, JSValue key, JSValue reviver) {
|
||||
int type = nota_type(nota);
|
||||
JSValue ret2;
|
||||
@@ -342,7 +340,6 @@ static int js_nota_init(JSContext *ctx, JSModuleDef *m) {
|
||||
JSValue js_nota_use(JSContext *js) {
|
||||
JSValue export = JS_NewObject(js);
|
||||
JS_SetPropertyFunctionList(js, export, js_nota_funcs, sizeof(js_nota_funcs)/sizeof(JSCFunctionListEntry));
|
||||
number = JS_GetPropertyStr(js, JS_GetGlobalObject(js), "Number");
|
||||
return export;
|
||||
}
|
||||
|
||||
|
||||
@@ -143,7 +143,7 @@ void script_startup(int argc, char **argv) {
|
||||
rt = JS_NewRuntime();
|
||||
#endif
|
||||
JSContext *js = JS_NewContextRaw(rt);
|
||||
SDL_SetTLS(&js_id, js, script_stop);
|
||||
SDL_SetTLS(&js_id, js, NULL);
|
||||
JS_AddIntrinsicBaseObjects(js);
|
||||
JS_AddIntrinsicEval(js);
|
||||
JS_AddIntrinsicRegExp(js);
|
||||
@@ -175,21 +175,26 @@ void script_startup(int argc, char **argv) {
|
||||
PHYSFS_close(eng);
|
||||
JSValue v = script_eval(js, ENGINE, data);
|
||||
uncaught_exception(js,v);
|
||||
free(eng);
|
||||
script_stop(js);
|
||||
}
|
||||
|
||||
void script_stop(JSContext *js)
|
||||
{
|
||||
prosperon_rt *prt = JS_GetContextOpaque(js);
|
||||
JS_FreeValue(js, prt->cycle_fn);
|
||||
JS_FreeValue(js, prt->idx_buffer);
|
||||
for (int i = 0; i < arrlen(prt->js_swapchains); i++)
|
||||
JS_FreeValue(js, prt->js_swapchains[i]);
|
||||
|
||||
free(prt);
|
||||
|
||||
printf("STOPPING CONTEXT %p\n", js);
|
||||
return;
|
||||
JSValue *onexp = SDL_GetTLS(&on_exception);
|
||||
JS_FreeValue(js,*onexp);
|
||||
JSRuntime *rt = JS_GetRuntime(js);
|
||||
JS_FreeContext(js);
|
||||
JS_FreeRuntime(rt);
|
||||
|
||||
free(rt);
|
||||
free(js);
|
||||
free(onexp);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,30 @@
|
||||
#include "quickjs.h"
|
||||
#include <SDL3/SDL.h>
|
||||
|
||||
typedef JSValue (*MODULEFN)(JSContext *js);
|
||||
|
||||
typedef struct {
|
||||
const char *name;
|
||||
MODULEFN fn;
|
||||
} ModuleEntry;
|
||||
|
||||
#define STATE_VECTOR_LENGTH 624
|
||||
#define STATE_VECTOR_M 397 /* changes to STATE_VECTOR_LENGTH also require changes to this */
|
||||
|
||||
typedef struct tagMTRand {
|
||||
uint32_t mt[STATE_VECTOR_LENGTH];
|
||||
int32_t index;
|
||||
} MTRand;
|
||||
|
||||
typedef struct prosperon_rt {
|
||||
MTRand mrand;
|
||||
JSValue cycle_fn;
|
||||
JSValue idx_buffer;
|
||||
int idx_count;
|
||||
ModuleEntry *module_registry;
|
||||
JSValue *js_swapchains;
|
||||
} prosperon_rt;
|
||||
|
||||
extern SDL_TLSID on_exception;
|
||||
extern SDL_TLSID js_id;
|
||||
|
||||
|
||||
@@ -265,8 +265,8 @@ console.log(`\nResult: ${passedCount}/${testCount} tests passed`);
|
||||
|
||||
if (passedCount < testCount) {
|
||||
console.log("Overall: FAILED");
|
||||
os.exit(1);
|
||||
// os.exit(1);
|
||||
} else {
|
||||
console.log("Overall: PASSED");
|
||||
os.exit(0);
|
||||
// os.exit(0);
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
var os = use('os')
|
||||
|
||||
$_.stop()
|
||||
|
||||
$_.start(e => {
|
||||
switch(e.type) {
|
||||
case "actor_started":
|
||||
|
||||
Reference in New Issue
Block a user