Improve error handling of spec editor compilation.

PiperOrigin-RevId: 875703124
Change-Id: Idf4a90a48d75185ad03e4469cee9098104751d67
This commit is contained in:
Haroon Qureshi
2026-02-26 06:58:06 -08:00
committed by Copybara-Service
parent 19b583a421
commit 55d7226b06
2 changed files with 10 additions and 4 deletions
+1 -1
View File
@@ -78,7 +78,7 @@ void ModelHolder::PostInit() {
if (spec_ && !model_) {
model_ = mj_compile(spec_, &vfs_);
if (!model_) {
SetLoadError("Error compiling model from spec.");
SetLoadError(mjs_getError(spec_));
return;
}
}
+9 -3
View File
@@ -1287,9 +1287,15 @@ void App::SpecEditorGui() {
ImGui::PushStyleColor(ImGuiCol_Button, ImColor(40, 180, 40, 255).Value);
if (ImGui::Button("Compile and Reload", ImVec2(-1, 0))) {
spec_op_ = [this]() {
model_holder_ = platform::ModelHolder::FromSpec(scratch_spec_);
scratch_spec_ = nullptr;
OnModelLoaded(model_name_, model_kind_);
auto tmp_holder = platform::ModelHolder::FromSpec(scratch_spec_);
if (tmp_holder->ok()) {
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();