diff --git a/doc/changelog.rst b/doc/changelog.rst index 72ece7b1..5f976430 100644 --- a/doc/changelog.rst +++ b/doc/changelog.rst @@ -75,6 +75,11 @@ General `AVX `_ instructions on x86-64 machines, which is not supported by Rosetta 2. (Before this version, users only get a cryptic "Illegal instruction" message.) +Bug fixes +^^^^^^^^^ + +- Fixed bug in ``mj_addFileVFS`` that was causing the file path to be ignored (introduced in 2.1.4). + Simulate ^^^^^^^^ diff --git a/src/engine/engine_vfs.c b/src/engine/engine_vfs.c index fa9edbc4..ff5a9559 100644 --- a/src/engine/engine_vfs.c +++ b/src/engine/engine_vfs.c @@ -93,7 +93,7 @@ int mj_addFileVFS(mjVFS* vfs, const char* directory, const char* filename) { // allocate and read int filesize = 0; - vfs->filedata[vfs->nfile] = mju_fileToMemory(filename, &filesize); + vfs->filedata[vfs->nfile] = mju_fileToMemory(fullname, &filesize); if (!vfs->filedata[vfs->nfile]) { return -1; } diff --git a/test/engine/CMakeLists.txt b/test/engine/CMakeLists.txt index c536572e..5cb8e05c 100644 --- a/test/engine/CMakeLists.txt +++ b/test/engine/CMakeLists.txt @@ -69,3 +69,6 @@ target_link_libraries(engine_util_solve_test fixture gmock) mujoco_test(engine_util_spatial_test) target_link_libraries(engine_util_spatial_test fixture gmock) + +mujoco_test(engine_vfs_test) +target_link_libraries(engine_vfs_test fixture gmock) diff --git a/test/engine/engine_vfs_test.cc b/test/engine/engine_vfs_test.cc new file mode 100644 index 00000000..1092319b --- /dev/null +++ b/test/engine/engine_vfs_test.cc @@ -0,0 +1,47 @@ +// Copyright 2021 DeepMind Technologies Limited +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include +#include + +#include +#include +#include +#include "test/fixture.h" + +namespace mujoco { +namespace { + +using ::testing::NotNull; +using EngineVfsTest = MujocoTest; + +TEST_F(EngineVfsTest, AddFileVFS) { + constexpr char path[] = "engine/testdata/"; + const std::string dir = GetTestDataFilePath(path); + std::string file = "refsite.xml"; + + std::FILE* fp = std::fopen((dir + file).c_str(), "r"); + ASSERT_THAT(fp, NotNull()) << "Input file missing."; + std::fclose(fp); + + auto mj_vfs = std::make_unique(); + mj_defaultVFS(mj_vfs.get()); + EXPECT_THAT(mj_addFileVFS(mj_vfs.get(), dir.c_str(), file.c_str()), 0); + EXPECT_THAT(mj_vfs->nfile, 1); + mj_deleteFileVFS(mj_vfs.get(), file.c_str()); + mj_deleteVFS(mj_vfs.get()); +} + +} // namespace +} // namespace mujoco