From 764248bb0d846f65c20931024c1f4adca57aae29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sat, 29 Jul 2023 08:18:00 +0200 Subject: [PATCH] =?UTF-8?q?wayl=5Fsurface=5Fscale=5Fexplicit=5Fwidth=5Fhei?= =?UTF-8?q?ght():=20don=E2=80=99t=20assert=20width/height=20are=20valid=20?= =?UTF-8?q?for=20scale?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This function is only called directly when scaling the mouse pointer. The mouse pointer is never guaranteed to have a valid width and height, so skip the width/height assertions for it. --- wayland.c | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/wayland.c b/wayland.c index 66e06c10..c338bef8 100644 --- a/wayland.c +++ b/wayland.c @@ -2000,18 +2000,31 @@ wayl_roundtrip(struct wayland *wayl) wayl_flush(wayl); } -void -wayl_surface_scale_explicit_width_height( +static void +surface_scale_explicit_width_height( const struct wl_window *win, const struct wayl_surface *surf, - int width, int height, float scale) + int width, int height, float scale, bool verify) { if (term_fractional_scaling(win->term)) { #if defined(HAVE_FRACTIONAL_SCALE) LOG_DBG("scaling by a factor of %.2f using fractional scaling " "(width=%d, height=%d) ", scale, width, height); - xassert((int)roundf(scale * (int)roundf(width / scale)) == width); - xassert((int)roundf(scale * (int)roundf(height / scale)) == height); + if (verify) { + if ((int)roundf(scale * (int)roundf(width / scale)) != width) { + BUG("width=%d is not valid with scaling factor %.2f (%d != %d)", + width, scale, + (int)roundf(scale * (int)roundf(width / scale)), + width); + } + + if ((int)roundf(scale * (int)roundf(height / scale)) != height) { + BUG("height=%d is not valid with scaling factor %.2f (%d != %d)", + height, scale, + (int)roundf(scale * (int)roundf(height / scale)), + height); + } + } wl_surface_set_buffer_scale(surf->surf, 1); wp_viewport_set_destination( @@ -2034,12 +2047,20 @@ wayl_surface_scale_explicit_width_height( } } +void +wayl_surface_scale_explicit_width_height( + const struct wl_window *win, const struct wayl_surface *surf, + int width, int height, float scale) +{ + surface_scale_explicit_width_height(win, surf, width, height, scale, false); +} + void wayl_surface_scale(const struct wl_window *win, const struct wayl_surface *surf, const struct buffer *buf, float scale) { - wayl_surface_scale_explicit_width_height( - win, surf, buf->width, buf->height, scale); + surface_scale_explicit_width_height( + win, surf, buf->width, buf->height, scale, true); } void