mirror of
https://github.com/love2d/love.git
synced 2026-08-20 04:30:09 +02:00
Fix issue #724: Bezier curve rendering/eval crashes with empty curves.
This commit is contained in:
@@ -162,6 +162,8 @@ Vector BezierCurve::eval(double t) const
|
|||||||
{
|
{
|
||||||
if (t < 0 || t > 1)
|
if (t < 0 || t > 1)
|
||||||
throw Exception("Invalid evaluation parameter: must be between 0 and 1");
|
throw Exception("Invalid evaluation parameter: must be between 0 and 1");
|
||||||
|
if (controlPoints.size() < 2)
|
||||||
|
throw Exception("Invalid Bezier curve: Not enough control points.");
|
||||||
|
|
||||||
// de casteljau
|
// de casteljau
|
||||||
vector<Vector> points(controlPoints);
|
vector<Vector> points(controlPoints);
|
||||||
@@ -174,6 +176,8 @@ Vector BezierCurve::eval(double t) const
|
|||||||
|
|
||||||
vector<Vector> BezierCurve::render(size_t accuracy) const
|
vector<Vector> BezierCurve::render(size_t accuracy) const
|
||||||
{
|
{
|
||||||
|
if (controlPoints.size() < 2)
|
||||||
|
throw Exception("Invalid Bezier curve: Not enough control points.");
|
||||||
vector<Vector> vertices(controlPoints);
|
vector<Vector> vertices(controlPoints);
|
||||||
subdivide(vertices, accuracy);
|
subdivide(vertices, accuracy);
|
||||||
return vertices;
|
return vertices;
|
||||||
|
|||||||
@@ -168,7 +168,15 @@ int w_BezierCurve_render(lua_State *L)
|
|||||||
BezierCurve *curve = luax_checkbeziercurve(L, 1);
|
BezierCurve *curve = luax_checkbeziercurve(L, 1);
|
||||||
int accuracy = luaL_optinteger(L, 2, 5);
|
int accuracy = luaL_optinteger(L, 2, 5);
|
||||||
|
|
||||||
std::vector<Vector> points = curve->render(accuracy);
|
std::vector<Vector> points;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
points = curve->render(accuracy);
|
||||||
|
}
|
||||||
|
catch (Exception &e)
|
||||||
|
{
|
||||||
|
return luaL_error(L, e.what());
|
||||||
|
}
|
||||||
|
|
||||||
lua_createtable(L, points.size()*2, 0);
|
lua_createtable(L, points.size()*2, 0);
|
||||||
for (size_t i = 0; i < points.size(); ++i)
|
for (size_t i = 0; i < points.size(); ++i)
|
||||||
|
|||||||
Reference in New Issue
Block a user