mirror of
https://github.com/ppy/osu.git
synced 2025-01-12 17:35:10 +08:00
Use local bindable instead
Binding events directly to an external bindable will cause that bindable to hold a permanent reference to the current object. We use `GetBoundCopy()` or otherwise a local bindable + `.BindTo()` to create a weak-referenced copy of the target bindable. When the local bindable's lifetime expires, so does the external bindable's reference to it.
This commit is contained in:
parent
7615c71efe
commit
099ad22a92
@ -28,6 +28,7 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components
|
||||
|
||||
private IBindable<Vector2> hitObjectPosition;
|
||||
private IBindable<int> pathVersion;
|
||||
private IBindable<int> stackHeight;
|
||||
|
||||
public PathControlPointConnectionPiece(T hitObject, int controlPointIndex)
|
||||
{
|
||||
@ -56,7 +57,8 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components
|
||||
pathVersion = hitObject.Path.Version.GetBoundCopy();
|
||||
pathVersion.BindValueChanged(_ => Scheduler.AddOnce(updateConnectingPath));
|
||||
|
||||
hitObject.StackHeightBindable.BindValueChanged(_ => updateConnectingPath());
|
||||
stackHeight = hitObject.StackHeightBindable.GetBoundCopy();
|
||||
stackHeight.BindValueChanged(_ => updateConnectingPath());
|
||||
|
||||
updateConnectingPath();
|
||||
}
|
||||
|
@ -48,6 +48,7 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components
|
||||
|
||||
private IBindable<Vector2> hitObjectPosition;
|
||||
private IBindable<float> hitObjectScale;
|
||||
private IBindable<int> stackHeight;
|
||||
|
||||
public PathControlPointPiece(T hitObject, PathControlPoint controlPoint)
|
||||
{
|
||||
@ -105,7 +106,8 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components
|
||||
hitObjectScale = hitObject.ScaleBindable.GetBoundCopy();
|
||||
hitObjectScale.BindValueChanged(_ => updateMarkerDisplay());
|
||||
|
||||
hitObject.StackHeightBindable.BindValueChanged(_ => updateMarkerDisplay());
|
||||
stackHeight = hitObject.StackHeightBindable.GetBoundCopy();
|
||||
stackHeight.BindValueChanged(_ => updateMarkerDisplay());
|
||||
|
||||
IsSelected.BindValueChanged(_ => updateMarkerDisplay());
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user