Skip to content

Commit

Permalink
x11: deal with xrandr display size in millimeters being zero.
Browse files Browse the repository at this point in the history
Xquartz on macOS reports a zero size, which leads to a division by zero here.
  • Loading branch information
icculus committed Jan 4, 2017
1 parent 082132a commit 9d04205
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/video/SDL_video.c
Expand Up @@ -3797,7 +3797,8 @@ SDL_SetWindowHitTest(SDL_Window * window, SDL_HitTest callback, void *userdata)
return 0;
}

float SDL_ComputeDiagonalDPI(int hpix, int vpix, float hinches, float vinches)
float
SDL_ComputeDiagonalDPI(int hpix, int vpix, float hinches, float vinches)
{
float den2 = hinches * hinches + vinches * vinches;
if (den2 <= 0.0f) {
Expand Down
4 changes: 2 additions & 2 deletions src/video/x11/SDL_x11modes.c
Expand Up @@ -464,8 +464,8 @@ X11_InitModes_XRandR(_THIS)
displaydata->screen = screen;
displaydata->visual = vinfo.visual;
displaydata->depth = vinfo.depth;
displaydata->hdpi = ((float) mode.w) * 25.4f / display_mm_width;
displaydata->vdpi = ((float) mode.h) * 25.4f / display_mm_height;
displaydata->hdpi = display_mm_width ? (((float) mode.w) * 25.4f / display_mm_width) : 0.0f;
displaydata->vdpi = display_mm_height ? (((float) mode.h) * 25.4f / display_mm_height) : 0.0f;
displaydata->ddpi = SDL_ComputeDiagonalDPI(mode.w, mode.h, ((float) display_mm_width) / 25.4f,((float) display_mm_height) / 25.4f);
displaydata->scanline_pad = scanline_pad;
displaydata->x = display_x;
Expand Down

0 comments on commit 9d04205

Please sign in to comment.