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")) {
|
||||
model = mj_loadModel(model_file.c_str(), 0);
|
||||
if (!model) {
|
||||
mju_error("LoadMujocoModel mj_loadModel could not load file '%s'",
|
||||
model_file.c_str());
|
||||
return nullptr;
|
||||
}
|
||||
} else if (model_file.ends_with(".xml")) {
|
||||
char error[1000] = "";
|
||||
model = mj_loadXML(model_file.c_str(), vfs, error, sizeof(error));
|
||||
if (!model) {
|
||||
mju_error("LoadMujocoModel mj_loadXML failed with '%s' for file '%s'",
|
||||
error, model_file.c_str());
|
||||
return nullptr;
|
||||
}
|
||||
} else {
|
||||
char error[1000] = "";
|
||||
auto spec =
|
||||
mj_parseXMLString(model_file.c_str(), nullptr, error, sizeof(error));
|
||||
if (!spec) {
|
||||
mju_error(
|
||||
"LoadMujocoModel mj_parseXMLString failed with '%s' for file '%s'",
|
||||
error, model_file.c_str());
|
||||
return nullptr;
|
||||
}
|
||||
model = mj_compile(spec, 0);
|
||||
mj_deleteSpec(spec);
|
||||
|
||||
@@ -60,10 +60,17 @@ bool Physics::ProcessPendingLoad() {
|
||||
pending_load_.reset();
|
||||
|
||||
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_);
|
||||
if (!data_) mju_error("Error making data.");
|
||||
if (!data_) {
|
||||
error_ = "Error making data!";
|
||||
paused_ = true;
|
||||
}
|
||||
|
||||
on_model_loaded_(model_file);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user