diff options
| author | volzhs | 2018-04-16 20:21:08 +0900 |
|---|---|---|
| committer | Hein-Pieter van Braam | 2018-04-28 22:54:44 +0200 |
| commit | 5a947ebc42c43f1d6f006d930f5d4161f36a28c6 (patch) | |
| tree | bb626e5d73b494fed2d3838187dbaccd78d2a9df | |
| parent | 44f4c8e74589e9f6e626e7853b6e52b0ac5f5ba2 (diff) | |
| download | godot-5a947ebc42c43f1d6f006d930f5d4161f36a28c6.tar.gz godot-5a947ebc42c43f1d6f006d930f5d4161f36a28c6.tar.zst godot-5a947ebc42c43f1d6f006d930f5d4161f36a28c6.zip | |
Fix index out of size error on Image
Fix #18229
(cherry picked from commit af0d547c020c8035842f6d0954e4040689e5b09b)
| -rw-r--r-- | scene/2d/sprite.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/scene/2d/sprite.cpp b/scene/2d/sprite.cpp index 8cde509c9..7fbce16ae 100644 --- a/scene/2d/sprite.cpp +++ b/scene/2d/sprite.cpp @@ -308,6 +308,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(); |
