From 7839c1c42a753b6eff57812fa5e97000d5b62016 Mon Sep 17 00:00:00 2001 From: Yuval Tassa Date: Wed, 31 Aug 2022 07:58:53 -0700 Subject: [PATCH] Annotate simulate/glfw_dispatch.cc PiperOrigin-RevId: 471256296 Change-Id: I63594a478fc65bf27d8f04f6bb25352a719c5ccc --- simulate/glfw_dispatch.cc | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/simulate/glfw_dispatch.cc b/simulate/glfw_dispatch.cc index bbbd15df..2d6e7bcd 100644 --- a/simulate/glfw_dispatch.cc +++ b/simulate/glfw_dispatch.cc @@ -27,9 +27,14 @@ #include namespace mujoco { + +// return dispatch table for glfw functions const struct Glfw& Glfw(void* dlhandle) { { + // set static init_dlhandle static const void* init_dlhandle = dlhandle; + + // check that not already initialized if (dlhandle && dlhandle != init_dlhandle) { std::cerr << "dlhandle is specified when GLFW dispatch table is already " "initialized\n"; @@ -37,9 +42,12 @@ const struct Glfw& Glfw(void* dlhandle) { } } - static const struct Glfw glfw = [&]() { + // make and intialize dispatch table + static const struct Glfw glfw = [&]() { // create and call constructor + // allocate struct Glfw glfw; + // load glfw dynamically #ifdef mjGLFW_DYNAMIC_SYMBOLS #ifdef _MSC_VER if (!dlhandle) dlhandle = LoadLibraryA("glfw3.dll"); @@ -63,11 +71,12 @@ const struct Glfw& Glfw(void* dlhandle) { #define mjGLFW_RESOLVE_SYMBOL(func) glfw.func = &::func #endif + // set pointers in dispatch table #define mjGLFW_INITIALIZE_SYMBOL(func) \ - if (!(mjGLFW_RESOLVE_SYMBOL(func))) { \ - std::cerr << "cannot dlsym " #func "\n"; \ - abort(); \ - } + if (!(mjGLFW_RESOLVE_SYMBOL(func))) { \ + std::cerr << "cannot dlsym " #func "\n"; \ + abort(); \ + } // go/keep-sorted start mjGLFW_INITIALIZE_SYMBOL(glfwCreateWindow);