Improve error messages in LoadMujocoModel

PiperOrigin-RevId: 817565307
Change-Id: I367298cdf77d26b6f8deb5c6a0d5c3cab1e4d065
This commit is contained in:
Matija Kecman
2025-10-10 03:23:41 -07:00
committed by Copybara-Service
parent 38af2e2d00
commit 59a5a7bf5f
+7 -3
View File
@@ -43,20 +43,24 @@ mjModel* LoadMujocoModel(const std::string& model_file, const mjVFS* vfs) {
} else if (model_file.ends_with(".mjb")) { } else if (model_file.ends_with(".mjb")) {
model = mj_loadModel(model_file.c_str(), 0); model = mj_loadModel(model_file.c_str(), 0);
if (!model) { if (!model) {
mju_error("Could not load binary model"); mju_error("LoadMujocoModel mj_loadModel could not load file '%s'",
model_file.c_str());
} }
} else if (model_file.ends_with(".xml")) { } else if (model_file.ends_with(".xml")) {
char error[1000] = ""; char error[1000] = "";
model = mj_loadXML(model_file.c_str(), vfs, error, sizeof(error)); model = mj_loadXML(model_file.c_str(), vfs, error, sizeof(error));
if (!model) { if (!model) {
mju_error("Load model error: %s", error); mju_error("LoadMujocoModel mj_loadXML failed with '%s' for file '%s'",
error, model_file.c_str());
} }
} else { } else {
char error[1000] = ""; char error[1000] = "";
auto spec = auto spec =
mj_parseXMLString(model_file.c_str(), nullptr, error, sizeof(error)); mj_parseXMLString(model_file.c_str(), nullptr, error, sizeof(error));
if (!spec) { if (!spec) {
mju_error("Load model error: %s", error); mju_error(
"LoadMujocoModel mj_parseXMLString failed with '%s' for file '%s'",
error, model_file.c_str());
} }
model = mj_compile(spec, 0); model = mj_compile(spec, 0);
mj_deleteSpec(spec); mj_deleteSpec(spec);