x11: deal with xrandr display size in millimeters being zero.
authorRyan C. Gordon <icculus@icculus.org>
Wed, 04 Jan 2017 09:33:47 -0500
changeset 1074695c57a177719
parent 10745 7461fcef6ae2
child 10747 da1f4eeac65a
x11: deal with xrandr display size in millimeters being zero.

Xquartz on macOS reports a zero size, which leads to a division by zero here.
src/video/SDL_video.c
src/video/x11/SDL_x11modes.c
     1.1 --- a/src/video/SDL_video.c	Tue Jan 03 23:39:28 2017 -0800
     1.2 +++ b/src/video/SDL_video.c	Wed Jan 04 09:33:47 2017 -0500
     1.3 @@ -3797,7 +3797,8 @@
     1.4      return 0;
     1.5  }
     1.6  
     1.7 -float SDL_ComputeDiagonalDPI(int hpix, int vpix, float hinches, float vinches)
     1.8 +float
     1.9 +SDL_ComputeDiagonalDPI(int hpix, int vpix, float hinches, float vinches)
    1.10  {
    1.11  	float den2 = hinches * hinches + vinches * vinches;
    1.12  	if (den2 <= 0.0f) {
     2.1 --- a/src/video/x11/SDL_x11modes.c	Tue Jan 03 23:39:28 2017 -0800
     2.2 +++ b/src/video/x11/SDL_x11modes.c	Wed Jan 04 09:33:47 2017 -0500
     2.3 @@ -464,8 +464,8 @@
     2.4                  displaydata->screen = screen;
     2.5                  displaydata->visual = vinfo.visual;
     2.6                  displaydata->depth = vinfo.depth;
     2.7 -                displaydata->hdpi = ((float) mode.w) * 25.4f / display_mm_width;
     2.8 -                displaydata->vdpi = ((float) mode.h) * 25.4f / display_mm_height;
     2.9 +                displaydata->hdpi = display_mm_width ? (((float) mode.w) * 25.4f / display_mm_width) : 0.0f;
    2.10 +                displaydata->vdpi = display_mm_height ? (((float) mode.h) * 25.4f / display_mm_height) : 0.0f;
    2.11                  displaydata->ddpi = SDL_ComputeDiagonalDPI(mode.w, mode.h, ((float) display_mm_width) / 25.4f,((float) display_mm_height) / 25.4f);
    2.12                  displaydata->scanline_pad = scanline_pad;
    2.13                  displaydata->x = display_x;