Fixed divide by zero if the application has run out of GDI handles and is trying to show an error dialog
authorSam Lantinga <slouken@libsdl.org>
Mon, 14 Sep 2015 11:15:25 -0700
changeset 9863 334d18fb5dd1
parent 9862 c3c3cdaf37f9
child 9864 2e197ad97280
Fixed divide by zero if the application has run out of GDI handles and is trying to show an error dialog
src/video/windows/SDL_windowsmessagebox.c
--- a/src/video/windows/SDL_windowsmessagebox.c	Sun Sep 13 11:29:45 2015 -0400
+++ b/src/video/windows/SDL_windowsmessagebox.c	Mon Sep 14 11:15:25 2015 -0700
@@ -297,9 +297,12 @@
 
         /* Font size - convert to logical font size for dialog parameter. */
         {
-            HDC ScreenDC = GetDC(0);
-            WordToPass = (WORD)(-72 * NCM.lfMessageFont.lfHeight / GetDeviceCaps(ScreenDC, LOGPIXELSY));
-            ReleaseDC(0, ScreenDC);
+            HDC ScreenDC = GetDC(NULL);
+            int LogicalPixelsY = GetDeviceCaps(ScreenDC, LOGPIXELSY);
+            if (!LogicalPixelsY) /* This can happen if the application runs out of GDI handles */
+                LogicalPixelsY = 72;
+            WordToPass = (WORD)(-72 * NCM.lfMessageFont.lfHeight / LogicalPixelsY);
+            ReleaseDC(NULL, ScreenDC);
         }
 
         if (!AddDialogData(dialog, &WordToPass, 2)) {