diff --git a/panda/src/wgldisplay/wglGraphicsStateGuardian.cxx b/panda/src/wgldisplay/wglGraphicsStateGuardian.cxx index ed9b0e0b2c..dc32a1ddcd 100644 --- a/panda/src/wgldisplay/wglGraphicsStateGuardian.cxx +++ b/panda/src/wgldisplay/wglGraphicsStateGuardian.cxx @@ -16,6 +16,7 @@ #include "wglGraphicsBuffer.h" #include "wglGraphicsPipe.h" #include "string_utils.h" +#include 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);