Skip to content

Dragging (selecting) with the mouse while holding down a key in a text box can crash the game #29041

Closed
ppy/osu-framework
#6485
@Gabixel

Description

@Gabixel

Type

Crash to desktop

Bug description

The video should easily describe the issue.
It's not a common thing to do, but it's possible to replace a string in a text box while holding down a letter and dragging with the mouse cursor. This seems to cause a crash in some cases. Not sure of the correct scenario to reproduce this 100%, but it seems easy to do (see the video).

I just tried it in the settings and in the collections dropdown (in the carousel) for now. The video shows the former.

Screenshots or videos

2024-07-24.20-05-50.-.Trim.mp4

Version

2024.718.1

Logs

1721844249.runtime.log

Relevant portion:

2024-07-24 18:16:55 [error]: An unhandled error has occurred.
2024-07-24 18:16:55 [error]: System.ArgumentOutOfRangeException: Index and length must refer to a location within the string. (Parameter 'length')
2024-07-24 18:16:55 [error]: at System.String.ThrowSubstringArgumentOutOfRange(Int32 startIndex, Int32 length)
2024-07-24 18:16:55 [error]: at System.String.Substring(Int32 startIndex, Int32 length)
2024-07-24 18:16:55 [error]: at osu.Framework.Graphics.UserInterface.TextBox.get_SelectedText()
2024-07-24 18:16:55 [error]: at osu.Game.Graphics.UserInterface.OsuTextBox.<>c__DisplayClass35_0.<PlayFeedbackSample>b__0()
2024-07-24 18:16:55 [error]: at osu.Framework.Threading.ScheduledDelegate.RunTaskInternal()
2024-07-24 18:16:55 [error]: at osu.Framework.Threading.Scheduler.Update()
2024-07-24 18:16:55 [error]: at osu.Framework.Graphics.Drawable.UpdateSubTree()
2024-07-24 18:16:55 [error]: at osu.Framework.Graphics.Containers.CompositeDrawable.UpdateSubTree()

Activity

Gabixel

Gabixel commented on Jul 24, 2024

@Gabixel
ContributorAuthor

I forgot to point out that I have a custom ruleset, as you can see from the video. I just tried without it - just in case - and the problem persists.

added
priority:1Very important. Feels bad without fix. Affects the majority of users.
and removed on Sep 5, 2024
424ever

424ever commented on Jan 4, 2025

@424ever
Contributor

Here's a test case for the crash. Note that InputManager.PressKey() did not work for me, so a key needs to be held down while running the test.

diff --git a/osu.Game.Tests/Visual/UserInterface/TestSceneOsuTextBox.cs b/osu.Game.Tests/Visual/UserInterface/TestSceneOsuTextBox.cs
index abad7e775c..8d76d671f3 100644
--- a/osu.Game.Tests/Visual/UserInterface/TestSceneOsuTextBox.cs
+++ b/osu.Game.Tests/Visual/UserInterface/TestSceneOsuTextBox.cs
@@ -96,6 +96,31 @@ public void TestSelectAllOnFocus()
             AddAssert("half text selected", () => numberBoxes.First().SelectedText == "54321");
         }
 
+        [Test]
+        public void TestSelectionCrash()
+        {
+            AddStep("create themed content", () => CreateThemedContent(OverlayColourScheme.Red));
+
+            OsuTextBox textBox = null!;
+
+            AddStep("click on normal box", () =>
+            {
+                textBox = this.ChildrenOfType<OsuTextBox>().First();
+                InputManager.MoveMouseTo(textBox);
+                InputManager.Click(MouseButton.Left);
+            });
+
+            AddStep("set text", () =>
+            {
+                textBox.Text = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
+            });
+
+            AddStep("1", () => InputManager.Click(MouseButton.Left));
+            AddStep("2", () => InputManager.PressButton(MouseButton.Left));
+            AddStep("3", () => InputManager.MoveMouseTo(textBox.ScreenSpaceDrawQuad.Centre - new Vector2(200, 0)));
+            AddStep("4", () => InputManager.ReleaseButton(MouseButton.Left));
+        }
+
         private void clearTextboxes(IEnumerable<OsuTextBox> textBoxes) => AddStep("clear textbox", () => textBoxes.ForEach(textBox => textBox.Text = null));
         private void expectedValue(IEnumerable<OsuTextBox> textBoxes, string value) => AddAssert("expected textbox value", () => textBoxes.All(textBox => textBox.Text == value));
     }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    osu!framework issueCan't resolve this without changes to osu!framework.priority:1Very important. Feels bad without fix. Affects the majority of users.type:reliability

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Dragging (selecting) with the mouse while holding down a key in a text box can crash the game · Issue #29041 · ppy/osu