summaryrefslogtreecommitdiff
path: root/src/drivers/GDI
diff options
context:
space:
mode:
Diffstat (limited to 'src/drivers/GDI')
-rw-r--r--src/drivers/GDI/Fl_GDI_Graphics_Driver.H11
-rw-r--r--src/drivers/GDI/Fl_GDI_Graphics_Driver.cxx16
2 files changed, 24 insertions, 3 deletions
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();
diff --git a/src/drivers/GDI/Fl_GDI_Graphics_Driver.cxx b/src/drivers/GDI/Fl_GDI_Graphics_Driver.cxx
index 188bd1d2d..7897dce53 100644
--- a/src/drivers/GDI/Fl_GDI_Graphics_Driver.cxx
+++ b/src/drivers/GDI/Fl_GDI_Graphics_Driver.cxx
@@ -53,10 +53,22 @@ int Fl_GDIplus_Graphics_Driver::antialias() {
#if USE_GDIPLUS
-ULONG_PTR Fl_GDIplus_Graphics_Driver::gdiplusToken = 0;
+int Fl_GDIplus_Graphics_Driver::gdiplus_state_ = Fl_GDIplus_Graphics_Driver::STATE_CLOSED;
+ULONG_PTR Fl_GDIplus_Graphics_Driver::gdiplus_token_ = 0;
void Fl_GDIplus_Graphics_Driver::shutdown() {
- Gdiplus::GdiplusShutdown(Fl_GDIplus_Graphics_Driver::gdiplusToken);
+ if (gdiplus_state_ == STATE_OPEN) {
+ gdiplus_state_ = STATE_SHUTDOWN;
+ Gdiplus::GdiplusShutdown(Fl_GDIplus_Graphics_Driver::gdiplus_token_);
+ gdiplus_token_ = 0;
+ gdiplus_state_ = STATE_CLOSED;
+ } else if (gdiplus_state_ == STATE_CLOSED) {
+// Fl::warning("Fl_GDIplus_Graphics_Driver::shutdown() called, but driver is closed.");
+ } else if (gdiplus_state_ == STATE_SHUTDOWN) {
+// Fl::warning("Fl_GDIplus_Graphics_Driver::shutdown() called recursively.");
+ } else if (gdiplus_state_ == STATE_STARTUP) {
+// Fl::warning("Fl_GDIplus_Graphics_Driver::shutdown() called while driver is starting up.");
+ }
}
#endif