From 40c09a062c16b816e1b497feb9cebbc12e25fba7 Mon Sep 17 00:00:00 2001 From: Sasha Szpakowski Date: Wed, 19 Aug 2026 22:27:24 -0300 Subject: [PATCH] graphics: fix a few functions that were missing C++ exception to Lua error conversion code. --- src/modules/graphics/wrap_Buffer.cpp | 5 +- src/modules/graphics/wrap_Graphics.cpp | 114 +++++++++++----------- src/modules/graphics/wrap_Mesh.cpp | 6 +- src/modules/graphics/wrap_SpriteBatch.cpp | 2 +- 4 files changed, 66 insertions(+), 61 deletions(-) diff --git a/src/modules/graphics/wrap_Buffer.cpp b/src/modules/graphics/wrap_Buffer.cpp index f0ea9d7bb..519d4fc18 100644 --- a/src/modules/graphics/wrap_Buffer.cpp +++ b/src/modules/graphics/wrap_Buffer.cpp @@ -257,7 +257,7 @@ static int w_Buffer_setArrayData(lua_State *L) size_t datasize = std::min(d->getSize() - dataoffset, count * stride); const void *sourcedata = (const uint8 *) d->getData() + dataoffset; - t->fill(bufferoffset, datasize, sourcedata); + luax_catchexcept(L, [&]() { t->fill(bufferoffset, datasize, sourcedata); }); return 0; } @@ -289,7 +289,8 @@ static int w_Buffer_setArrayData(lua_State *L) if (destindex + count > arraylength) return luaL_error(L, "Too many array elements (expected at most %d, got %d)", arraylength - destindex, count); - char *data = (char *) t->map(Buffer::MAP_WRITE_INVALIDATE, bufferoffset, count * stride); + char *data = nullptr; + luax_catchexcept(L, [&]() { data = (char *)t->map(Buffer::MAP_WRITE_INVALIDATE, bufferoffset, count * stride); }); if (tableoftables) { diff --git a/src/modules/graphics/wrap_Graphics.cpp b/src/modules/graphics/wrap_Graphics.cpp index 7625578d5..8221cc9e3 100644 --- a/src/modules/graphics/wrap_Graphics.cpp +++ b/src/modules/graphics/wrap_Graphics.cpp @@ -276,7 +276,7 @@ int w_setCanvas(lua_State *L) // called with none -> reset to default buffer if (lua_isnoneornil(L, 1)) { - instance()->setRenderTarget(); + luax_catchexcept(L, [&]() { instance()->setRenderTarget(); }); return 0; } @@ -577,7 +577,7 @@ int w_setScissor(lua_State *L) if (rect.w < 0 || rect.h < 0) return luaL_error(L, "Can't set scissor with negative width and/or height."); - instance()->setScissor(rect); + luax_catchexcept(L, [&]() { instance()->setScissor(rect); }); return 0; } @@ -592,7 +592,7 @@ int w_intersectScissor(lua_State *L) if (rect.w < 0 || rect.h < 0) return luaL_error(L, "Can't set scissor with negative width and/or height."); - instance()->intersectScissor(rect); + luax_catchexcept(L, [&]() { instance()->intersectScissor(rect); }); return 0; } @@ -1426,7 +1426,8 @@ int w_newImageFont(lua_State *L) love::font::Rasterizer *rasterizer = luax_checktype(L, 1); // Create the font. - Font *font = instance()->newFont(rasterizer); + Font *font = nullptr; + luax_catchexcept(L, [&]() { font = instance()->newFont(rasterizer); }); // Push the type. luax_pushtype(L, font); @@ -1570,7 +1571,7 @@ static int w_getShaderSource(lua_State *L, int startidx, std::vectorgetDataMembers(); - size_t stride = b->getArrayStride(); - - if (tableoftables) + luax_catchexcept(L, [&]() { - for (size_t i = 0; i < arraylength; i++) + Buffer::Mapper mapper(*b); + char *data = (char *) mapper.data; + const auto &members = b->getDataMembers(); + size_t stride = b->getArrayStride(); + + if (tableoftables) { - // get arraydata[index] - lua_rawgeti(L, 2, i + 1); - luaL_checktype(L, -1, LUA_TTABLE); - - // get arraydata[index][j] - for (int j = 1; j <= ncomponents; j++) - lua_rawgeti(L, -j, j); - - int idx = -ncomponents; - - for (const Buffer::DataMember &member : members) + for (size_t i = 0; i < arraylength; i++) { - luax_writebufferdata(L, idx, member.decl.format, data + member.offset); - idx += member.info.components; - } + // get arraydata[index] + lua_rawgeti(L, 2, i + 1); + luaL_checktype(L, -1, LUA_TTABLE); - lua_pop(L, ncomponents + 1); - data += stride; + // get arraydata[index][j] + for (int j = 1; j <= ncomponents; j++) + lua_rawgeti(L, -j, j); + + int idx = -ncomponents; + + for (const Buffer::DataMember &member : members) + { + luax_writebufferdata(L, idx, member.decl.format, data + member.offset); + idx += member.info.components; + } + + lua_pop(L, ncomponents + 1); + data += stride; + } } - } - else // Flat array - { - for (size_t i = 0; i < arraylength; i++) + else // Flat array { - // get arraydata[arrayindex * ncomponents + componentindex] - for (int componentindex = 1; componentindex <= ncomponents; componentindex++) - lua_rawgeti(L, 2, i * ncomponents + componentindex); - - int idx = -ncomponents; - - for (const Buffer::DataMember &member : members) + for (size_t i = 0; i < arraylength; i++) { - luax_writebufferdata(L, idx, member.decl.format, data + member.offset); - idx += member.info.components; - } + // get arraydata[arrayindex * ncomponents + componentindex] + for (int componentindex = 1; componentindex <= ncomponents; componentindex++) + lua_rawgeti(L, 2, i * ncomponents + componentindex); - lua_pop(L, ncomponents); - data += stride; + int idx = -ncomponents; + + for (const Buffer::DataMember &member : members) + { + luax_writebufferdata(L, idx, member.decl.format, data + member.offset); + idx += member.info.components; + } + + lua_pop(L, ncomponents); + data += stride; + } } - } + }); } return b; @@ -2192,7 +2196,7 @@ static Mesh *newCustomMesh(lua_State *L) } t->setVertexDataModified(0, stride * numvertices); - t->flush(); + luax_catchexcept(L, [&]() { t->flush(); }); } if (t->getVertexBuffer() != nullptr) @@ -2605,7 +2609,7 @@ int w_setColorMask(lua_State *L) mask.a = luax_checkboolean(L, 4); } - instance()->setColorMask(mask); + luax_catchexcept(L, [&]() { instance()->setColorMask(mask); }); return 0; } @@ -2867,7 +2871,7 @@ int w_getLineJoin(lua_State *L) int w_setPointSize(lua_State *L) { float size = (float)luaL_checknumber(L, 1); - instance()->setPointSize(size); + luax_catchexcept(L, [&]() { instance()->setPointSize(size); }); return 0; } @@ -2957,7 +2961,7 @@ int w_getFrontFaceWinding(lua_State *L) int w_setWireframe(lua_State *L) { - instance()->setWireframe(luax_checkboolean(L, 1)); + luax_catchexcept(L, [&]() { instance()->setWireframe(luax_checkboolean(L, 1)); }); return 0; } @@ -2976,7 +2980,7 @@ int w_setShader(lua_State *L) } Shader *shader = luax_checkshader(L, 1); - instance()->setShader(shader); + luax_catchexcept(L, [&]() { instance()->setShader(shader); }); return 0; } @@ -3891,9 +3895,9 @@ int w_copyTextureToBuffer(lua_State *L) return 0; } -int w_flushBatch(lua_State *) +int w_flushBatch(lua_State *L) { - instance()->flushBatchedDraws(); + luax_catchexcept(L, [&]() { instance()->flushBatchedDraws(); }); return 0; } @@ -4028,13 +4032,13 @@ int w_setProjection(lua_State *L) float elements[16]; love::math::luax_checkmatrix(L, idx, layout, elements); - instance()->setProjection(Matrix4(elements)); + luax_catchexcept(L, [&]() { instance()->setProjection(Matrix4(elements)); }); return 0; } -int w_resetProjection(lua_State */*L*/) +int w_resetProjection(lua_State *L) { - instance()->resetProjection(); + luax_catchexcept(L, [&]() { instance()->resetProjection(); }); return 0; } diff --git a/src/modules/graphics/wrap_Mesh.cpp b/src/modules/graphics/wrap_Mesh.cpp index afaec0fdf..fe734c500 100644 --- a/src/modules/graphics/wrap_Mesh.cpp +++ b/src/modules/graphics/wrap_Mesh.cpp @@ -72,7 +72,7 @@ int w_Mesh_setVertices(lua_State *L) memcpy(bytedata, d->getData(), datasize); t->setVertexDataModified(byteoffset, datasize); - t->flush(); + luax_catchexcept(L, [&]() { t->flush(); }); return 0; } @@ -117,7 +117,7 @@ int w_Mesh_setVertices(lua_State *L) } t->setVertexDataModified(byteoffset, vertcount * stride); - t->flush(); + luax_catchexcept(L, [&]() { t->flush(); }); return 0; } @@ -425,7 +425,7 @@ int w_Mesh_getVertexBuffer(lua_State *L) int w_Mesh_flush(lua_State *L) { Mesh *t = luax_checkmesh(L, 1); - t->flush(); + luax_catchexcept(L, [&]() { t->flush(); }); return 0; } diff --git a/src/modules/graphics/wrap_SpriteBatch.cpp b/src/modules/graphics/wrap_SpriteBatch.cpp index 592c86ae9..4eec3f172 100644 --- a/src/modules/graphics/wrap_SpriteBatch.cpp +++ b/src/modules/graphics/wrap_SpriteBatch.cpp @@ -132,7 +132,7 @@ int w_SpriteBatch_clear(lua_State *L) int w_SpriteBatch_flush(lua_State *L) { SpriteBatch *t = luax_checkspritebatch(L, 1); - t->flush(); + luax_catchexcept(L, [&]() { t->flush(); }); return 0; }