Fixed an issue with memory

This commit is contained in:
2022-10-03 07:29:24 +01:00
parent 39aa3ca51d
commit bd32a1d221
3 changed files with 15 additions and 12 deletions

View File

@@ -1,11 +1,11 @@
import standard;
//root node can load the whole scene, and essentially act as the scene object //root node can load the whole scene, and essentially act as the scene object
fn onInit() { fn onInit() {
print "root.toy:onInit() called"; print "root.toy:onInit() called";
} }
fn onStep() { fn onStep() {
import standard;
print "root.toy:onStep() called";
print clock(); print clock();
} }

View File

@@ -206,8 +206,8 @@ void execEngine() {
} }
//render the world //render the world
SDL_SetRenderDrawColor(engine.renderer, 0, 0, 0, 255); //NOTE: This line can be disabled later // SDL_SetRenderDrawColor(engine.renderer, 0, 0, 0, 255); //NOTE: This line can be disabled later
SDL_RenderClear(engine.renderer); //NOTE: This line can be disabled later // SDL_RenderClear(engine.renderer); //NOTE: This line can be disabled later
SDL_RenderPresent(engine.renderer); // SDL_RenderPresent(engine.renderer);
} }
} }

View File

@@ -180,13 +180,16 @@ static int nativeLoadRootNode(Interpreter* interpreter, LiteralArray* arguments)
engine.rootNode = ALLOCATE(EngineNode, 1); engine.rootNode = ALLOCATE(EngineNode, 1);
//BUGFIX: use an inner-interpreter here, otherwise it'll mess up the original's length value by calling run within a native function //BUGFIX
Interpreter inner; unsigned char* originalTb = engine.interpreter.bytecode;
initInterpreter(&inner); size_t originalSize = engine.interpreter.length;
int originalCount = engine.interpreter.count;
initEngineNode(engine.rootNode, &inner, tb, size); int originalCodeStart = engine.interpreter.codeStart;
initEngineNode(engine.rootNode, &engine.interpreter, tb, size);
freeInterpreter(&inner); engine.interpreter.bytecode = originalTb;
engine.interpreter.length = originalSize;
engine.interpreter.count = originalCount;
engine.interpreter.codeStart = originalCodeStart;
//init the new node //init the new node
callEngineNode(engine.rootNode, &engine.interpreter, "onInit"); callEngineNode(engine.rootNode, &engine.interpreter, "onInit");