1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-13 08:32:57 +08:00

Merge pull request #18697 from frenzibyte/timeline-track-change-crash

Fix `ZoomableScrollContainer` attempting to update zoom with invalid range
This commit is contained in:
Dean Herbert 2022-06-15 14:41:37 +09:00 committed by GitHub
commit d1c236e187
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 12 deletions

View File

@ -78,6 +78,21 @@ namespace osu.Game.Tests.Visual.Editing
AddAssert("Inner container width matches scroll container", () => innerBox.DrawWidth == scrollContainer.DrawWidth);
}
[Test]
public void TestZoomRangeUpdate()
{
AddStep("set zoom to 2", () => scrollContainer.Zoom = 2);
AddStep("set min zoom to 5", () => scrollContainer.MinZoom = 5);
AddAssert("zoom = 5", () => scrollContainer.Zoom == 5);
AddStep("set max zoom to 10", () => scrollContainer.MaxZoom = 10);
AddAssert("zoom = 5", () => scrollContainer.Zoom == 5);
AddStep("set min zoom to 20", () => scrollContainer.MinZoom = 20);
AddStep("set max zoom to 40", () => scrollContainer.MaxZoom = 40);
AddAssert("zoom = 20", () => scrollContainer.Zoom == 20);
}
[Test]
public void TestZoom0()
{

View File

@ -66,8 +66,9 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
minZoom = value;
if (Zoom < value)
Zoom = value;
// ensure zoom range is in valid state before updating zoom.
if (MinZoom < MaxZoom)
updateZoom();
}
}
@ -86,8 +87,9 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
maxZoom = value;
if (Zoom > value)
Zoom = value;
// ensure zoom range is in valid state before updating zoom.
if (MaxZoom > MinZoom)
updateZoom();
}
}
@ -97,15 +99,17 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
public float Zoom
{
get => zoomTarget;
set
{
value = Math.Clamp(value, MinZoom, MaxZoom);
set => updateZoom(value);
}
if (IsLoaded)
setZoomTarget(value, ToSpaceOfOtherDrawable(new Vector2(DrawWidth / 2, 0), zoomedContent).X);
else
currentZoom = zoomTarget = value;
}
private void updateZoom(float? value = null)
{
float newZoom = Math.Clamp(value ?? Zoom, MinZoom, MaxZoom);
if (IsLoaded)
setZoomTarget(newZoom, ToSpaceOfOtherDrawable(new Vector2(DrawWidth / 2, 0), zoomedContent).X);
else
currentZoom = zoomTarget = newZoom;
}
protected override void Update()