From abf68a2399d8895c26dd6ca7a82c54dd516fa0ba Mon Sep 17 00:00:00 2001 From: Susko3 Date: Mon, 18 Jul 2022 12:02:35 +0200 Subject: [PATCH] Fix zero width textbox throwing Math.Clamp could fail if the usable text area was considered negative. --- osu.Framework/Graphics/UserInterface/TextBox.cs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/osu.Framework/Graphics/UserInterface/TextBox.cs b/osu.Framework/Graphics/UserInterface/TextBox.cs index ad4142618a..6e2a9cfbe3 100644 --- a/osu.Framework/Graphics/UserInterface/TextBox.cs +++ b/osu.Framework/Graphics/UserInterface/TextBox.cs @@ -1570,8 +1570,17 @@ private void updateImeWindowPosition() float start = getPositionAt(startIndex) - textContainerPosX + LeftRightPadding; float end = getPositionAt(endIndex) - textContainerPosX + LeftRightPadding; - start = Math.Clamp(start, LeftRightPadding, DrawWidth - LeftRightPadding); - end = Math.Clamp(end, LeftRightPadding, DrawWidth - LeftRightPadding); + if (LeftRightPadding <= DrawWidth - LeftRightPadding) + { + start = Math.Clamp(start, LeftRightPadding, DrawWidth - LeftRightPadding); + end = Math.Clamp(end, LeftRightPadding, DrawWidth - LeftRightPadding); + } + else + { + // DrawWidth is probably zero/invalid, sane fallback instead of throwing in Math.Clamp + start = 0; + end = 0; + } var compositionTextRectangle = new RectangleF {