From af0d547c020c8035842f6d0954e4040689e5b09b Mon Sep 17 00:00:00 2001 From: volzhs Date: Mon, 16 Apr 2018 20:21:08 +0900 Subject: [PATCH 1/2] Fix index out of size error on Image Fix #18229 --- scene/2d/sprite.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/scene/2d/sprite.cpp b/scene/2d/sprite.cpp index ca1ac2cd7f..16e22036c5 100644 --- a/scene/2d/sprite.cpp +++ b/scene/2d/sprite.cpp @@ -332,6 +332,27 @@ bool Sprite::_edit_is_selected_on_click(const Point2 &p_point, double p_toleranc ERR_FAIL_COND_V(image.is_null(), false); + bool is_repeat = texture->get_flags() & Texture::FLAG_REPEAT; + bool is_mirrored_repeat = texture->get_flags() & Texture::FLAG_MIRRORED_REPEAT; + if (is_repeat) { + int mirror_x = 0; + int mirror_y = 0; + if (is_mirrored_repeat) { + mirror_x = (int)(q.x / texture->get_size().width); + mirror_y = (int)(q.y / texture->get_size().height); + } + q.x = Math::fmod(q.x, texture->get_size().width); + q.y = Math::fmod(q.y, texture->get_size().height); + if (mirror_x % 2 == 1) { + q.x = texture->get_size().width - q.x - 1; + } + if (mirror_y % 2 == 1) { + q.y = texture->get_size().height - q.y - 1; + } + } else { + q.x = MIN(q.x, texture->get_size().width - 1); + q.y = MIN(q.y, texture->get_size().height - 1); + } image->lock(); const Color c = image->get_pixel((int)q.x, (int)q.y); image->unlock(); From 3ecf8eef37db55e50b2fd70a376cd60787f54203 Mon Sep 17 00:00:00 2001 From: volzhs Date: Mon, 16 Apr 2018 21:53:54 +0900 Subject: [PATCH 2/2] Fix error spam with Sprite has compressed texture Fix #18177 --- scene/2d/sprite.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/scene/2d/sprite.cpp b/scene/2d/sprite.cpp index 16e22036c5..bc39368c88 100644 --- a/scene/2d/sprite.cpp +++ b/scene/2d/sprite.cpp @@ -331,6 +331,9 @@ bool Sprite::_edit_is_selected_on_click(const Point2 &p_point, double p_toleranc } ERR_FAIL_COND_V(image.is_null(), false); + if (image->is_compressed()) { + return dst_rect.has_point(p_point); + } bool is_repeat = texture->get_flags() & Texture::FLAG_REPEAT; bool is_mirrored_repeat = texture->get_flags() & Texture::FLAG_MIRRORED_REPEAT;