Merge pull request #21386 from peppy/fix-editor-tap-timing-crash

Fix crash when hitting 'T' to tap timing while no timing point is selected
This commit is contained in:
Bartłomiej Dach 2022-11-23 18:40:13 +01:00 committed by GitHub
commit 224bf85e4a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 49 additions and 1 deletions

View File

@ -18,6 +18,7 @@ using osu.Game.Overlays;
using osu.Game.Screens.Edit;
using osu.Game.Screens.Edit.Timing;
using osuTK;
using osuTK.Input;
namespace osu.Game.Tests.Visual.Editing
{
@ -125,6 +126,41 @@ namespace osu.Game.Tests.Visual.Editing
AddUntilStep("wait for track stopped", () => !EditorClock.IsRunning);
}
[Test]
public void TestNoCrashesWhenNoGroupSelected()
{
AddStep("unset selected group", () => selectedGroup.Value = null);
AddStep("press T to tap", () => InputManager.Key(Key.T));
AddStep("click tap button", () =>
{
control.ChildrenOfType<OsuButton>()
.Last()
.TriggerClick();
});
AddStep("click reset button", () =>
{
control.ChildrenOfType<OsuButton>()
.First()
.TriggerClick();
});
AddStep("adjust offset", () =>
{
var adjustOffsetButton = control.ChildrenOfType<TimingAdjustButton>().First();
InputManager.MoveMouseTo(adjustOffsetButton);
InputManager.Click(MouseButton.Left);
});
AddStep("adjust BPM", () =>
{
var adjustBPMButton = control.ChildrenOfType<TimingAdjustButton>().Last();
InputManager.MoveMouseTo(adjustBPMButton);
InputManager.Click(MouseButton.Left);
});
}
protected override void Dispose(bool isDisposing)
{
Beatmap.Disabled = false;

View File

@ -295,6 +295,9 @@ namespace osu.Game.Screens.Edit.Timing
private void handleTap()
{
if (selectedGroup?.Value == null)
return;
tapTimings.Add(Clock.CurrentTime);
if (tapTimings.Count > initial_taps_to_ignore + max_taps_to_consider)

View File

@ -183,18 +183,27 @@ namespace osu.Game.Screens.Edit.Timing
private void start()
{
if (selectedGroup.Value == null)
return;
editorClock.Seek(selectedGroup.Value.Time);
editorClock.Start();
}
private void reset()
{
if (selectedGroup.Value == null)
return;
editorClock.Stop();
editorClock.Seek(selectedGroup.Value.Time);
}
private void adjustOffset(double adjust)
{
if (selectedGroup.Value == null)
return;
bool wasAtStart = editorClock.CurrentTimeAccurate == selectedGroup.Value.Time;
// VERY TEMPORARY
@ -216,7 +225,7 @@ namespace osu.Game.Screens.Edit.Timing
private void adjustBpm(double adjust)
{
var timing = selectedGroup.Value.ControlPoints.OfType<TimingControlPoint>().FirstOrDefault();
var timing = selectedGroup.Value?.ControlPoints.OfType<TimingControlPoint>().FirstOrDefault();
if (timing == null)
return;