From 5bdea01559adcb3ab0dff4616cf5507b0e69b6cc Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Wed, 12 Aug 2015 23:45:44 -0300 Subject: [PATCH] Fixed Canvas:renderTo to restore the previous canvases if an error occurs in the passed function. --- src/modules/graphics/opengl/wrap_Canvas.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/modules/graphics/opengl/wrap_Canvas.cpp b/src/modules/graphics/opengl/wrap_Canvas.cpp index b1d9cdbf5..004ee2f9a 100644 --- a/src/modules/graphics/opengl/wrap_Canvas.cpp +++ b/src/modules/graphics/opengl/wrap_Canvas.cpp @@ -51,12 +51,15 @@ int w_Canvas_renderTo(lua_State *L) luax_catchexcept(L, [&](){ graphics->setCanvas(canvas); }); lua_settop(L, 2); // make sure the function is on top of the stack - lua_call(L, 0, 0); + int status = lua_pcall(L, 0, 0, 0); graphics->setCanvas(oldcanvases); for (Canvas *c : oldcanvases) c->release(); + + if (status != 0) + return lua_error(L); } return 0;