1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 11:37:28 +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:
Dan Balasescu 2024-04-01 15:31:34 +09:00
parent 7615c71efe
commit 099ad22a92
No known key found for this signature in database
2 changed files with 6 additions and 2 deletions

View File

@ -28,6 +28,7 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components
private IBindable<Vector2> hitObjectPosition; private IBindable<Vector2> hitObjectPosition;
private IBindable<int> pathVersion; private IBindable<int> pathVersion;
private IBindable<int> stackHeight;
public PathControlPointConnectionPiece(T hitObject, int controlPointIndex) 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 = hitObject.Path.Version.GetBoundCopy();
pathVersion.BindValueChanged(_ => Scheduler.AddOnce(updateConnectingPath)); pathVersion.BindValueChanged(_ => Scheduler.AddOnce(updateConnectingPath));
hitObject.StackHeightBindable.BindValueChanged(_ => updateConnectingPath()); stackHeight = hitObject.StackHeightBindable.GetBoundCopy();
stackHeight.BindValueChanged(_ => updateConnectingPath());
updateConnectingPath(); updateConnectingPath();
} }

View File

@ -48,6 +48,7 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components
private IBindable<Vector2> hitObjectPosition; private IBindable<Vector2> hitObjectPosition;
private IBindable<float> hitObjectScale; private IBindable<float> hitObjectScale;
private IBindable<int> stackHeight;
public PathControlPointPiece(T hitObject, PathControlPoint controlPoint) public PathControlPointPiece(T hitObject, PathControlPoint controlPoint)
{ {
@ -105,7 +106,8 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components
hitObjectScale = hitObject.ScaleBindable.GetBoundCopy(); hitObjectScale = hitObject.ScaleBindable.GetBoundCopy();
hitObjectScale.BindValueChanged(_ => updateMarkerDisplay()); hitObjectScale.BindValueChanged(_ => updateMarkerDisplay());
hitObject.StackHeightBindable.BindValueChanged(_ => updateMarkerDisplay()); stackHeight = hitObject.StackHeightBindable.GetBoundCopy();
stackHeight.BindValueChanged(_ => updateMarkerDisplay());
IsSelected.BindValueChanged(_ => updateMarkerDisplay()); IsSelected.BindValueChanged(_ => updateMarkerDisplay());