Browse Source

wgldisplay: don't restore gamma atexit if we never modified it

This avoids possible instability (see #685) when this feature isn't even used
rdb 6 years ago
parent
commit
f989bce584
1 changed files with 7 additions and 1 deletions
  1. 7 1
      panda/src/wgldisplay/wglGraphicsStateGuardian.cxx

+ 7 - 1
panda/src/wgldisplay/wglGraphicsStateGuardian.cxx

@@ -16,6 +16,7 @@
 #include "wglGraphicsBuffer.h"
 #include "wglGraphicsPipe.h"
 #include "string_utils.h"
+#include <atomic>
 
 TypeHandle wglGraphicsStateGuardian::_type_handle;
 
@@ -49,7 +50,6 @@ wglGraphicsStateGuardian(GraphicsEngine *engine, GraphicsPipe *pipe,
   _wglCreateContextAttribsARB = nullptr;
 
   get_gamma_table();
-  atexit(atexit_function);
 }
 
 /**
@@ -886,6 +886,12 @@ static_set_gamma(bool restore, PN_stdfloat gamma) {
 
     if (SetDeviceGammaRamp (hdc, ramp)) {
       set = true;
+
+      // Register an atexit handler
+      static std::atomic_flag gamma_modified = ATOMIC_FLAG_INIT;
+      if (!gamma_modified.test_and_set()) {
+        atexit(atexit_function);
+      }
     }
 
     ReleaseDC (nullptr, hdc);