Skip to content

Commit

Permalink
Fix zero width textbox throwing
Browse files Browse the repository at this point in the history
Math.Clamp could fail if the usable text area was considered negative.
  • Loading branch information
Susko3 committed Jul 18, 2022
1 parent 7fea93e commit abf68a2
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions osu.Framework/Graphics/UserInterface/TextBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down

0 comments on commit abf68a2

Please sign in to comment.