Improve error handling of spec editor compilation.
PiperOrigin-RevId: 875703124 Change-Id: Idf4a90a48d75185ad03e4469cee9098104751d67
This commit is contained in:
committed by
Copybara-Service
parent
19b583a421
commit
55d7226b06
@@ -78,7 +78,7 @@ void ModelHolder::PostInit() {
|
|||||||
if (spec_ && !model_) {
|
if (spec_ && !model_) {
|
||||||
model_ = mj_compile(spec_, &vfs_);
|
model_ = mj_compile(spec_, &vfs_);
|
||||||
if (!model_) {
|
if (!model_) {
|
||||||
SetLoadError("Error compiling model from spec.");
|
SetLoadError(mjs_getError(spec_));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1287,9 +1287,15 @@ void App::SpecEditorGui() {
|
|||||||
ImGui::PushStyleColor(ImGuiCol_Button, ImColor(40, 180, 40, 255).Value);
|
ImGui::PushStyleColor(ImGuiCol_Button, ImColor(40, 180, 40, 255).Value);
|
||||||
if (ImGui::Button("Compile and Reload", ImVec2(-1, 0))) {
|
if (ImGui::Button("Compile and Reload", ImVec2(-1, 0))) {
|
||||||
spec_op_ = [this]() {
|
spec_op_ = [this]() {
|
||||||
model_holder_ = platform::ModelHolder::FromSpec(scratch_spec_);
|
auto tmp_holder = platform::ModelHolder::FromSpec(scratch_spec_);
|
||||||
scratch_spec_ = nullptr;
|
if (tmp_holder->ok()) {
|
||||||
OnModelLoaded(model_name_, model_kind_);
|
model_holder_ = std::move(tmp_holder);
|
||||||
|
scratch_spec_ = nullptr;
|
||||||
|
OnModelLoaded(model_name_, model_kind_);
|
||||||
|
} else {
|
||||||
|
scratch_spec_ = tmp_holder->ReleaseSpec();
|
||||||
|
load_error_ = std::move(tmp_holder->error());
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
ImGui::PopStyleColor();
|
ImGui::PopStyleColor();
|
||||||
|
|||||||
Reference in New Issue
Block a user