diff --git a/src/components/screen.c b/src/components/screen.c index c0ef794..b6512d3 100644 --- a/src/components/screen.c +++ b/src/components/screen.c @@ -2,6 +2,7 @@ nn_screen *nn_newScreen(nn_Context *context, int maxWidth, int maxHeight, int maxDepth, int editableColors, int paletteColors) { nn_Alloc *alloc = &context->allocator; + // TODO: handle OOMs nn_screen *screen = nn_alloc(alloc, sizeof(nn_screen)); screen->ctx = *context; screen->buffer = nn_alloc(alloc, sizeof(nn_scrchr_t) * maxWidth * maxHeight); @@ -65,6 +66,20 @@ void nn_setResolution(nn_screen *screen, int width, int height) { screen->height = height; } +nn_bool_t nn_unsafeReallocateScreenBuffer(nn_screen *screen, int maxWidth, int maxHeight) { + nn_Alloc *alloc = &screen->ctx.allocator; + + nn_scrchr_t *newBuffer = nn_alloc(alloc, sizeof(nn_scrchr_t) * maxWidth * maxHeight); + if(newBuffer == NULL) { + return false; + } + + screen->buffer = newBuffer; + screen->maxWidth = maxWidth; + screen->maxHeight = maxHeight; + return true; +} + void nn_getViewport(nn_screen *screen, int *width, int *height) { *width = screen->viewportWidth; *height = screen->viewportHeight; diff --git a/src/components/volatileFilesystem.c b/src/components/volatileFilesystem.c index 5059d0d..399cf86 100644 --- a/src/components/volatileFilesystem.c +++ b/src/components/volatileFilesystem.c @@ -111,7 +111,7 @@ nn_size_t nn_vf_spaceUsedByNode(nn_vfnode *node) { if(node->isDirectory) { nn_size_t sum = 0; for(nn_size_t i = 0; i < node->len; i++) { - sum = nn_vf_spaceUsedByNode(node->entries[i]); + sum += nn_vf_spaceUsedByNode(node->entries[i]); } return sum; } else { diff --git a/src/neonucleus.h b/src/neonucleus.h index d0585d1..8bcad17 100644 --- a/src/neonucleus.h +++ b/src/neonucleus.h @@ -914,6 +914,9 @@ void nn_unlockScreen(nn_screen *screen); void nn_getResolution(nn_screen *screen, int *width, int *height); void nn_maxResolution(nn_screen *screen, int *width, int *height); void nn_setResolution(nn_screen *screen, int width, int height); +// changes the maximum resolution +// DOES NOT USE THE LOCK AND THUS MAY CAUSE RACE CONDITIONS AND SEGFAULTS!!!!! +nn_bool_t nn_unsafeReallocateScreenBuffer(nn_screen *screen, int maxWidth, int maxHeight); void nn_getViewport(nn_screen *screen, int *width, int *height); void nn_setViewport(nn_screen *screen, int width, int height); diff --git a/src/sandbox.lua b/src/sandbox.lua index fdd18e5..d5b3d7f 100644 --- a/src/sandbox.lua +++ b/src/sandbox.lua @@ -228,6 +228,7 @@ local libcomputer = { local deadline = computer.uptime() + (type(timeout) == "number" and timeout or math.huge) repeat + print("waiting for signal", computer.uptime()) yield() -- give executor a chance to give us stuff local s = table.pack(computer.popSignal()) if s.n > 0 then @@ -437,7 +438,6 @@ local lastGC = computer.uptime() while true do timeout = nextDeadline() bubbleYield = false - collectgarbage() if computer.uptime() - lastGC >= gcInterval then collectgarbage("collect") diff --git a/src/testLuaArch.c b/src/testLuaArch.c index 993405b..420efbc 100644 --- a/src/testLuaArch.c +++ b/src/testLuaArch.c @@ -69,7 +69,7 @@ void *testLuaArch_alloc(testLuaArch *arch, void *ptr, size_t osize, size_t nsize nn_Alloc *alloc = nn_getAllocator(nn_getUniverse(arch->computer)); if(nsize == 0) { arch->memoryUsed -= osize; - free(ptr); + nn_dealloc(alloc, ptr, osize); return NULL; } else { size_t actualOldSize = osize; @@ -79,7 +79,7 @@ void *testLuaArch_alloc(testLuaArch *arch, void *ptr, size_t osize, size_t nsize } arch->memoryUsed -= actualOldSize; arch->memoryUsed += nsize; - return realloc(ptr, nsize); + return nn_resize(alloc, ptr, actualOldSize, nsize); } }