From edd5d1cc0912ce4f8d29eaef96ebf5a79b9a7b67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Molinari?= Date: Thu, 22 Jun 2023 19:09:31 +0200 Subject: [PATCH] gl-renderer: Make clip_transformed() surf parameter constant MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Calling clip_transformed() 4 times in a row with the same polygon8 in commit a4d31fa8bdc00b04359e42f63e93c134cdf0384f introduced a bug because the surf input is modified each time. This is fixed by working on a local copy. The input parameter is marked constant to reflect the change on the function prototype. Fixes #764 Signed-off-by: Loïc Molinari --- libweston/vertex-clipping.c | 26 +++++++++++++------------- libweston/vertex-clipping.h | 2 +- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/libweston/vertex-clipping.c b/libweston/vertex-clipping.c index 8896527a..d37aed6c 100644 --- a/libweston/vertex-clipping.c +++ b/libweston/vertex-clipping.c @@ -294,29 +294,29 @@ clip_simple(struct clip_context *ctx, WESTON_EXPORT_FOR_TESTS int clip_transformed(struct clip_context *ctx, - struct polygon8 *surf, + const struct polygon8 *surf, struct clip_vertex *restrict vertices) { - struct polygon8 polygon; + struct polygon8 p = *surf, tmp; int i, n; - polygon.n = clip_polygon_left(ctx, surf, polygon.pos); - surf->n = clip_polygon_right(ctx, &polygon, surf->pos); - polygon.n = clip_polygon_top(ctx, surf, polygon.pos); - surf->n = clip_polygon_bottom(ctx, &polygon, surf->pos); + tmp.n = clip_polygon_left(ctx, &p, tmp.pos); + p.n = clip_polygon_right(ctx, &tmp, p.pos); + tmp.n = clip_polygon_top(ctx, &p, tmp.pos); + p.n = clip_polygon_bottom(ctx, &tmp, p.pos); /* Get rid of duplicate vertices */ - vertices[0] = surf->pos[0]; + vertices[0] = p.pos[0]; n = 1; - for (i = 1; i < surf->n; i++) { - if (float_difference(vertices[n - 1].x, surf->pos[i].x) == 0.0f && - float_difference(vertices[n - 1].y, surf->pos[i].y) == 0.0f) + for (i = 1; i < p.n; i++) { + if (float_difference(vertices[n - 1].x, p.pos[i].x) == 0.0f && + float_difference(vertices[n - 1].y, p.pos[i].y) == 0.0f) continue; - vertices[n] = surf->pos[i]; + vertices[n] = p.pos[i]; n++; } - if (float_difference(vertices[n - 1].x, surf->pos[0].x) == 0.0f && - float_difference(vertices[n - 1].y, surf->pos[0].y) == 0.0f) + if (float_difference(vertices[n - 1].x, p.pos[0].x) == 0.0f && + float_difference(vertices[n - 1].y, p.pos[0].y) == 0.0f) n--; return n; diff --git a/libweston/vertex-clipping.h b/libweston/vertex-clipping.h index 1b0fdc42..07231703 100644 --- a/libweston/vertex-clipping.h +++ b/libweston/vertex-clipping.h @@ -64,7 +64,7 @@ clip_simple(struct clip_context *ctx, int clip_transformed(struct clip_context *ctx, - struct polygon8 *surf, + const struct polygon8 *surf, struct clip_vertex *restrict vertices); /*