Fixed undefined behaviour when love exceptions are converted into Lua errors (resolves issue #729)

This commit is contained in:
Alex Szpakowski
2013-09-05 23:17:29 -03:00
parent 389e99bf2c
commit 06f80d5c08
45 changed files with 349 additions and 873 deletions
+11 -16
View File
@@ -34,14 +34,7 @@ namespace math
int w_setRandomState(lua_State *L)
{
try
{
Math::instance.setRandomState(luax_checkrandomstate(L, 1));
}
catch (love::Exception &e)
{
return luaL_error(L, "%s", e.what());
}
EXCEPT_GUARD(Math::instance.setRandomState(luax_checkrandomstate(L, 1));)
return 0;
}
@@ -79,6 +72,8 @@ int w_newRandomGenerator(lua_State *L)
if (lua_gettop(L) > 0)
{
bool should_error = false;
try
{
t->setState(s);
@@ -86,8 +81,12 @@ int w_newRandomGenerator(lua_State *L)
catch (love::Exception &e)
{
t->release();
return luaL_error(L, "%s", e.what());
should_error = true;
lua_pushstring(L, e.what());
}
if (should_error)
return lua_error(L);
}
luax_pushtype(L, "RandomGenerator", MATH_RANDOM_GENERATOR_T, t);
@@ -169,17 +168,13 @@ int w_triangulate(lua_State *L)
return luaL_error(L, "Need at least 3 vertices to triangulate");
std::vector<Triangle> triangles;
try
{
EXCEPT_GUARD(
if (vertices.size() == 3)
triangles.push_back(Triangle(vertices[0], vertices[1], vertices[2]));
else
triangles = Math::instance.triangulate(vertices);
}
catch (love::Exception &e)
{
return luaL_error(L, e.what());
}
)
lua_createtable(L, triangles.size(), 0);
for (size_t i = 0; i < triangles.size(); ++i)