From 92449eb66c25a54e3ee70b008bd1559dade32c8b Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Sun, 10 May 2026 17:54:04 +1000 Subject: [PATCH] Updated Toy, fixed a leak --- Toy | 2 +- source/actor.c | 10 ++++++---- source/main.c | 4 ++-- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/Toy b/Toy index 3b813da..53d3606 160000 --- a/Toy +++ b/Toy @@ -1 +1 @@ -Subproject commit 3b813da1cf8a8d5838d837fd6784e37dcf91b5c4 +Subproject commit 53d3606c7e225496f3223621c789b3d91f998131 diff --git a/source/actor.c b/source/actor.c index 4f068e9..40bfc24 100644 --- a/source/actor.c +++ b/source/actor.c @@ -72,7 +72,7 @@ static void api_loadSprite(Toy_VM* vm) { } //insert into the table as an opaque - Toy_insertTable(&spriteTable, Toy_copyValue(&vm->memoryBucket, key), TOY_OPAQUE_FROM_POINTER(sprite)); + Toy_insertTable(&spriteTable, key, TOY_OPAQUE_FROM_POINTER(sprite)); Toy_freeValue(key); Toy_freeValue(file); @@ -204,7 +204,7 @@ void initActorAPI(Toy_VM* vm) { //declare each callback in the global scope for (int i = 0; callbackPairs[i].name; i++) { - Toy_String* key = Toy_toString(&(vm->memoryBucket), callbackPairs[i].name); + Toy_String* key = Toy_createStringLength(&(vm->memoryBucket), callbackPairs[i].name, strlen(callbackPairs[i].name)); Toy_Function* fn = Toy_createFunctionFromCallback(&(vm->memoryBucket), callbackPairs[i].callback); Toy_declareScope(vm->scope, key, TOY_VALUE_FUNCTION, TOY_VALUE_FROM_FUNCTION(fn), true); @@ -260,7 +260,7 @@ void processActorStep(Toy_VM* vm) { //c-string of the param's name && as a name string const char* cstr = ((char*)(subVM.code + subVM.dataAddr)) + paramAddr; - Toy_String* name = Toy_toStringLength(&subVM.memoryBucket, cstr, strlen(cstr)); + Toy_String* name = Toy_toStringLength(&subVM.memoryBucket, cstr, strlen(cstr)); //don't use 'create' int ticker = 0; @@ -280,6 +280,8 @@ void processActorStep(Toy_VM* vm) { Toy_freeVM(&subVM); + Toy_freeString(name); + //DEBUG: "wipe" the actors if there's too many, so memory doesn't keep growing. if (ticker >= 100) { for (unsigned int i = 0; i < actorArray->count; i++) { @@ -337,7 +339,7 @@ void loadSprite(Toy_Bucket** bucketHandle, Toy_Value key, const char* fname, int sprite->texture = LoadTexture(fname); //insert into the table as an opaque - Toy_insertTable(&spriteTable, Toy_copyValue(bucketHandle, key), TOY_OPAQUE_FROM_POINTER(sprite)); + Toy_insertTable(&spriteTable, key, TOY_OPAQUE_FROM_POINTER(sprite)); } ActorData* spawnActorAt(Toy_Bucket** bucketHandle, Toy_Value key, int xpos, int ypos) { diff --git a/source/main.c b/source/main.c index c1f8223..0404a1a 100644 --- a/source/main.c +++ b/source/main.c @@ -85,7 +85,7 @@ void initScreen(Toy_VM* vm) { //setup raylib InitWindow(TOY_VALUE_AS_INTEGER(width), TOY_VALUE_AS_INTEGER(height), TOY_VALUE_AS_STRING(caption)->leaf.data); - SetTargetFPS(60); + // SetTargetFPS(60); if (!IsWindowReady()) { fprintf(stderr, TOY_CC_ERROR "ERROR: raylib failed to init the window, exiting" TOY_CC_RESET "\n"); @@ -160,7 +160,7 @@ void initGameAPI(Toy_VM* vm) { //declare each function in the global scope for (int i = 0; callbackPairs[i].name; i++) { - Toy_String* key = Toy_toString(&(vm->memoryBucket), callbackPairs[i].name); + Toy_String* key = Toy_createStringLength(&(vm->memoryBucket), callbackPairs[i].name, strlen(callbackPairs[i].name)); Toy_Function* fn = Toy_createFunctionFromCallback(&(vm->memoryBucket), callbackPairs[i].callback); Toy_declareScope(vm->scope, key, TOY_VALUE_FUNCTION, TOY_VALUE_FROM_FUNCTION(fn), true); Toy_freeString(key);