Raise an informative error when running on macOS under Rosetta 2.

Current users only get a cryptic "Illegal instruction" crash.

Context: https://github.com/deepmind/mujoco/issues/611
PiperOrigin-RevId: 491705647
Change-Id: I1285897a36e858300ee3d125957e90754be9a7f7
This commit is contained in:
Saran Tunyasuvunakool
2022-11-29 12:17:58 -08:00
committed by Copybara-Service
parent 5f7d9f4f02
commit df25d7d602
9 changed files with 93 additions and 9 deletions
+17
View File
@@ -437,8 +437,25 @@ void PhysicsThread(mj::Simulate* sim, const char* filename) {
//------------------------------------------ main --------------------------------------------------
// machinery for replacing command line error by a macOS dialog box when running under Rosetta
#if defined(__APPLE__) && defined(__AVX__)
extern void DisplayErrorDialogBox(const char* title, const char* msg);
static const char* rosetta_error_msg = nullptr;
__attribute__((used, visibility("default"))) extern "C" void _mj_rosettaError(const char* msg) {
rosetta_error_msg = msg;
}
#endif
// run event loop
int main(int argc, const char** argv) {
// display an error if running on macOS under Rosetta 2
#if defined(__APPLE__) && defined(__AVX__)
if (rosetta_error_msg) {
DisplayErrorDialogBox("Rosetta 2 is not supported", rosetta_error_msg);
std::exit(1);
}
#endif
// print version, check compatibility
std::printf("MuJoCo version %s\n", mj_versionString());
if (mjVERSION_HEADER!=mj_version()) {