From adc3cc06fae838ee8dda0eeb4522c7c6b5d5c87f Mon Sep 17 00:00:00 2001 From: Alessio Quaglino Date: Mon, 10 Mar 2025 04:18:32 -0700 Subject: [PATCH] Change private->public spec for error checking in mjCSkin recompilation. Fixes #2485. PiperOrigin-RevId: 735323174 Change-Id: Ifcc2055f6a74afaa18ad5228633f36f760adcffd --- src/user/user_mesh.cc | 19 +++++++++---------- test/user/testdata/cube.skn | Bin 0 -> 504 bytes test/user/testdata/cube.stl | Bin 0 -> 684 bytes test/user/testdata/cube_skin.xml | 13 +++++++++++++ test/user/user_mesh_test.cc | 15 +++++++++++++++ 5 files changed, 37 insertions(+), 10 deletions(-) create mode 100644 test/user/testdata/cube.skn create mode 100644 test/user/testdata/cube.stl create mode 100644 test/user/testdata/cube_skin.xml diff --git a/src/user/user_mesh.cc b/src/user/user_mesh.cc index 32b281de..7c691dc8 100644 --- a/src/user/user_mesh.cc +++ b/src/user/user_mesh.cc @@ -2526,16 +2526,15 @@ void mjCSkin::Compile(const mjVFS* vfs) { // load file if (!file_.empty()) { // make sure data is not present - if (!vert_.empty() || - !texcoord_.empty() || - !face_.empty() || - !bodyname_.empty() || - !bindpos_.empty() || - !bindquat_.empty() || - !vertid_.empty() || - !vertweight_.empty() || - !bodyid.empty()) { - throw mjCError(this, "Data already exists, trying to load from skin file: %s", file_.c_str()); + if (!spec_vert_.empty() || + !spec_texcoord_.empty() || + !spec_face_.empty() || + !spec_bodyname_.empty() || + !spec_bindpos_.empty() || + !spec_bindquat_.empty() || + !spec_vertid_.empty() || + !spec_vertweight_.empty()) { + throw mjCError(this, "Both skin data and file were specified: %s", file_.c_str()); } // remove path from file if necessary diff --git a/test/user/testdata/cube.skn b/test/user/testdata/cube.skn new file mode 100644 index 0000000000000000000000000000000000000000..498a792621097f9b04c7721f1f993f08859746c6 GIT binary patch literal 504 zcma)&O%8%U427$r5^umcW{q5cQy7*eByM!+HS{jtV7Qb0n3i(4ys)FM(V zE{eTk%Ka~(4Vt>=uxsid*1YGng}H>g9yWIrR$6K8_H65Qj7O+|vAe6#xJL literal 0 HcmV?d00001 diff --git a/test/user/testdata/cube_skin.xml b/test/user/testdata/cube_skin.xml new file mode 100644 index 00000000..69004072 --- /dev/null +++ b/test/user/testdata/cube_skin.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/test/user/user_mesh_test.cc b/test/user/user_mesh_test.cc index 2e1eb1e0..167b1480 100644 --- a/test/user/user_mesh_test.cc +++ b/test/user/user_mesh_test.cc @@ -66,6 +66,8 @@ static const char* const kDuplicateOBJPath = "user/testdata/duplicate.xml"; static const char* const kMalformedFaceOBJPath = "user/testdata/malformed_face.xml"; +static const char* const kCubeSkinPath = + "user/testdata/cube_skin.xml"; using ::testing::ElementsAre; using ::testing::HasSubstr; @@ -1184,6 +1186,19 @@ TEST_F(MjCMeshTest, InvalidIndexInFace) { mj_deleteModel(model); } +TEST_F(MjCMeshTest, LoadSkin) { + const std::string xml_path = GetTestDataFilePath(kCubeSkinPath); + std::array error; + mjSpec* spec = mj_parseXML(xml_path.c_str(), 0, error.data(), error.size()); + EXPECT_THAT(spec, NotNull()) << error.data(); + mjModel* m1 = mj_compile(spec, 0); + EXPECT_THAT(m1, NotNull()); + mj_deleteModel(m1); + mjModel* m2 = mj_compile(spec, 0); + EXPECT_THAT(m2, NotNull()); + mj_deleteModel(m2); + mj_deleteSpec(spec); +} } // namespace