mirror of
https://github.com/ppy/osu.git
synced 2026-05-24 07:14:10 +08:00
Fix potential failure in ensureSourceClockSet()
`ensureSourceClockSet()` was intended to only run when the adjustable
source hasn't been set at all yet. As it turns out permitting it to run
unconditionally can break the state of the underlying interpolated
clock. This is caused by the following factors:
* While the decoupleable clock is running, its `CurrentTime` does not
come from either the source clock, or the internal stopwatch; it is
instead calculated using the base `InterpolatingFramedClock` logic.
* A source change of a decoupleable clock seeks the provided source
clock to the decoupleable's current time.
* When an interpolating clock is seeked (decoupleable clock is also
an interpolating one), its interpolation state
(`{Last,Current}InterpolatedTime`) are reset to 0.
* If the interpolating clock determines that its current time is too
far away from the source's time (which was set when the source is
changed), it will ignore the source and instead continue to use
its current time until the source clock has caught up.
Overall, the source change is not really necessary if a source is
already there. The only reason to ensure it was set was to make sure
the first seek of the gameplay clock wasn't performed in decoupled
mode. Therefore, add a guard to make sure the source is only set if
there isn't one already.
This commit is contained in:
@@ -116,13 +116,17 @@ namespace osu.Game.Screens.Play
|
||||
protected void ChangeSource(IClock sourceClock) => AdjustableSource.ChangeSource(SourceClock = sourceClock);
|
||||
|
||||
/// <summary>
|
||||
/// Ensures that the <see cref="AdjustableSource"/> is set to <see cref="SourceClock"/>.
|
||||
/// Ensures that the <see cref="AdjustableSource"/> is set to <see cref="SourceClock"/>, if it hasn't been given a source yet.
|
||||
/// This is usually done before a seek to avoid accidentally seeking only the adjustable source in decoupled mode,
|
||||
/// but not the actual source clock.
|
||||
/// That will pretty much only happen on the very first call of this method, as the source clock is passed in the constructor,
|
||||
/// but it is not yet set on the adjustable source there.
|
||||
/// </summary>
|
||||
private void ensureSourceClockSet() => ChangeSource(SourceClock);
|
||||
private void ensureSourceClockSet()
|
||||
{
|
||||
if (AdjustableSource.Source == null)
|
||||
ChangeSource(SourceClock);
|
||||
}
|
||||
|
||||
protected override void Update()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user