Display error when loading model.
PiperOrigin-RevId: 830862449 Change-Id: Iab1e8786d79d55db9a15a788ecb37e0b0418111c
This commit is contained in:
committed by
Copybara-Service
parent
b3deb9dd12
commit
4a5a36f3fc
@@ -44,24 +44,20 @@ 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("LoadMujocoModel mj_loadModel could not load file '%s'",
|
return nullptr;
|
||||||
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("LoadMujocoModel mj_loadXML failed with '%s' for file '%s'",
|
return nullptr;
|
||||||
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(
|
return nullptr;
|
||||||
"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);
|
||||||
|
|||||||
@@ -60,10 +60,17 @@ bool Physics::ProcessPendingLoad() {
|
|||||||
pending_load_.reset();
|
pending_load_.reset();
|
||||||
|
|
||||||
model_ = LoadMujocoModel(model_file, vfs_);
|
model_ = LoadMujocoModel(model_file, vfs_);
|
||||||
if (!model_) mju_error("Error loading model");
|
if (!model_) {
|
||||||
|
error_ = "Error loading model!";
|
||||||
|
paused_ = true;
|
||||||
|
model_ = LoadMujocoModel("", vfs_);
|
||||||
|
}
|
||||||
|
|
||||||
data_ = mj_makeData(model_);
|
data_ = mj_makeData(model_);
|
||||||
if (!data_) mju_error("Error making data.");
|
if (!data_) {
|
||||||
|
error_ = "Error making data!";
|
||||||
|
paused_ = true;
|
||||||
|
}
|
||||||
|
|
||||||
on_model_loaded_(model_file);
|
on_model_loaded_(model_file);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user