From 15929e83fd54a88838a166a69b3f47b858fabed9 Mon Sep 17 00:00:00 2001 From: Alx Sa Date: Sat, 13 Jan 2024 13:15:56 +0000 Subject: [PATCH] core: Fix crash when pattern can't be loaded For certain small selections, the pattern preview can't be loaded. Since e1e30c6f assumes the pattern loads, this could cause a crash if a dialogue with the preview is visible. This patch checks if the scaled pattern was loaded before using it, and otherwise uses the default pattern. --- app/core/gimppattern.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/app/core/gimppattern.c b/app/core/gimppattern.c index f54c093a65..c8623ea34a 100644 --- a/app/core/gimppattern.c +++ b/app/core/gimppattern.c @@ -143,13 +143,14 @@ gimp_pattern_get_new_preview (GimpViewable *viewable, gint width, gint height) { - GimpPattern *pattern = GIMP_PATTERN (viewable); + GimpPattern *pattern = GIMP_PATTERN (viewable); GimpTempBuf *temp_buf; GeglBuffer *src_buffer; gint true_width; gint true_height; gint copy_width; gint copy_height; + gboolean has_temp_buf = FALSE; true_width = gimp_temp_buf_get_width (pattern->mask); true_height = gimp_temp_buf_get_height (pattern->mask); @@ -174,13 +175,21 @@ gimp_pattern_get_new_preview (GimpViewable *viewable, temp_buf = gimp_temp_buf_new (copy_width, copy_height, gimp_temp_buf_get_format (pattern->mask)); - gegl_buffer_get (src_buffer, - GEGL_RECTANGLE (0, 0, copy_width, copy_height), - scale, gimp_temp_buf_get_format (temp_buf), - gimp_temp_buf_get_data (temp_buf), - GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_CLAMP); + if (temp_buf) + { + gegl_buffer_get (src_buffer, + GEGL_RECTANGLE (0, 0, copy_width, copy_height), + scale, gimp_temp_buf_get_format (temp_buf), + gimp_temp_buf_get_data (temp_buf), + GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_CLAMP); + + has_temp_buf = TRUE; + } } - else + + /* If scaled image pattern could not be loaded, + * use the default pattern */ + if (! has_temp_buf) { GeglBuffer *dest_buffer;