From ed82f055e8af76962b7a6f1fe21e073b7c0cc300 Mon Sep 17 00:00:00 2001 From: Levi Burner Date: Thu, 2 Jun 2022 17:11:24 -0400 Subject: [PATCH] Simulate: fixes for windows version --- simulate/CMakeLists.txt | 8 +++++++- simulate/simulate.cc | 6 ++++++ simulate/simulate.h | 15 ++++++++++++++- 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/simulate/CMakeLists.txt b/simulate/CMakeLists.txt index 6b7517e9..6442bb9b 100644 --- a/simulate/CMakeLists.txt +++ b/simulate/CMakeLists.txt @@ -82,6 +82,7 @@ target_link_options(uitools PRIVATE ${MUJOCO_SIMULATE_LINK_OPTIONS}) add_library(mjsimulate SHARED) target_sources(mjsimulate PUBLIC simulate.h array_safety.h simulate.cc) target_include_directories(mjsimulate PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) +target_compile_definitions(mjsimulate PUBLIC MJSIMULATE_DLL_EXPORTS) target_compile_options(mjsimulate PUBLIC ${MUJOCO_SIMULATE_COMPILE_OPTIONS}) target_link_libraries(mjsimulate PUBLIC glfw uitools mujoco::mujoco) # TODO is that right target_link_options(mjsimulate PRIVATE ${MUJOCO_SIMULATE_LINK_OPTIONS}) @@ -117,7 +118,12 @@ target_link_libraries( glfw Threads::Threads ) -target_link_options(simulate PRIVATE ${MUJOCO_SAMPLE_LINK_OPTIONS}) + +if(WIN32) + target_link_options(simulate PRIVATE ${MUJOCO_SIMULATE_LINK_OPTIONS} /STACK:8000000) +else() + target_link_options(simulate PRIVATE ${MUJOCO_SIMULATE_LINK_OPTIONS}) +endif() if(APPLE) target_sources(simulate PRIVATE macos_save.mm) diff --git a/simulate/simulate.cc b/simulate/simulate.cc index 1ad4d525..55815651 100644 --- a/simulate/simulate.cc +++ b/simulate/simulate.cc @@ -1901,6 +1901,12 @@ void Simulate::renderthread(void) { this->clearcallback(); mjv_freeScene(&this->scn); mjr_freeContext(&this->con); + + // terminate GLFW (crashes with Linux NVidia drivers) + // Must call terminate in this thread on Windows with NVidia drivers (Intel is fine) +#if defined(__APPLE__) || defined(_WIN32) + glfwTerminate(); +#endif } } // namespace mujoco diff --git a/simulate/simulate.h b/simulate/simulate.h index b02c77a9..461318c6 100644 --- a/simulate/simulate.h +++ b/simulate/simulate.h @@ -20,12 +20,25 @@ #include "uitools.h" +#ifdef MJSIMULATE_STATIC + // static library +#define MJSIMULATEAPI +#define MJSIMULATELOCAL +#else +#ifdef MJSIMULATE_DLL_EXPORTS +#define MJSIMULATEAPI MUJOCO_HELPER_DLL_EXPORT +#else +#define MJSIMULATEAPI MUJOCO_HELPER_DLL_IMPORT +#endif +#define MJSIMULATELOCAL MUJOCO_HELPER_DLL_LOCAL +#endif + namespace mujoco { //-------------------------------- global ----------------------------------------------- // Simulate states not contained in MuJoCo structures -class Simulate { +class MJSIMULATEAPI Simulate { public: // create object and initialize the simulate ui Simulate(void);