From 5d18933411a91987b1a380e38229d064ed22a3dd Mon Sep 17 00:00:00 2001 From: Josip Miskovic Date: Wed, 3 Jun 2020 20:13:13 +0300 Subject: [PATCH] Limit simulation parameters to positive values --- src/api/l_physics_joints.c | 4 ++++ src/api/l_physics_world.c | 2 ++ 2 files changed, 6 insertions(+) diff --git a/src/api/l_physics_joints.c b/src/api/l_physics_joints.c index 176c4ce0..5bdddd8f 100644 --- a/src/api/l_physics_joints.c +++ b/src/api/l_physics_joints.c @@ -132,6 +132,7 @@ static int l_lovrBallJointGetResponseTime(lua_State* L) { static int l_lovrBallJointSetResponseTime(lua_State* L) { Joint* joint = luax_checkjoint(L, 1); float responseTime = luax_checkfloat(L, 2); + lovrAssert(responseTime >= 0, "Negative response time causes simulation instability"); lovrBallJointSetResponseTime(joint, responseTime); return 0; } @@ -146,6 +147,7 @@ static int l_lovrBallJointGetTightness(lua_State* L) { static int l_lovrBallJointSetTightness(lua_State* L) { Joint* joint = luax_checkjoint(L, 1); float tightness = luax_checkfloat(L, 2); + lovrAssert(tightness >= 0, "Negative tightness factor causes simulation instability"); lovrBallJointSetTightness(joint, tightness); return 0; } @@ -206,6 +208,7 @@ static int l_lovrDistanceJointGetResponseTime(lua_State* L) { static int l_lovrDistanceJointSetResponseTime(lua_State* L) { Joint* joint = luax_checkjoint(L, 1); float responseTime = luax_checkfloat(L, 2); + lovrAssert(responseTime >= 0, "Negative response time causes simulation instability"); lovrDistanceJointSetResponseTime(joint, responseTime); return 0; } @@ -220,6 +223,7 @@ static int l_lovrDistanceJointGetTightness(lua_State* L) { static int l_lovrDistanceJointSetTightness(lua_State* L) { Joint* joint = luax_checkjoint(L, 1); float tightness = luax_checkfloat(L, 2); + lovrAssert(tightness >= 0, "Negative tightness factor causes simulation instability"); lovrDistanceJointSetTightness(joint, tightness); return 0; } diff --git a/src/api/l_physics_world.c b/src/api/l_physics_world.c index f87f8208..1d2b5ffa 100644 --- a/src/api/l_physics_world.c +++ b/src/api/l_physics_world.c @@ -190,6 +190,7 @@ static int l_lovrWorldSetGravity(lua_State* L) { static int l_lovrWorldGetTightness(lua_State* L) { World* world = luax_checktype(L, 1, World); float tightness = lovrWorldGetTightness(world); + lovrAssert(tightness >= 0, "Negative tightness factor causes simulation instability"); lua_pushnumber(L, tightness); return 1; } @@ -211,6 +212,7 @@ static int l_lovrWorldGetResponseTime(lua_State* L) { static int l_lovrWorldSetResponseTime(lua_State* L) { World* world = luax_checktype(L, 1, World); float responseTime = luax_checkfloat(L, 2); + lovrAssert(responseTime >= 0, "Negative response time causes simulation instability"); lovrWorldSetResponseTime(world, responseTime); return 0; }