From 395a0028018f496fcc513a146e25d5783e79b067 Mon Sep 17 00:00:00 2001 From: Haroon Qureshi Date: Fri, 8 May 2026 04:49:44 -0700 Subject: [PATCH] Small usability fixes. - allow reloading of files that failed to load - clear errors on successful reload PiperOrigin-RevId: 912458744 Change-Id: Ie6af87508f10e83461bc998c99c9c66e2d58312e --- src/experimental/studio/app.cc | 23 +++++++++++------------ src/experimental/studio/app.h | 3 --- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/src/experimental/studio/app.cc b/src/experimental/studio/app.cc index 3952c9f9..f30c6551 100644 --- a/src/experimental/studio/app.cc +++ b/src/experimental/studio/app.cc @@ -106,17 +106,6 @@ void App::SwitchGraphicsMode(int width, int height, window_->GetNativeWindowHandle(), gfx_mode_); } -void App::ClearModel() { - model_holder_.reset(); - window_->SetTitle("MuJoCo Studio"); - step_control_.SetSpeed(100.f); - profiler_.Clear(); - tmp_ = UiTempState(); - load_error_ = ""; - step_error_ = ""; - edit_error_ = ""; -} - void App::Recompile() { mj_recompile(model_holder_->spec(), model_holder_->vfs(), model_holder_->model(), model_holder_->data()); @@ -129,7 +118,8 @@ void App::RequestModelLoad(std::string model_file) { } void App::RequestModelReload() { - if (model_kind_ == kModelFromFile) { + if (model_kind_ == kModelFromFile || + (model_kind_ == kEmptyModel && !model_path_.empty())) { pending_load_ = model_path_; preserve_camera_on_load_ = true; } @@ -158,6 +148,9 @@ void App::LoadModelFromFile(const std::string& filepath) { } } else { SetLoadError(std::string(model_holder_->error())); + // Keep track of the attempted load in case the user fixes the error and + // tries to reload the same file again. + model_path_ = resolved_file; } } @@ -175,6 +168,10 @@ void App::LoadModelFromBuffer(std::span buffer, } void App::OnModelLoaded(std::string filename, ModelKind model_kind) { + load_error_ = ""; + step_error_ = ""; + edit_error_ = ""; + model_path_ = std::move(filename); if (model_kind_ == kEmptyModel) { @@ -243,6 +240,8 @@ void App::UpdateFilePaths(const std::string& resolved_path) { void App::SetLoadError(std::string error) { InitEmptyModel(); load_error_ = std::move(error); + step_error_ = ""; + edit_error_ = ""; } void App::ResetPhysics() { diff --git a/src/experimental/studio/app.h b/src/experimental/studio/app.h index bef5f6ed..52059644 100644 --- a/src/experimental/studio/app.h +++ b/src/experimental/studio/app.h @@ -175,9 +175,6 @@ class App { // Requests that the currently loaded model be reloaded at the next update. void RequestModelReload(); - // Clears the currently loaded model and all associated state. - void ClearModel(); - // Recompiles the spec, updating the model and data. void Recompile();