Raise appropriate errors for mj_addBufferVFS in Python bindings.

When loading models in the XML bindings, different issues with the asset dictionary were all reported as "assets dict is too big".

PiperOrigin-RevId: 670960339
Change-Id: I2e47d91a6b433fd90ebdf9960a9b5b47413af410
This commit is contained in:
Nimrod Gileadi
2024-09-04 07:19:27 -07:00
committed by Copybara-Service
parent e9a85764ea
commit 9a27fc14c2
3 changed files with 16 additions and 2 deletions
+7 -1
View File
@@ -345,7 +345,13 @@ static raw::MjModel* LoadModelFileImpl(
const int vfs_error = InterceptMjErrors(mj_addBufferVFS)(
vfs_ptr, buffer_name.c_str(), asset.content, asset.content_size);
if (vfs_error) {
throw py::value_error("assets dict is too big");
mj_deleteVFS(vfs_ptr);
if (vfs_error == 2) {
throw py::value_error("Repeated file name in assets dict: " +
buffer_name);
} else {
throw py::value_error("Asset failed to load: " + buffer_name);
}
}
}
}