From f715b566b199b82cb08cac7fa6eb15d2dbd66083 Mon Sep 17 00:00:00 2001 From: Michael Alexsander Date: Thu, 6 Aug 2020 06:13:45 -0300 Subject: [PATCH] Fix out-of-bounds error when color picking outside the image (#291) --- src/Autoload/DrawingAlgos.gd | 2 +- src/Tools/ColorPicker.gd | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Autoload/DrawingAlgos.gd b/src/Autoload/DrawingAlgos.gd index 551e39fd8..5e93cf95f 100644 --- a/src/Autoload/DrawingAlgos.gd +++ b/src/Autoload/DrawingAlgos.gd @@ -229,7 +229,7 @@ func scale_image(width : int, height : int, interpolation : int) -> void: # Different method for scale3x if interpolation == 5: var times : Vector2 = Vector2(ceil(width/(3.0*sprite.get_width())),ceil(height/(3.0*sprite.get_height()))) - for j in range(max(times.x,times.y)): + for _j in range(max(times.x,times.y)): sprite.copy_from(scale3X(sprite)) sprite.resize(width, height, 0) else: diff --git a/src/Tools/ColorPicker.gd b/src/Tools/ColorPicker.gd index 5b8b39675..36596e2be 100644 --- a/src/Tools/ColorPicker.gd +++ b/src/Tools/ColorPicker.gd @@ -37,8 +37,14 @@ func draw_end(_position : Vector2) -> void: func _pick_color(position : Vector2) -> void: + if position.x < 0 or position.y < 0: + return + var image := Image.new() image.copy_from(_get_draw_image()) + if position.x > image.get_width() - 1 or position.y > image.get_height() - 1: + return + image.lock() var color := image.get_pixelv(position) var button := BUTTON_LEFT if _color_slot == 0 else BUTTON_RIGHT