From 2c13b00bc1c64183b1c73202610c0ce4d0d77f6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A0=D1=83=D1=81=D0=BB=D0=B0=D0=BD=20=D0=98=D0=B6=D0=B1?= =?UTF-8?q?=D1=83=D0=BB=D0=B0=D1=82=D0=BE=D0=B2?= Date: Wed, 6 Jun 2018 19:15:32 +0000 Subject: [PATCH] GDK W32: ensure that monitor enumeration matches up In case something happens between monitor counting and monitor enumeration, repeat until the count matches up. enum_monitor is changed to ignore any monitors past _gdk_num_monitors and just keep increasing the count past that number. --- gdk/win32/gdkdisplay-win32.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/gdk/win32/gdkdisplay-win32.c b/gdk/win32/gdkdisplay-win32.c index cef60721a1..7447525f72 100644 --- a/gdk/win32/gdkdisplay-win32.c +++ b/gdk/win32/gdkdisplay-win32.c @@ -82,7 +82,12 @@ enum_monitor (HMONITOR hmonitor, gint *index = (gint *) data; GdkWin32Monitor *monitor; - g_assert (*index < _gdk_num_monitors); + if (*index >= _gdk_num_monitors) + { + (*index) += 1; + + return TRUE; + } monitor = _gdk_monitors + *index; @@ -126,14 +131,21 @@ _gdk_monitor_init (void) #ifdef HAVE_MONITOR_INFO gint i, index; - _gdk_num_monitors = 0; + /* In case something happens between monitor counting and monitor + * enumeration, repeat until the count matches up. + * enum_monitor is coded to ignore any monitors past _gdk_num_monitors. + */ + do + { + _gdk_num_monitors = 0; - EnumDisplayMonitors (NULL, NULL, count_monitor, (LPARAM) &_gdk_num_monitors); + EnumDisplayMonitors (NULL, NULL, count_monitor, (LPARAM) &_gdk_num_monitors); - _gdk_monitors = g_renew (GdkWin32Monitor, _gdk_monitors, _gdk_num_monitors); + _gdk_monitors = g_renew (GdkWin32Monitor, _gdk_monitors, _gdk_num_monitors); - index = 0; - EnumDisplayMonitors (NULL, NULL, enum_monitor, (LPARAM) &index); + index = 0; + EnumDisplayMonitors (NULL, NULL, enum_monitor, (LPARAM) &index); + } while (index != _gdk_num_monitors); _gdk_offset_x = G_MININT; _gdk_offset_y = G_MININT;