1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 08:43:01 +08:00

Merge pull request #15480 from frenzibyte/fix-more-null

Fix more occurring "possible null reference exception" inspections
This commit is contained in:
Dean Herbert 2021-11-07 17:59:07 +09:00 committed by GitHub
commit ae54e79b4c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 77 additions and 36 deletions

View File

@ -105,6 +105,9 @@ namespace osu.Game.Tests.Mods
testMod.ResetSettingsToDefaults();
Assert.That(testMod.DrainRate.Value, Is.Null);
// ReSharper disable once HeuristicUnreachableCode
// see https://youtrack.jetbrains.com/issue/RIDER-70159.
Assert.That(testMod.OverallDifficulty.Value, Is.Null);
var applied = applyDifficulty(new BeatmapDifficulty

View File

@ -79,8 +79,17 @@ namespace osu.Game.Tests.NonVisual
public List<HitObject> HitObjects;
public override IEnumerable<HitObject> Objects => HitObjects;
public override event Action<JudgementResult> NewResult;
public override event Action<JudgementResult> RevertResult;
public override event Action<JudgementResult> NewResult
{
add => throw new InvalidOperationException();
remove => throw new InvalidOperationException();
}
public override event Action<JudgementResult> RevertResult
{
add => throw new InvalidOperationException();
remove => throw new InvalidOperationException();
}
public override Playfield Playfield { get; }
public override Container Overlays { get; }
@ -95,9 +104,6 @@ namespace osu.Game.Tests.NonVisual
public TestDrawableRuleset()
: base(new OsuRuleset())
{
// won't compile without this.
NewResult?.Invoke(null);
RevertResult?.Invoke(null);
}
public override void SetReplayScore(Score replayScore) => throw new NotImplementedException();

View File

@ -235,8 +235,17 @@ namespace osu.Game.Tests.Visual.Gameplay
public override IEnumerable<HitObject> Objects => new[] { new HitCircle { HitWindows = HitWindows } };
public override event Action<JudgementResult> NewResult;
public override event Action<JudgementResult> RevertResult;
public override event Action<JudgementResult> NewResult
{
add => throw new InvalidOperationException();
remove => throw new InvalidOperationException();
}
public override event Action<JudgementResult> RevertResult
{
add => throw new InvalidOperationException();
remove => throw new InvalidOperationException();
}
public override Playfield Playfield { get; }
public override Container Overlays { get; }
@ -251,9 +260,6 @@ namespace osu.Game.Tests.Visual.Gameplay
public TestDrawableRuleset()
: base(new OsuRuleset())
{
// won't compile without this.
NewResult?.Invoke(null);
RevertResult?.Invoke(null);
}
public override void SetReplayScore(Score replayScore) => throw new NotImplementedException();

View File

@ -1,7 +1,9 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Input.Events;
using osu.Game.Graphics.Containers;
using osuTK;
@ -22,15 +24,9 @@ namespace osu.Game.Graphics.UserInterface
Enabled.Value = !isLoading;
if (value)
{
loading.Show();
OnLoadStarted();
}
else
{
loading.Hide();
OnLoadFinished();
}
}
}
@ -44,18 +40,34 @@ namespace osu.Game.Graphics.UserInterface
protected LoadingButton()
{
AddRange(new[]
Add(loading = new LoadingSpinner
{
CreateContent(),
loading = new LoadingSpinner
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Size = new Vector2(12)
}
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Size = new Vector2(12),
Depth = -1,
});
}
[BackgroundDependencyLoader]
private void load()
{
Add(CreateContent());
}
protected override void LoadComplete()
{
base.LoadComplete();
loading.State.BindValueChanged(s =>
{
if (s.NewValue == Visibility.Visible)
OnLoadStarted();
else
OnLoadFinished();
}, true);
}
protected override bool OnClick(ClickEvent e)
{
if (!Enabled.Value)

View File

@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using JetBrains.Annotations;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
@ -22,6 +23,11 @@ namespace osu.Game.Overlays.BeatmapListing
public BeatmapSearchMultipleSelectionFilterRow(LocalisableString header)
: base(header)
{
}
[BackgroundDependencyLoader]
private void load()
{
Current.BindTo(filter.Current);
}
@ -31,6 +37,7 @@ namespace osu.Game.Overlays.BeatmapListing
/// <summary>
/// Creates a filter control that can be used to simultaneously select multiple values of type <typeparamref name="T"/>.
/// </summary>
[NotNull]
protected virtual MultipleSelectionFilter CreateMultipleSelectionFilter() => new MultipleSelectionFilter();
protected class MultipleSelectionFilter : FillFlowContainer<MultipleSelectionFilterTabItem>

View File

@ -26,6 +26,8 @@ namespace osu.Game.Overlays.Changelog
public static LocalisableString ListingString => LayoutStrings.HeaderChangelogIndex;
private readonly Bindable<APIUpdateStream> currentStream = new Bindable<APIUpdateStream>();
private Box streamsBackground;
public ChangelogHeader()
@ -39,7 +41,7 @@ namespace osu.Game.Overlays.Changelog
Build.ValueChanged += showBuild;
Streams.Current.ValueChanged += e =>
currentStream.ValueChanged += e =>
{
if (e.NewValue?.LatestBuild != null && !e.NewValue.Equals(Build.Value?.UpdateStream))
Build.Value = e.NewValue.LatestBuild;
@ -67,7 +69,7 @@ namespace osu.Game.Overlays.Changelog
else
{
Current.Value = ListingString;
Streams.Current.Value = null;
currentStream.Value = null;
}
}
@ -92,7 +94,7 @@ namespace osu.Game.Overlays.Changelog
Horizontal = 65,
Vertical = 20
},
Child = Streams = new ChangelogUpdateStreamControl()
Child = Streams = new ChangelogUpdateStreamControl { Current = currentStream },
}
}
};
@ -110,7 +112,7 @@ namespace osu.Game.Overlays.Changelog
if (Build.Value == null)
return;
Streams.Current.Value = Streams.Items.FirstOrDefault(s => s.Name == Build.Value.UpdateStream.Name);
currentStream.Value = Streams.Items.FirstOrDefault(s => s.Name == Build.Value.UpdateStream.Name);
}
private class ChangelogHeaderTitle : OverlayTitle

