From 1f2e2c1d4539c688c2f1d7f606a6338a394fb09f Mon Sep 17 00:00:00 2001 From: Relintai Date: Wed, 16 Nov 2022 13:28:19 +0100 Subject: [PATCH] Fix crash in PaintCanvas. --- modules/paint/nodes/paint_canvas.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/modules/paint/nodes/paint_canvas.cpp b/modules/paint/nodes/paint_canvas.cpp index f27a7b709..533084946 100644 --- a/modules/paint/nodes/paint_canvas.cpp +++ b/modules/paint/nodes/paint_canvas.cpp @@ -143,8 +143,8 @@ void PaintCanvas::resize(int width, int height) { set_size(Vector2i(width, height)); - resize_image(_image_texture); - resize_image(_preview_image_texture); + resize_image(_image); + resize_image(_preview_image); update_textures(); } @@ -154,16 +154,16 @@ void PaintCanvas::resize_image(Ref image) { int prev_width = image->get_size().x; int prev_height = image->get_size().y; - image->lock(); - - for (int y = 0; y < prev_height; ++y) { - for (int x = 0; x < prev_width; ++x) { - pixel_colors.append(image->get_pixel(x, y)); + if (prev_width != 0 && prev_height != 0) { + image->lock(); + for (int y = 0; y < prev_height; ++y) { + for (int x = 0; x < prev_width; ++x) { + pixel_colors.append(image->get_pixel(x, y)); + } } + image->unlock(); } - image->unlock(); - image->create(get_size().x, get_size().y, false, Image::FORMAT_RGBA8); image->lock();