From 5a25641317dd570757f33181e45393a74019dc30 Mon Sep 17 00:00:00 2001 From: Matthias Melcher Date: Sat, 11 Feb 2023 19:14:23 +0100 Subject: Very controlled GDIplus startup and shutdown #635 (#679) Fall back to GDI if GDIplus is not available --- src/drivers/GDI/Fl_GDI_Graphics_Driver.H | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'src/drivers/GDI/Fl_GDI_Graphics_Driver.H') diff --git a/src/drivers/GDI/Fl_GDI_Graphics_Driver.H b/src/drivers/GDI/Fl_GDI_Graphics_Driver.H index 6fa6840c8..941ac4db1 100644 --- a/src/drivers/GDI/Fl_GDI_Graphics_Driver.H +++ b/src/drivers/GDI/Fl_GDI_Graphics_Driver.H @@ -182,7 +182,16 @@ private: Gdiplus::Color gdiplus_color_; Gdiplus::Pen *pen_; Gdiplus::SolidBrush *brush_; - static ULONG_PTR gdiplusToken; + // The code below ensures the a connection to GDIplus is only made once, and that the + // matching connection shutdown is also done exactly once. + enum { + STATE_CLOSED = 0, // no connection, token is invalid + STATE_STARTUP, // attempt to start up, avoid recursions for whatever reason + STATE_OPEN, // connection was successful and the token is valid + STATE_SHUTDOWN // shutting down the gdi connection, avoid possible recursion + }; + static int gdiplus_state_; // reflect the state of the GDIplus driver connection + static ULONG_PTR gdiplus_token_; // the token that GDIplus gives to us public: Fl_GDIplus_Graphics_Driver(); virtual ~Fl_GDIplus_Graphics_Driver(); -- cgit v1.2.3