From d662e5509de5dca8a497691e16fbe617c92f2a02 Mon Sep 17 00:00:00 2001 From: Reuh Date: Sat, 22 Aug 2015 17:52:50 +0200 Subject: [PATCH] Fixed freeze when Lua tried to garbage collect a unloaded texture --- sdcard/3ds/ctruLua/example.lua | 17 +++++++++-------- sdcard/3ds/ctruLua/main.lua | 1 + source/texture.c | 5 +++-- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/sdcard/3ds/ctruLua/example.lua b/sdcard/3ds/ctruLua/example.lua index cd3f1ae..cf4ebc6 100644 --- a/sdcard/3ds/ctruLua/example.lua +++ b/sdcard/3ds/ctruLua/example.lua @@ -8,29 +8,30 @@ local dMul = 1 local angle = 0 -local texture1 = gfx.texture.load("sdmc:/3ds/ctruLua/icon.png", gfx.texture.PLACE_VRAM, gfx.texture.TYPE_PNG); +local texture1 = gfx.texture.load("sdmc:/3ds/ctruLua/icon.png", gfx.texture.PLACE_RAM, gfx.texture.TYPE_PNG); if not texture1 then error("Giants ducks came from another planet") end gfx.color.setBackground(gfx.color.RGBA8(200, 200, 200)) gfx.set3D(true) -local function drawStuffIn3D(depth) +-- eye : -1 = left, 1 = right +local function drawStuffIn3D(eye) gfx.text(2, 5, "Depth multiplicator: "..dMul) -- 3D stuff - local depth = math.floor(depth * dMul) + local function d(depth) return math.ceil(eye * depth * dMul) end gfx.color.setDefault(0x00FFFFFF) - gfx.rectangle(240 + depth*5, 150, 120, 10) + gfx.rectangle(240 + d(10), 150, 120, 10) - gfx.point(10 + depth*3, 20, 0xFF0000FF) + gfx.point(10 + d(6), 20, 0xFF0000FF) gfx.color.setDefault(0xFF0000FF) - gfx.rectangle(x + depth*math.ceil(5*math.sin(ctr.time()/500)), y, 20, 20, angle) + gfx.rectangle(x + d(10*math.sin(ctr.time()/500)), y, 20, 20, angle) - gfx.line(50 - depth*3, 50, 75 + depth*2, 96, gfx.color.RGBA8(52, 10, 65)) + gfx.line(50 + d(-6), 50, 75 + d(4), 96, gfx.color.RGBA8(52, 10, 65)) - gfx.circle(125 - depth*4, 125, 16) + gfx.circle(125 + d(-8), 125, 16) end while ctr.run() do diff --git a/sdcard/3ds/ctruLua/main.lua b/sdcard/3ds/ctruLua/main.lua index b8dcee9..3bdca31 100644 --- a/sdcard/3ds/ctruLua/main.lua +++ b/sdcard/3ds/ctruLua/main.lua @@ -37,6 +37,7 @@ while ctr.run() do if f.name:match("%..+$") == ".lua" then dofile(curdir..f.name) -- reset things the script could have changed + gfx.set3D(false) gfx.color.setDefault(0xFFFFFFFF) gfx.color.setBackground(0x000000FF) end diff --git a/source/texture.c b/source/texture.c index d0178d8..d2680ac 100644 --- a/source/texture.c +++ b/source/texture.c @@ -109,9 +109,10 @@ static int texture_drawPartBlend(lua_State *L) { static int texture_unload(lua_State *L) { texture_userdata *texture = luaL_checkudata(L, 1, "LTexture"); - if (texture->texture != NULL) sf2d_free_texture(texture->texture); + if (texture->texture == NULL) return 0; + + sf2d_free_texture(texture->texture); texture->texture = NULL; - free(texture); return 0; }