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.
This commit is contained in:
Diego Ballesteros Villamizar
2020-08-14 23:03:50 +02:00
committed by GitHub
parent 0a9e612fdd
commit 4ba82d4d91

View File

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