1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-21 15:27:24 +08:00

Fix crashes when opening scale/rotation popovers during selection box operations

This commit is contained in:
Bartłomiej Dach 2024-06-25 15:01:43 +02:00
parent 6cd1367329
commit 2fda45cad4
No known key found for this signature in database
7 changed files with 40 additions and 10 deletions

View File

@ -53,9 +53,11 @@ namespace osu.Game.Rulesets.Osu.Edit
public override void Begin() public override void Begin()
{ {
if (objectsInRotation != null) if (OperationInProgress.Value)
throw new InvalidOperationException($"Cannot {nameof(Begin)} a rotate operation while another is in progress!"); throw new InvalidOperationException($"Cannot {nameof(Begin)} a rotate operation while another is in progress!");
base.Begin();
changeHandler?.BeginChange(); changeHandler?.BeginChange();
objectsInRotation = selectedMovableObjects.ToArray(); objectsInRotation = selectedMovableObjects.ToArray();
@ -68,10 +70,10 @@ namespace osu.Game.Rulesets.Osu.Edit
public override void Update(float rotation, Vector2? origin = null) public override void Update(float rotation, Vector2? origin = null)
{ {
if (objectsInRotation == null) if (!OperationInProgress.Value)
throw new InvalidOperationException($"Cannot {nameof(Update)} a rotate operation without calling {nameof(Begin)} first!"); throw new InvalidOperationException($"Cannot {nameof(Update)} a rotate operation without calling {nameof(Begin)} first!");
Debug.Assert(originalPositions != null && originalPathControlPointPositions != null && defaultOrigin != null); Debug.Assert(objectsInRotation != null && originalPositions != null && originalPathControlPointPositions != null && defaultOrigin != null);
Vector2 actualOrigin = origin ?? defaultOrigin.Value; Vector2 actualOrigin = origin ?? defaultOrigin.Value;
@ -91,11 +93,13 @@ namespace osu.Game.Rulesets.Osu.Edit
public override void Commit() public override void Commit()
{ {
if (objectsInRotation == null) if (!OperationInProgress.Value)
throw new InvalidOperationException($"Cannot {nameof(Commit)} a rotate operation without calling {nameof(Begin)} first!"); throw new InvalidOperationException($"Cannot {nameof(Commit)} a rotate operation without calling {nameof(Begin)} first!");
changeHandler?.EndChange(); changeHandler?.EndChange();
base.Commit();
objectsInRotation = null; objectsInRotation = null;
originalPositions = null; originalPositions = null;
originalPathControlPointPositions = null; originalPathControlPointPositions = null;

View File

@ -72,9 +72,11 @@ namespace osu.Game.Rulesets.Osu.Edit
public override void Begin() public override void Begin()
{ {
if (objectsInScale != null) if (OperationInProgress.Value)
throw new InvalidOperationException($"Cannot {nameof(Begin)} a scale operation while another is in progress!"); throw new InvalidOperationException($"Cannot {nameof(Begin)} a scale operation while another is in progress!");
base.Begin();
changeHandler?.BeginChange(); changeHandler?.BeginChange();
objectsInScale = selectedMovableObjects.ToDictionary(ho => ho, ho => new OriginalHitObjectState(ho)); objectsInScale = selectedMovableObjects.ToDictionary(ho => ho, ho => new OriginalHitObjectState(ho));
@ -86,10 +88,10 @@ namespace osu.Game.Rulesets.Osu.Edit
public override void Update(Vector2 scale, Vector2? origin = null, Axes adjustAxis = Axes.Both) public override void Update(Vector2 scale, Vector2? origin = null, Axes adjustAxis = Axes.Both)
{ {
if (objectsInScale == null) if (!OperationInProgress.Value)
throw new InvalidOperationException($"Cannot {nameof(Update)} a scale operation without calling {nameof(Begin)} first!"); throw new InvalidOperationException($"Cannot {nameof(Update)} a scale operation without calling {nameof(Begin)} first!");
Debug.Assert(defaultOrigin != null && OriginalSurroundingQuad != null); Debug.Assert(objectsInScale != null && defaultOrigin != null && OriginalSurroundingQuad != null);
Vector2 actualOrigin = origin ?? defaultOrigin.Value; Vector2 actualOrigin = origin ?? defaultOrigin.Value;
@ -117,11 +119,13 @@ namespace osu.Game.Rulesets.Osu.Edit
public override void Commit() public override void Commit()
{ {
if (objectsInScale == null) if (!OperationInProgress.Value)
throw new InvalidOperationException($"Cannot {nameof(Commit)} a rotate operation without calling {nameof(Begin)} first!"); throw new InvalidOperationException($"Cannot {nameof(Commit)} a rotate operation without calling {nameof(Begin)} first!");
changeHandler?.EndChange(); changeHandler?.EndChange();
base.Commit();
objectsInScale = null; objectsInScale = null;
OriginalSurroundingQuad = null; OriginalSurroundingQuad = null;
defaultOrigin = null; defaultOrigin = null;

View File

@ -77,13 +77,15 @@ namespace osu.Game.Rulesets.Osu.Edit
{ {
case GlobalAction.EditorToggleRotateControl: case GlobalAction.EditorToggleRotateControl:
{ {
rotateButton.TriggerClick(); if (!RotationHandler.OperationInProgress.Value || rotateButton.Selected.Value)
rotateButton.TriggerClick();
return true; return true;
} }
case GlobalAction.EditorToggleScaleControl: case GlobalAction.EditorToggleScaleControl:
{ {
scaleButton.TriggerClick(); if (!ScaleHandler.OperationInProgress.Value || scaleButton.Selected.Value)
scaleButton.TriggerClick();
return true; return true;
} }
} }

View File

@ -67,6 +67,9 @@ namespace osu.Game.Screens.Edit.Compose.Components
if (rotationHandler == null) return false; if (rotationHandler == null) return false;
if (rotationHandler.OperationInProgress.Value)
return false;
rotationHandler.Begin(); rotationHandler.Begin();
return true; return true;
} }

View File

@ -32,6 +32,9 @@ namespace osu.Game.Screens.Edit.Compose.Components
if (scaleHandler == null) return false; if (scaleHandler == null) return false;
if (scaleHandler.OperationInProgress.Value)
return false;
originalAnchor = Anchor; originalAnchor = Anchor;
scaleHandler.Begin(); scaleHandler.Begin();

View File

@ -12,6 +12,11 @@ namespace osu.Game.Screens.Edit.Compose.Components
/// </summary> /// </summary>
public partial class SelectionRotationHandler : Component public partial class SelectionRotationHandler : Component
{ {
/// <summary>
/// Whether there is any ongoing scale operation right now.
/// </summary>
public Bindable<bool> OperationInProgress { get; private set; } = new BindableBool();
/// <summary> /// <summary>
/// Whether rotation anchored by the selection origin can currently be performed. /// Whether rotation anchored by the selection origin can currently be performed.
/// </summary> /// </summary>
@ -50,6 +55,7 @@ namespace osu.Game.Screens.Edit.Compose.Components
/// </remarks> /// </remarks>
public virtual void Begin() public virtual void Begin()
{ {
OperationInProgress.Value = true;
} }
/// <summary> /// <summary>
@ -85,6 +91,7 @@ namespace osu.Game.Screens.Edit.Compose.Components
/// </remarks> /// </remarks>
public virtual void Commit() public virtual void Commit()
{ {
OperationInProgress.Value = false;
} }
} }
} }

View File

@ -13,6 +13,11 @@ namespace osu.Game.Screens.Edit.Compose.Components
/// </summary> /// </summary>
public partial class SelectionScaleHandler : Component public partial class SelectionScaleHandler : Component
{ {
/// <summary>
/// Whether there is any ongoing scale operation right now.
/// </summary>
public Bindable<bool> OperationInProgress { get; private set; } = new BindableBool();
/// <summary> /// <summary>
/// Whether horizontal scaling (from the left or right edge) support should be enabled. /// Whether horizontal scaling (from the left or right edge) support should be enabled.
/// </summary> /// </summary>
@ -63,6 +68,7 @@ namespace osu.Game.Screens.Edit.Compose.Components
/// </remarks> /// </remarks>
public virtual void Begin() public virtual void Begin()
{ {
OperationInProgress.Value = true;
} }
/// <summary> /// <summary>
@ -99,6 +105,7 @@ namespace osu.Game.Screens.Edit.Compose.Components
/// </remarks> /// </remarks>
public virtual void Commit() public virtual void Commit()
{ {
OperationInProgress.Value = false;
} }
} }
} }