From 099ad22a92658f8bc016a1abe72fb2b13fb99da6 Mon Sep 17 00:00:00 2001 From: Dan Balasescu Date: Mon, 1 Apr 2024 15:31:34 +0900 Subject: [PATCH] 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. --- .../Sliders/Components/PathControlPointConnectionPiece.cs | 4 +++- .../Blueprints/Sliders/Components/PathControlPointPiece.cs | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/osu.Game.Rulesets.Osu/Edit/Blueprints/Sliders/Components/PathControlPointConnectionPiece.cs b/osu.Game.Rulesets.Osu/Edit/Blueprints/Sliders/Components/PathControlPointConnectionPiece.cs index 56dc16dd95..9b3d8fc7a7 100644 --- a/osu.Game.Rulesets.Osu/Edit/Blueprints/Sliders/Components/PathControlPointConnectionPiece.cs +++ b/osu.Game.Rulesets.Osu/Edit/Blueprints/Sliders/Components/PathControlPointConnectionPiece.cs @@ -28,6 +28,7 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components private IBindable hitObjectPosition; private IBindable pathVersion; + private IBindable 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(); } diff --git a/osu.Game.Rulesets.Osu/Edit/Blueprints/Sliders/Components/PathControlPointPiece.cs b/osu.Game.Rulesets.Osu/Edit/Blueprints/Sliders/Components/PathControlPointPiece.cs index ee306fb6d7..c6e05d3ca3 100644 --- a/osu.Game.Rulesets.Osu/Edit/Blueprints/Sliders/Components/PathControlPointPiece.cs +++ b/osu.Game.Rulesets.Osu/Edit/Blueprints/Sliders/Components/PathControlPointPiece.cs @@ -48,6 +48,7 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components private IBindable hitObjectPosition; private IBindable hitObjectScale; + private IBindable 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());