diff --git a/include/mujoco/mjplugin.h b/include/mujoco/mjplugin.h index 610297bc..55b143df 100644 --- a/include/mujoco/mjplugin.h +++ b/include/mujoco/mjplugin.h @@ -69,7 +69,7 @@ typedef struct mjpResourceProvider mjpResourceProvider; // function pointer types // return an mjSpec representing the decoded resource. -typedef mjSpec* (*mjfDecode)(mjResource* resource); +typedef mjSpec* (*mjfDecode)(mjResource* resource, const mjVFS* vfs); // return true if the given resource can be decoded. typedef int (*mjfCanDecode)(const mjResource* resource); diff --git a/src/user/user_api.cc b/src/user/user_api.cc index 8a327def..257bb453 100644 --- a/src/user/user_api.cc +++ b/src/user/user_api.cc @@ -107,7 +107,7 @@ mjSpec* mj_parse(const char* filename, const char* content_type, memcpy(resource->name, fullname.c_str(), sizeof(char) * (n + 1)); } - mjSpec* spec = mju_decodeResource(resource, content_type); + mjSpec* spec = mju_decodeResource(resource, content_type, vfs); mju_closeResource(resource); return spec; } diff --git a/src/user/user_resource.cc b/src/user/user_resource.cc index 7d07432b..5f2b41d3 100644 --- a/src/user/user_resource.cc +++ b/src/user/user_resource.cc @@ -265,7 +265,7 @@ int mju_isModifiedResource(const mjResource* resource, const char* timestamp) { return FileModified(resource, timestamp); } -mjSpec* mju_decodeResource(mjResource* resource, const char* content_type) { +mjSpec* mju_decodeResource(mjResource* resource, const char* content_type, const mjVFS* vfs) { const mjpDecoder* decoder = nullptr; if (content_type) { decoder = mjp_findDecoder(resource, content_type); @@ -276,6 +276,6 @@ mjSpec* mju_decodeResource(mjResource* resource, const char* content_type) { mju_error("Could not find decoder for resource '%s'", resource->name); } - return decoder->decode(resource); + return decoder->decode(resource, vfs); } diff --git a/src/user/user_resource.h b/src/user/user_resource.h index fc8e6013..01925287 100644 --- a/src/user/user_resource.h +++ b/src/user/user_resource.h @@ -48,7 +48,8 @@ MJAPI int mju_isModifiedResource(const mjResource* resource, const char* timesta // given a resource, find its decoder and return the decoded spec // the caller takes ownership of the spec and is responsible for cleaning it up -MJAPI mjSpec* mju_decodeResource(mjResource* resource, const char* content_type); +MJAPI mjSpec* mju_decodeResource(mjResource* resource, const char* content_type, + const mjVFS* vfs); #ifdef __cplusplus } diff --git a/test/plugin/decoder/decoder_test.cc b/test/plugin/decoder/decoder_test.cc index 58113b14..02ca6513 100644 --- a/test/plugin/decoder/decoder_test.cc +++ b/test/plugin/decoder/decoder_test.cc @@ -39,7 +39,9 @@ static mjSpec* MakeSimpleSpec() { } // Always returns a simple mjSpec, ignoring the resource. -mjSpec* FakeDecode(mjResource* resource) { return MakeSimpleSpec(); } +mjSpec* FakeDecode(mjResource* resource, const mjVFS* vfs) { + return MakeSimpleSpec(); +} // Can decode any resource that has a .fakeformat extension. int FakeCanDecode(const mjResource* resource) { @@ -81,8 +83,7 @@ TEST_F(DecoderPluginTest, CanDecode) { // Check referencing a resource via XML invokes the decoder. char error[1024]; - mjSpec* spec = - mj_parseXMLString(xml, nullptr, error, sizeof(error)); + mjSpec* spec = mj_parseXMLString(xml, nullptr, error, sizeof(error)); mjModel* model = mj_compile(spec, nullptr); ASSERT_THAT(model, testing::NotNull()) << error; EXPECT_EQ(model->nbody, 2); // world + included body @@ -91,8 +92,7 @@ TEST_F(DecoderPluginTest, CanDecode) { mj_deleteSpec(spec); // Check mj_parse with extension .fakeformat - spec = - mj_parse("dummy.fakeformat", nullptr, nullptr, error, sizeof(error)); + spec = mj_parse("dummy.fakeformat", nullptr, nullptr, error, sizeof(error)); model = mj_compile(spec, nullptr); EXPECT_EQ(model->nbody, 2); // world + included body EXPECT_EQ(model->ngeom, 1);