36 lines
875 B
Diff
36 lines
875 B
Diff
|
From 6a5767cc5a6c8f88f8cc689c0916ddc0111308fe Mon Sep 17 00:00:00 2001
|
||
|
From: Bram Stolk <b.stolk@gmail.com>
|
||
|
Date: Fri, 30 Mar 2018 19:21:26 -0700
|
||
|
Subject: [PATCH] Fix issue #144 of division by zero when setting zero mass,
|
||
|
zero moment.
|
||
|
|
||
|
---
|
||
|
src/cpBody.c | 4 ++--
|
||
|
1 file changed, 2 insertions(+), 2 deletions(-)
|
||
|
|
||
|
diff --git src/cpBody.c src/cpBody.c
|
||
|
index a8e0797..8ad2bc9 100644
|
||
|
--- src/cpBody.c
|
||
|
+++ src/cpBody.c
|
||
|
@@ -258,7 +258,7 @@ cpBodySetMass(cpBody *body, cpFloat mass)
|
||
|
|
||
|
cpBodyActivate(body);
|
||
|
body->m = mass;
|
||
|
- body->m_inv = 1.0f/mass;
|
||
|
+ body->m_inv = mass == 0.0f ? INFINITY : 1.0f/mass;
|
||
|
cpAssertSaneBody(body);
|
||
|
}
|
||
|
|
||
|
@@ -275,7 +275,7 @@ cpBodySetMoment(cpBody *body, cpFloat moment)
|
||
|
|
||
|
cpBodyActivate(body);
|
||
|
body->i = moment;
|
||
|
- body->i_inv = 1.0f/moment;
|
||
|
+ body->i_inv = moment == 0.0f ? INFINITY : 1.0f/moment;
|
||
|
cpAssertSaneBody(body);
|
||
|
}
|
||
|
|
||
|
--
|
||
|
2.21.0
|
||
|
|