Skip to content

Log MuJoCo errors through BSKLogger #1022

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/source/Support/bskReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ Version |release|

If you still want to use Visual Studio 16, then be sure to set the generator
using ``python conanfile.py --generator "Visual Studio 16 2019``
- Redirected MuJoCo errors and warnings to ``BSKLogger`` instead of printing to file.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make BSKLogger a hyperlink using

:ref:`bskLogging`



Version 2.7.0 (April 20, 2025)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ MJScene::MJScene(std::string xml, const std::vector<std::string>& files)
{
this->AddFwdKinematicsToDynamicsTask(MJScene::FWD_KINEMATICS_PRIORITY);
this->integrator = new svIntegratorRK4(this);

// Replace default MuJoCo error/warning handling with our own
mju_user_error = MJBasilisk::detail::logMujocoError;
mju_user_warning = MJBasilisk::detail::logMujocoWarning;
}

MJScene MJScene::fromFile(const std::string& fileName)
Expand Down
14 changes: 14 additions & 0 deletions src/simulation/mujocoDynamics/_GeneralModuleFiles/MJUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,20 @@

#include "MJUtils.h"

using namespace std::string_literals;

namespace MJBasilisk::detail
{
void
logMujocoError(const char* err)
{
logAndThrow<std::runtime_error>("MuJoCo internal error: "s + err);
}

void
logMujocoWarning(const char* err)
{
BSKLogger{}.bskLog(BSK_WARNING, ("MuJoCo internal warning: "s + err).c_str());
}

} // namespace MJBasilisk::detail
12 changes: 12 additions & 0 deletions src/simulation/mujocoDynamics/_GeneralModuleFiles/MJUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,18 @@ template <typename T = std::invalid_argument>
throw T(error);
}

/** Calls ``logAndThrow<std::runtime_error>`` with the given input
*
* Meant to be used as an error callback for MuJoCo's ``mju_user_error``.
*/
void logMujocoError(const char* err);

/** Calls ``BSKLogger::bskLog`` with the given input
*
* Meant to be used as an error callback for MuJoCo's ``mju_user_warning``.
*/
void logMujocoWarning(const char* err);

} // namespace MJBasilisk::detail

#endif
Loading