View File

@ -175,6 +175,8 @@ namespace osu.Game.Overlays.Comments
protected override IEnumerable<Drawable> EffectTargets => new[] { background };
private readonly string text;
[Resolved]
private OverlayColourProvider colourProvider { get; set; }
@ -184,10 +186,10 @@ namespace osu.Game.Overlays.Comments
public CommitButton(string text)
{
this.text = text;
AutoSizeAxes = Axes.Both;
LoadingAnimationSize = new Vector2(10);
drawableText.Text = text;
}
[BackgroundDependencyLoader]
@ -232,7 +234,8 @@ namespace osu.Game.Overlays.Comments
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Font = OsuFont.GetFont(size: 12, weight: FontWeight.Bold),
Margin = new MarginPadding { Horizontal = 20 }
Margin = new MarginPadding { Horizontal = 20 },
Text = text,
}
}
};

View File

@ -37,11 +37,7 @@ namespace osu.Game.Overlays
Anchor = Anchor.BottomRight,
Origin = Anchor.BottomRight,
Margin = new MarginPadding(20),
Action = () =>
{
ScrollToStart();
Button.State = Visibility.Hidden;
}
Action = scrollToTop
});
}
@ -58,6 +54,12 @@ namespace osu.Game.Overlays
Button.State = Target > button_scroll_position ? Visibility.Visible : Visibility.Hidden;
}
private void scrollToTop()
{
ScrollToStart();
Button.State = Visibility.Hidden;
}
public class ScrollToTopButton : OsuHoverContainer
{
private const int fade_duration = 500;