From c8c5b55f82ff341a8eba3dc13e7eb16eed447efe Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Tue, 7 May 2024 00:28:11 +0400 Subject: [PATCH] Fix drawing color picker crash --- submodules/DrawingUI/Sources/ColorPickerScreen.swift | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/submodules/DrawingUI/Sources/ColorPickerScreen.swift b/submodules/DrawingUI/Sources/ColorPickerScreen.swift index 5745ca248b..6b79a8f536 100644 --- a/submodules/DrawingUI/Sources/ColorPickerScreen.swift +++ b/submodules/DrawingUI/Sources/ColorPickerScreen.swift @@ -591,11 +591,15 @@ final class ColorGridComponent: Component { else { return nil } - let row = Int(point.y / size.height * 10.0) - let col = Int(point.x / size.width * 12.0) + let row = max(0, min(10, Int(point.y / size.height * 10.0))) + let col = max(0, min(12, Int(point.x / size.width * 12.0))) let index = row * 12 + col - return DrawingColor(rgb: palleteColors[index]) + if index < palleteColors.count { + return DrawingColor(rgb: palleteColors[index]) + } else { + return DrawingColor(rgb: 0x000000) + } } @objc func handlePress(_ gestureRecognizer: UILongPressGestureRecognizer) {