mirror of
https://github.com/ppy/osu.git
synced 2025-02-25 17:42:56 +08:00
Merge pull request #31644 from peppy/fix-beatmap-offset-crash
Fix potential crash when adjusting offset
This commit is contained in:
commit
2f84aec88d
@ -121,7 +121,11 @@ namespace osu.Game.Screens.Play.PlayerSettings
|
||||
// At the point we reach here, it's not guaranteed that all realm writes have taken place (there may be some in-flight).
|
||||
// We are only aware of writes that originated from our own flow, so if we do see one that's active we can avoid handling the feedback value arriving.
|
||||
if (realmWriteTask == null)
|
||||
{
|
||||
Current.Disabled = false;
|
||||
Current.Value = val;
|
||||
Current.Disabled = allowOffsetAdjust;
|
||||
}
|
||||
|
||||
if (realmWriteTask?.IsCompleted == true)
|
||||
{
|
||||
@ -134,15 +138,15 @@ namespace osu.Game.Screens.Play.PlayerSettings
|
||||
ReferenceScore.BindValueChanged(scoreChanged, true);
|
||||
}
|
||||
|
||||
// the last play graph is relative to the offset at the point of the last play, so we need to factor that out for some usages.
|
||||
private double adjustmentSinceLastPlay => lastPlayBeatmapOffset - Current.Value;
|
||||
|
||||
private void currentChanged(ValueChangedEvent<double> offset)
|
||||
{
|
||||
Scheduler.AddOnce(updateOffset);
|
||||
|
||||
void updateOffset()
|
||||
{
|
||||
// the last play graph is relative to the offset at the point of the last play, so we need to factor that out.
|
||||
double adjustmentSinceLastPlay = lastPlayBeatmapOffset - Current.Value;
|
||||
|
||||
// Negative is applied here because the play graph is considering a hit offset, not track (as we currently use for clocks).
|
||||
lastPlayGraph?.UpdateOffset(-adjustmentSinceLastPlay);
|
||||
|
||||
@ -153,11 +157,6 @@ namespace osu.Game.Screens.Play.PlayerSettings
|
||||
return;
|
||||
}
|
||||
|
||||
if (useAverageButton != null)
|
||||
{
|
||||
useAverageButton.Enabled.Value = !Precision.AlmostEquals(lastPlayAverage, adjustmentSinceLastPlay, Current.Precision / 2);
|
||||
}
|
||||
|
||||
realmWriteTask = realm.WriteAsync(r =>
|
||||
{
|
||||
var setInfo = r.Find<BeatmapSetInfo>(beatmap.Value.BeatmapSetInfo.ID);
|
||||
@ -245,10 +244,12 @@ namespace osu.Game.Screens.Play.PlayerSettings
|
||||
Text = BeatmapOffsetControlStrings.CalibrateUsingLastPlay,
|
||||
Action = () =>
|
||||
{
|
||||
if (Current.Disabled)
|
||||
return;
|
||||
|
||||
Current.Value = lastPlayBeatmapOffset - lastPlayAverage;
|
||||
lastAppliedScore.Value = ReferenceScore.Value;
|
||||
},
|
||||
Enabled = { Value = !Precision.AlmostEquals(lastPlayAverage, 0, Current.Precision / 2) }
|
||||
},
|
||||
globalOffsetText = new LinkFlowContainer
|
||||
{
|
||||
@ -277,7 +278,13 @@ namespace osu.Game.Screens.Play.PlayerSettings
|
||||
protected override void Update()
|
||||
{
|
||||
base.Update();
|
||||
Current.Disabled = !allowOffsetAdjust;
|
||||
|
||||
bool allow = allowOffsetAdjust;
|
||||
|
||||
if (useAverageButton != null)
|
||||
useAverageButton.Enabled.Value = allow && !Precision.AlmostEquals(lastPlayAverage, adjustmentSinceLastPlay, Current.Precision / 2);
|
||||
|
||||
Current.Disabled = !allow;
|
||||
}
|
||||
|
||||
private bool allowOffsetAdjust
|
||||
|
Loading…
Reference in New Issue
Block a user