Skip to content

Commit

Permalink
Fixed divide by zero if the application has run out of GDI handles an…
Browse files Browse the repository at this point in the history
…d is trying to show an error dialog
  • Loading branch information
slouken committed Sep 14, 2015
1 parent 4295a6f commit 08ce12c
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/video/windows/SDL_windowsmessagebox.c
Expand Up @@ -297,9 +297,12 @@ static WIN_DialogData *CreateDialogData(int w, int h, const char *caption)

/* 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)) {
Expand Down

0 comments on commit 08ce12c

Please sign in to comment.