From acf7f030a6781e934550b7fc51cea8c6de7a5713 Mon Sep 17 00:00:00 2001 From: Kyle Bayes Date: Wed, 11 Mar 2026 04:54:58 -0700 Subject: [PATCH] Remove const qualifier from mjData in mj_geomDistance. The function mj_geomDistance will require data stack space as nativeccd memory is determined from opt.ccd_iterations. PiperOrigin-RevId: 881946592 Change-Id: I524b9fa41018a581e58647d44de6ca3db4c6608b --- doc/includes/references.h | 4 ++-- include/mujoco/mujoco.h | 4 ++-- python/mujoco/functions.cc | 2 +- python/mujoco/introspect/functions.py | 2 +- src/engine/engine_support.c | 4 ++-- src/engine/engine_support.h | 4 ++-- wasm/codegen/generated/bindings.cc | 2 +- 7 files changed, 11 insertions(+), 11 deletions(-) diff --git a/doc/includes/references.h b/doc/includes/references.h index c0bf11bc..8c79e7b8 100644 --- a/doc/includes/references.h +++ b/doc/includes/references.h @@ -3293,8 +3293,8 @@ void mj_objectVelocity(const mjModel* m, const mjData* d, int objtype, int objid, mjtNum res[6], int flg_local); void mj_objectAcceleration(const mjModel* m, const mjData* d, int objtype, int objid, mjtNum res[6], int flg_local); -mjtNum mj_geomDistance(const mjModel* m, const mjData* d, int geom1, int geom2, - mjtNum distmax, mjtNum fromto[6]); +mjtNum mj_geomDistance(const mjModel* m, mjData* d, int geom1, int geom2, mjtNum distmax, + mjtNum fromto[6]); void mj_contactForce(const mjModel* m, const mjData* d, int id, mjtNum result[6]); void mj_differentiatePos(const mjModel* m, mjtNum* qvel, mjtNum dt, const mjtNum* qpos1, const mjtNum* qpos2); diff --git a/include/mujoco/mujoco.h b/include/mujoco/mujoco.h index 4578bc85..c938d8db 100644 --- a/include/mujoco/mujoco.h +++ b/include/mujoco/mujoco.h @@ -609,8 +609,8 @@ MJAPI void mj_objectAcceleration(const mjModel* m, const mjData* d, // Return smallest signed distance between two geoms and optionally segment from geom1 to geom2. // Nullable: fromto -MJAPI mjtNum mj_geomDistance(const mjModel* m, const mjData* d, int geom1, int geom2, - mjtNum distmax, mjtNum fromto[6]); +MJAPI mjtNum mj_geomDistance(const mjModel* m, mjData* d, int geom1, int geom2, mjtNum distmax, + mjtNum fromto[6]); // Extract 6D force:torque given contact id, in the contact frame. MJAPI void mj_contactForce(const mjModel* m, const mjData* d, int id, mjtNum result[6]); diff --git a/python/mujoco/functions.cc b/python/mujoco/functions.cc index 776e8ae4..d6e0c724 100644 --- a/python/mujoco/functions.cc +++ b/python/mujoco/functions.cc @@ -663,7 +663,7 @@ PYBIND11_MODULE(_functions, pymodule) { Def(pymodule); Def( pymodule, - [](const raw::MjModel* m, const raw::MjData* d, + [](const raw::MjModel* m, raw::MjData* d, int geom1, int geom2, mjtNum distmax, std::optional> fromto) { if (fromto.has_value() && fromto->size() != 6) { diff --git a/python/mujoco/introspect/functions.py b/python/mujoco/introspect/functions.py index a1e2d806..bf608c26 100644 --- a/python/mujoco/introspect/functions.py +++ b/python/mujoco/introspect/functions.py @@ -3626,7 +3626,7 @@ FUNCTIONS: Mapping[str, FunctionDecl] = dict([ FunctionParameterDecl( name='d', type=PointerType( - inner_type=ValueType(name='mjData', is_const=True), + inner_type=ValueType(name='mjData'), ), ), FunctionParameterDecl( diff --git a/src/engine/engine_support.c b/src/engine/engine_support.c index fc0dab5e..7c42ba3e 100644 --- a/src/engine/engine_support.c +++ b/src/engine/engine_support.c @@ -524,7 +524,7 @@ void mj_xfrcAccumulate(const mjModel* m, mjData* d, mjtNum* qfrc) { //-------------------------- miscellaneous --------------------------------------------------------- // returns the smallest distance between two geoms (using nativeccd) -static mjtNum mj_geomDistanceCCD(const mjModel* m, const mjData* d, int g1, int g2, +static mjtNum mj_geomDistanceCCD(const mjModel* m, mjData* d, int g1, int g2, mjtNum distmax, mjtNum fromto[6]) { mjCCDConfig config; mjCCDStatus status; @@ -553,7 +553,7 @@ static mjtNum mj_geomDistanceCCD(const mjModel* m, const mjData* d, int g1, int // returns the smallest distance between two geoms -mjtNum mj_geomDistance(const mjModel* m, const mjData* d, int geom1, int geom2, mjtNum distmax, +mjtNum mj_geomDistance(const mjModel* m, mjData* d, int geom1, int geom2, mjtNum distmax, mjtNum fromto[6]) { mjContact con[mjMAXCONPAIR]; mjtNum dist = distmax; diff --git a/src/engine/engine_support.h b/src/engine/engine_support.h index 04125ed3..7e1fd911 100644 --- a/src/engine/engine_support.h +++ b/src/engine/engine_support.h @@ -86,8 +86,8 @@ void mj_xfrcAccumulate(const mjModel* m, mjData* d, mjtNum* qfrc); //-------------------------- miscellaneous --------------------------------------------------------- // returns the smallest distance between two geoms -MJAPI mjtNum mj_geomDistance(const mjModel* m, const mjData* d, int geom1, int geom2, - mjtNum distmax, mjtNum fromto[6]); +MJAPI mjtNum mj_geomDistance(const mjModel* m, mjData* d, int geom1, int geom2, mjtNum distmax, + mjtNum fromto[6]); // compute velocity by finite-differencing two positions MJAPI void mj_differentiatePos(const mjModel* m, mjtNum* qvel, mjtNum dt, diff --git a/wasm/codegen/generated/bindings.cc b/wasm/codegen/generated/bindings.cc index 9c83a652..dfcb4a68 100644 --- a/wasm/codegen/generated/bindings.cc +++ b/wasm/codegen/generated/bindings.cc @@ -8599,7 +8599,7 @@ void mj_fwdVelocity_wrapper(const MjModel& m, MjData& d) { mj_fwdVelocity(m.get(), d.get()); } -mjtNum mj_geomDistance_wrapper(const MjModel& m, const MjData& d, int geom1, int geom2, mjtNum distmax, const val& fromto) { +mjtNum mj_geomDistance_wrapper(const MjModel& m, MjData& d, int geom1, int geom2, mjtNum distmax, const val& fromto) { UNPACK_NULLABLE_VALUE(mjtNum, fromto); CHECK_SIZE(fromto, 6); return mj_geomDistance(m.get(), d.get(), geom1, geom2, distmax, fromto_.data());