Pārlūkot izejas kodu

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.
Ryan C. Gordon 8 gadi atpakaļ
vecāks
revīzija
9d04205263
2 mainītis faili ar 4 papildinājumiem un 3 dzēšanām
  1. 2 1
      src/video/SDL_video.c
  2. 2 2
      src/video/x11/SDL_x11modes.c

+ 2 - 1
src/video/SDL_video.c

@@ -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) {

+ 2 - 2
src/video/x11/SDL_x11modes.c

@@ -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;