From 65048d6b8ffaaeb74968622bba60ef89410e2f56 Mon Sep 17 00:00:00 2001 From: Alessio Quaglino Date: Mon, 6 Jan 2025 04:16:56 -0800 Subject: [PATCH] Do not use fast lookup for frames. Fast lookup is not possible since mjOBJ_FRAME > mjNOBJECT, which is the size of the objects maps used for the search. Fixes #2328. PiperOrigin-RevId: 712479460 Change-Id: I7bcfa75ff8a1e288183d60ed4a44cab5bc6f4173 --- src/user/user_api.cc | 2 +- test/user/user_api_test.cc | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/user/user_api.cc b/src/user/user_api.cc index af465e75..af7cd9b5 100644 --- a/src/user/user_api.cc +++ b/src/user/user_api.cc @@ -614,7 +614,7 @@ mjsBody* mjs_findBody(mjSpec* s, const char* name) { // find element in spec by name mjsElement* mjs_findElement(mjSpec* s, mjtObj type, const char* name) { mjCModel* model = static_cast(s->element); - if (model->IsCompiled()) { + if (model->IsCompiled() && type != mjOBJ_FRAME) { return model->FindObject(type, std::string(name)); // fast lookup } switch (type) { diff --git a/test/user/user_api_test.cc b/test/user/user_api_test.cc index 67b7282d..c6620c1c 100644 --- a/test/user/user_api_test.cc +++ b/test/user/user_api_test.cc @@ -1014,6 +1014,9 @@ TEST_F(MujocoTest, AttachDifferent) { mjModel* m_attached = mj_compile(parent, 0); EXPECT_THAT(m_attached, NotNull()); + // check frame is present + EXPECT_THAT(mjs_findFrame(parent, "frame"), NotNull()); + // check full name stored in mjModel EXPECT_STREQ(mj_id2name(m_attached, mjOBJ_BODY, 2), "attached-body-1");