From e1289d4c870296b1bd75496964a9826e1ff979ee Mon Sep 17 00:00:00 2001 From: Diego Ballesteros Villamizar Date: Fri, 14 Aug 2020 19:57:39 +0200 Subject: [PATCH 1/2] Handle glfwGetPrimaryMonitor returning nullptr [glfwGetPrimaryMonitor](https://www.glfw.org/docs/3.3/group__monitor.html#ga721867d84c6d18d6790d64d2847ca0b1) may return NULL in non-error cases when no monitor is found. This started to happen recently with an update to the linux distribution, see internal b/162545223. Handling this case avoids a crash and instead assumes a pixel density. --- shell/platform/glfw/flutter_glfw.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/shell/platform/glfw/flutter_glfw.cc b/shell/platform/glfw/flutter_glfw.cc index 802a1d9a73126..ef8118da7f961 100644 --- a/shell/platform/glfw/flutter_glfw.cc +++ b/shell/platform/glfw/flutter_glfw.cc @@ -184,6 +184,9 @@ static FlutterDesktopMessage ConvertToDesktopMessage( // that a screen coordinate is one dp. static double GetScreenCoordinatesPerInch() { auto* primary_monitor = glfwGetPrimaryMonitor(); + if (primary_monitor == nullptr) { + return kDpPerInch; + } auto* primary_monitor_mode = glfwGetVideoMode(primary_monitor); int primary_monitor_width_mm; glfwGetMonitorPhysicalSize(primary_monitor, &primary_monitor_width_mm, From 5a2050936ed00eb0bd4a87af13e577a58c967ea0 Mon Sep 17 00:00:00 2001 From: Diego Ballesteros Villamizar Date: Fri, 14 Aug 2020 20:06:06 +0200 Subject: [PATCH 2/2] Fix formatting --- shell/platform/glfw/flutter_glfw.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shell/platform/glfw/flutter_glfw.cc b/shell/platform/glfw/flutter_glfw.cc index ef8118da7f961..6ed101449e9ca 100644 --- a/shell/platform/glfw/flutter_glfw.cc +++ b/shell/platform/glfw/flutter_glfw.cc @@ -185,7 +185,7 @@ static FlutterDesktopMessage ConvertToDesktopMessage( static double GetScreenCoordinatesPerInch() { auto* primary_monitor = glfwGetPrimaryMonitor(); if (primary_monitor == nullptr) { - return kDpPerInch; + return kDpPerInch; } auto* primary_monitor_mode = glfwGetVideoMode(primary_monitor); int primary_monitor_width_mm;