From 255cd9a9fff5d928eb63eb3464b5d4c27a2a74e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20=C3=85dahl?= Date: Sat, 3 Sep 2022 15:01:40 +0200 Subject: [PATCH] color-device: Don't attempt to set GAMMA_LUT if LUT size is zero This might happen on e.g. virtual machines. If we don't skip trying, we'll end up crashing because we'll fail to create a look up table since the size must be greater than zero to make any sense. Fixes: baef39e603f232f5ce3c2ce79c443383cd6a1f67 Closes: https://gitlab.gnome.org/GNOME/mutter/-/issues/2415 Part-of: --- src/backends/meta-color-device.c | 14 +++++++++----- src/backends/meta-color-profile.c | 2 +- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/backends/meta-color-device.c b/src/backends/meta-color-device.c index 272fade57..e6854fc3a 100644 --- a/src/backends/meta-color-device.c +++ b/src/backends/meta-color-device.c @@ -1171,7 +1171,6 @@ meta_color_device_update (MetaColorDevice *color_device, MetaColorProfile *color_profile; MetaMonitor *monitor; size_t lut_size; - g_autoptr (MetaGammaLut) lut = NULL; color_profile = meta_color_device_get_assigned_profile (color_device); if (!color_profile) @@ -1206,11 +1205,16 @@ meta_color_device_update (MetaColorDevice *color_device, } lut_size = meta_monitor_get_gamma_lut_size (monitor); - lut = meta_color_profile_generate_gamma_lut (color_profile, - temperature, - lut_size); + if (lut_size > 0) + { + g_autoptr (MetaGammaLut) lut = NULL; - meta_monitor_set_gamma_lut (monitor, lut); + lut = meta_color_profile_generate_gamma_lut (color_profile, + temperature, + lut_size); + + meta_monitor_set_gamma_lut (monitor, lut); + } g_signal_emit (color_device, signals[UPDATED], 0); } diff --git a/src/backends/meta-color-profile.c b/src/backends/meta-color-profile.c index 573acadb8..82c235b0f 100644 --- a/src/backends/meta-color-profile.c +++ b/src/backends/meta-color-profile.c @@ -488,7 +488,7 @@ meta_color_profile_generate_gamma_lut (MetaColorProfile *color_profile, unsigned int temperature, size_t lut_size) { - g_return_val_if_fail (lut_size > 0, NULL); + g_assert (lut_size > 0); if (color_profile->calibration->has_vcgt) {