From cf3e60f9a42aa20c5546993045e8d521f728fcf6 Mon Sep 17 00:00:00 2001 From: Yuval Tassa Date: Wed, 21 Aug 2024 02:53:03 -0700 Subject: [PATCH] Fix load time reporting in simulate. Before this change, a model which took more than 1/4 seconds to load caused the simulation to pause, which is a behavior that is only supposed to occur for models that loaded with a warning. PiperOrigin-RevId: 665786861 Change-Id: Ie3a6c8d18a6abbb425a0bbcc5a8e55d5fd7a0c72 --- simulate/main.cc | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/simulate/main.cc b/simulate/main.cc index 15316383..ac4d7b36 100644 --- a/simulate/main.cc +++ b/simulate/main.cc @@ -245,13 +245,6 @@ mjModel* LoadModel(const char* file, mj::Simulate& sim) { auto load_interval = mj::Simulate::Clock::now() - load_start; double load_seconds = Seconds(load_interval).count(); - // if no error and load took more than 1/4 seconds, report load time - if (!loadError[0] && load_seconds > 0.25) { - mju::sprintf_arr(loadError, "Model loaded in %.2g seconds", load_seconds); - } - - mju::strcpy_arr(sim.load_error, loadError); - if (!mnew) { std::printf("%s\n", loadError); return nullptr; @@ -264,6 +257,13 @@ mjModel* LoadModel(const char* file, mj::Simulate& sim) { sim.run = 0; } + // if no error and load took more than 1/4 seconds, report load time + if (!loadError[0] && load_seconds > 0.25) { + mju::sprintf_arr(loadError, "Model loaded in %.2g seconds", load_seconds); + } + + mju::strcpy_arr(sim.load_error, loadError); + return mnew; }