Skip to content

Commit 65048d6

Browse files
quaglacopybara-github
authored andcommitted
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
1 parent daed8f4 commit 65048d6

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

src/user/user_api.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,7 @@ mjsBody* mjs_findBody(mjSpec* s, const char* name) {
614614
// find element in spec by name
615615
mjsElement* mjs_findElement(mjSpec* s, mjtObj type, const char* name) {
616616
mjCModel* model = static_cast<mjCModel*>(s->element);
617-
if (model->IsCompiled()) {
617+
if (model->IsCompiled() && type != mjOBJ_FRAME) {
618618
return model->FindObject(type, std::string(name)); // fast lookup
619619
}
620620
switch (type) {

test/user/user_api_test.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,6 +1014,9 @@ TEST_F(MujocoTest, AttachDifferent) {
10141014
mjModel* m_attached = mj_compile(parent, 0);
10151015
EXPECT_THAT(m_attached, NotNull());
10161016

1017+
// check frame is present
1018+
EXPECT_THAT(mjs_findFrame(parent, "frame"), NotNull());
1019+
10171020
// check full name stored in mjModel
10181021
EXPECT_STREQ(mj_id2name(m_attached, mjOBJ_BODY, 2), "attached-body-1");
10191022

0 commit comments

Comments
 (0)