From 3f3d5a3b49547bb125f6b2c2fdea4eba039875e7 Mon Sep 17 00:00:00 2001 From: Alessio Quaglino Date: Tue, 17 Oct 2023 15:04:38 -0700 Subject: [PATCH] Fix `contactcompare` swapping condition. PiperOrigin-RevId: 574276137 Change-Id: Iafbb6a99c1fb57907d3cb1d0796b6ad718e549d2 --- src/engine/engine_collision_driver.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/engine/engine_collision_driver.c b/src/engine/engine_collision_driver.c index 590f5852..11433b0c 100644 --- a/src/engine/engine_collision_driver.c +++ b/src/engine/engine_collision_driver.c @@ -238,7 +238,8 @@ quicksortfunc(contactcompare, context, el1, el2) { // for geom:geom, reproduce the order of contacts without mj_collideTree // normally sorted by (g1, g2), but in mj_collideGeoms, g1 and g2 are swapped based on geom_type // here we undo this swapping for the purpose of sorting - needs to be done for each mjContact - if (c1->geom[0] >= 0 && c1->geom[1] && c2->geom[0] >= 0 && c2->geom[1]) { + if (c1->geom[0] >= 0 && c1->geom[1] >= 0 && + c2->geom[0] >= 0 && c2->geom[1] >= 0) { if (m->geom_type[con1_obj1] > m->geom_type[con1_obj2]) { int tmp = con1_obj1; con1_obj1 = con1_obj2;