Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add two new update methods for AudioComponents to use #1120

Merged
merged 4 commits into from
Oct 27, 2017

Conversation

peppy
Copy link
Sponsor Member

@peppy peppy commented Oct 25, 2017

This allows state updates to be performed a second time post queued actions. Until now, if a queued action was to change a state which only got revalidated in a component's Update, it would be stale for a single frame.

This caused all end of race conditions, such as ppy/osu#1369

@peppy peppy added this to the 2017.1025.0 milestone Oct 25, 2017
@peppy peppy requested review from smoogipoo and Tom94 October 25, 2017 04:56
protected virtual void UpdateComponent()
{

}

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

@@ -43,10 +43,10 @@ protected override void Dispose(bool disposing)
base.Dispose(disposing);
}

public override void Update()
protected override void UpdateState()

This comment was marked as off-topic.

@@ -119,7 +119,7 @@ public override void Update()
currentAmplitudes.FrequencyAmplitudes = new float[256];
}

This comment was marked as off-topic.

smoogipoo
smoogipoo previously approved these changes Oct 25, 2017
Copy link
Contributor

@smoogipoo smoogipoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks okay to me, I guess. We'll determine later if running the FFT twice is going to be an issue.

Awaiting @Tom94's review.

Copy link
Collaborator

@Tom94 Tom94 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As it stands now I see 2 problems with this PR:

  • Calling UpdateState twice does not fully address race conditions. It merely reduces the latency until cached values are updated and thereby makes data races less likely to occur. I would prefer a more fundamental solution to this problem.
  • Setting isPlaying to false from the update thread may cause unpredictable behavior in audio-thread code which depends on the current state of isPlaying. Essentially one type of data race is replaced by another.

Also changes order of execution to update the state *after* all queued actions are completed.
@@ -21,9 +21,17 @@ public class AudioComponent : IDisposable, IUpdateable
}

/// <summary>
/// Run each loop of the audio thread after queued actions to allow components to update anything they need to.
/// If we require

This comment was marked as off-topic.

Tom94
Tom94 previously approved these changes Oct 27, 2017
@Tom94 Tom94 merged commit 767a0b1 into ppy:master Oct 27, 2017
@peppy peppy deleted the safe-audio-component-updates branch November 22, 2017 11:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants