Skip to content

Commit 8bcfe07

Browse files
yuvaltassacopybara-github
authored andcommitted
Fix potential division by zero in mj_tendonDot.
PiperOrigin-RevId: 742246626 Change-Id: I1f897bd0ca28e0efdffc5a93fadca35221eaeb38
1 parent 01d4c46 commit 8bcfe07

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

src/engine/engine_core_smooth.c

+2-3
Original file line numberDiff line numberDiff line change
@@ -938,15 +938,14 @@ void mj_tendonDot(const mjModel* m, mjData* d, int id, mjtNum* Jdot) {
938938
// dpnt = 3D position difference, normalize
939939
mjtNum dpnt[3];
940940
mju_sub3(dpnt, wpnt+3, wpnt);
941-
mjtNum norm = mju_norm3(dpnt);
942-
mju_scl3(dpnt, dpnt, 1/norm);
941+
mjtNum norm = mju_normalize3(dpnt);
943942

944943
// dvel = d / dt (dpnt)
945944
mjtNum dvel[3];
946945
mju_sub3(dvel, wvel+3, wvel);
947946
mjtNum dot = mju_dot3(dpnt, dvel);
948947
mju_addToScl3(dvel, dpnt, -dot);
949-
mju_scl3(dvel, dvel, 1/norm);
948+
mju_scl3(dvel, dvel, norm > mjMINVAL ? 1/norm : 0);
950949

951950
// TODO(tassa ) write sparse branch, requires mj_jacDotSparse
952951
// if (mj_isSparse(m)) { ... }

0 commit comments

Comments
 (0)