From 4ba82d4d91e254bbbe30379ef2275a9e14f28ad9 Mon Sep 17 00:00:00 2001 From: Diego Ballesteros Villamizar Date: Fri, 14 Aug 2020 23:03:50 +0200 Subject: [PATCH] Handle glfwGetPrimaryMonitor returning nullptr (flutter/engine#20523) * 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. --- engine/src/flutter/shell/platform/glfw/flutter_glfw.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/engine/src/flutter/shell/platform/glfw/flutter_glfw.cc b/engine/src/flutter/shell/platform/glfw/flutter_glfw.cc index 802a1d9a73..6ed101449e 100644 --- a/engine/src/flutter/shell/platform/glfw/flutter_glfw.cc +++ b/engine/src/flutter/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,