summaryrefslogtreecommitdiff
path: root/src/lib/ephysics
diff options
context:
space:
mode:
authorCarsten Haitzler (Rasterman) <raster@rasterman.com>2014-08-22 19:55:45 +0900
committerCarsten Haitzler (Rasterman) <raster@rasterman.com>2014-08-22 20:14:59 +0900
commit56dc04b019bc401ce6b581ee779dbb816ebef234 (patch)
tree812ee54138f9dc5b9267225893add6d26368f1f3 /src/lib/ephysics
parentf764b8e644d55af768c94e8c30e3d6cc76c26fc3 (diff)
ehysics - fix potential divide by zero
fix CID 1039435
Diffstat (limited to 'src/lib/ephysics')
-rw-r--r--src/lib/ephysics/ephysics_body.cpp15
1 files changed, 9 insertions, 6 deletions
diff --git a/src/lib/ephysics/ephysics_body.cpp b/src/lib/ephysics/ephysics_body.cpp
index 48ef8cf..9e1e87c 100644
--- a/src/lib/ephysics/ephysics_body.cpp
+++ b/src/lib/ephysics/ephysics_body.cpp
@@ -1004,8 +1004,8 @@ _ephysics_body_soft_body_mass_set(EPhysics_Body *body, double mass)
1004 double inverse_mass; 1004 double inverse_mass;
1005 1005
1006 if (body->type == EPHYSICS_BODY_TYPE_SOFT) 1006 if (body->type == EPHYSICS_BODY_TYPE_SOFT)
1007 body->soft_body->setTotalMass(mass); 1007 body->soft_body->setTotalMass(mass);
1008 else 1008 else if (mass > 0.0)
1009 { 1009 {
1010 valid_nodes = 0; 1010 valid_nodes = 0;
1011 for (int i = 0; i < body->soft_body->m_nodes.size(); i++) 1011 for (int i = 0; i < body->soft_body->m_nodes.size(); i++)
@@ -1015,12 +1015,15 @@ _ephysics_body_soft_body_mass_set(EPhysics_Body *body, double mass)
1015 valid_nodes++; 1015 valid_nodes++;
1016 } 1016 }
1017 1017
1018 inverse_mass = 1 / (mass / valid_nodes); 1018 if (valid_nodes > 0)
1019 if (body->dragging_data.dragging)
1020 { 1019 {
1021 valid_nodes++;
1022 inverse_mass = 1 / (mass / valid_nodes); 1020 inverse_mass = 1 / (mass / valid_nodes);
1023 body->dragging_data.mass = inverse_mass; 1021 if (body->dragging_data.dragging)
1022 {
1023 valid_nodes++;
1024 inverse_mass = 1 / (mass / valid_nodes);
1025 body->dragging_data.mass = inverse_mass;
1026 }
1024 } 1027 }
1025 1028
1026 for (int i = 0; i < body->soft_body->m_nodes.size(); i++) 1029 for (int i = 0; i < body->soft_body->m_nodes.size(); i++)