Skip to content

Commit 3fe92fb

Browse files
authored
Merge pull request #32158 from bdach/scaling-crash
Fix possible crash when scaling objects in editor
2 parents 57ec2f7 + 47747ae commit 3fe92fb

File tree

11 files changed

+32
-26
lines changed

11 files changed

+32
-26
lines changed

CodeAnalysis/BannedSymbols.txt

+3
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,6 @@ M:Humanizer.InflectorExtensions.Pascalize(System.String);Humanizer's .Pascalize(
1818
M:Humanizer.InflectorExtensions.Camelize(System.String);Humanizer's .Camelize() extension method changes behaviour depending on CultureInfo.CurrentCulture. Use StringDehumanizeExtensions.ToCamelCase() instead.
1919
M:Humanizer.InflectorExtensions.Underscore(System.String);Humanizer's .Underscore() extension method changes behaviour depending on CultureInfo.CurrentCulture. Use StringDehumanizeExtensions.ToSnakeCase() instead.
2020
M:Humanizer.InflectorExtensions.Kebaberize(System.String);Humanizer's .Kebaberize() extension method changes behaviour depending on CultureInfo.CurrentCulture. Use StringDehumanizeExtensions.ToKebabCase() instead.
21+
M:osuTK.MathHelper.Clamp(System.Int32,System.Int32,System.Int32)~System.Int32;Use Math.Clamp() instead.
22+
M:osuTK.MathHelper.Clamp(System.Single,System.Single,System.Single)~System.Single;This osuTK helper has unsafe semantics when one of the bounds provided is NaN. Use Math.Clamp() instead.
23+
M:osuTK.MathHelper.Clamp(System.Double,System.Double,System.Double)~System.Double;This osuTK helper has unsafe semantics when one of the bounds provided is NaN. Use Math.Clamp() instead.

Templates/Rulesets/ruleset-scrolling-example/osu.Game.Rulesets.Pippidon/Beatmaps/PippidonBeatmapConverter.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
22
// See the LICENCE file in the repository root for full licence text.
33

4+
using System;
45
using System.Collections.Generic;
56
using System.Linq;
67
using System.Threading;
@@ -9,7 +10,6 @@
910
using osu.Game.Rulesets.Objects.Types;
1011
using osu.Game.Rulesets.Pippidon.Objects;
1112
using osu.Game.Rulesets.Pippidon.UI;
12-
using osuTK;
1313

1414
namespace osu.Game.Rulesets.Pippidon.Beatmaps
1515
{
@@ -40,7 +40,7 @@ protected override IEnumerable<PippidonHitObject> ConvertHitObject(HitObject ori
4040
};
4141
}
4242

43-
private int getLane(HitObject hitObject) => (int)MathHelper.Clamp(
43+
private int getLane(HitObject hitObject) => (int)Math.Clamp(
4444
(getUsablePosition(hitObject) - minPosition) / (maxPosition - minPosition) * PippidonPlayfield.LANE_COUNT, 0, PippidonPlayfield.LANE_COUNT - 1);
4545

4646
private float getUsablePosition(HitObject h) => (h as IHasYPosition)?.Y ?? ((IHasXPosition)h).X;

osu.Game.Rulesets.Catch/Skinning/Argon/ArgonBananaPiece.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
22
// See the LICENCE file in the repository root for full licence text.
33

4+
using System;
45
using osu.Framework.Allocation;
56
using osu.Framework.Extensions.Color4Extensions;
67
using osu.Framework.Graphics;
@@ -110,7 +111,7 @@ protected override void Update()
110111

111112
double duration = ObjectState.HitObject.StartTime - ObjectState.DisplayStartTime;
112113

113-
fadeContent.Alpha = MathHelper.Clamp(
114+
fadeContent.Alpha = Math.Clamp(
114115
Interpolation.ValueAt(
115116
Time.Current, 1f, 0f,
116117
ObjectState.DisplayStartTime + duration * lens_flare_start,

osu.Game.Rulesets.Osu/Edit/Blueprints/HitCircles/Components/HitCircleOverlapMarker.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#nullable disable
55

6+
using System;
67
using osu.Framework.Allocation;
78
using osu.Framework.Bindables;
89
using osu.Framework.Graphics;
@@ -76,7 +77,7 @@ public override void UpdateFrom(HitCircle hitObject)
7677
if (hasReachedObject && showHitMarkers.Value)
7778
{
7879
float alpha = Interpolation.ValueAt(editorTime, 0, 1f, hitObjectTime, hitObjectTime + FADE_OUT_EXTENSION, Easing.In);
79-
float ringScale = MathHelper.Clamp(Interpolation.ValueAt(editorTime, 0, 1f, hitObjectTime, hitObjectTime + FADE_OUT_EXTENSION / 2, Easing.OutQuint), 0, 1);
80+
float ringScale = Math.Clamp(Interpolation.ValueAt(editorTime, 0, 1f, hitObjectTime, hitObjectTime + FADE_OUT_EXTENSION / 2, Easing.OutQuint), 0, 1);
8081

8182
ring.Scale = new Vector2(1 + 0.1f * ringScale);
8283
content.Alpha = 0.9f * (1 - alpha);

osu.Game.Rulesets.Osu/Edit/Blueprints/Sliders/SliderSelectionBlueprint.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -270,14 +270,14 @@ private void adjustLength(double proposedDistance, bool adjustVelocity)
270270
if (adjustVelocity)
271271
{
272272
proposedVelocity = proposedDistance / oldDuration;
273-
proposedDistance = MathHelper.Clamp(proposedDistance, 0.1 * oldDuration, 10 * oldDuration);
273+
proposedDistance = Math.Clamp(proposedDistance, 0.1 * oldDuration, 10 * oldDuration);
274274
}
275275
else
276276
{
277277
double minDistance = distanceSnapProvider?.GetBeatSnapDistance() * oldVelocityMultiplier ?? 1;
278278
// Add a small amount to the proposed distance to make it easier to snap to the full length of the slider.
279279
proposedDistance = distanceSnapProvider?.FindSnappedDistance((float)proposedDistance + 1, HitObject.StartTime, HitObject) ?? proposedDistance;
280-
proposedDistance = MathHelper.Clamp(proposedDistance, minDistance, HitObject.Path.CalculatedDistance);
280+
proposedDistance = Math.Clamp(proposedDistance, minDistance, HitObject.Path.CalculatedDistance);
281281
}
282282

283283
if (Precision.AlmostEquals(proposedDistance, HitObject.Path.Distance) && Precision.AlmostEquals(proposedVelocity, HitObject.SliderVelocityMultiplier))

osu.Game.Rulesets.Osu/Edit/OsuSelectionScaleHandler.cs

+6-6
Original file line numberDiff line numberDiff line change
@@ -263,24 +263,24 @@ Vector2 clampToBounds(Vector2 s, Vector2 p, Vector2 lowerBounds, Vector2 upperBo
263263
{
264264
case Axes.X:
265265
(sLowerBound, sUpperBound) = computeBounds(lowerBounds - b, upperBounds - b, a);
266-
s.X = MathHelper.Clamp(s.X, sLowerBound, sUpperBound);
266+
s.X = Math.Clamp(s.X, sLowerBound, sUpperBound);
267267
break;
268268

269269
case Axes.Y:
270270
(sLowerBound, sUpperBound) = computeBounds(lowerBounds - a, upperBounds - a, b);
271-
s.Y = MathHelper.Clamp(s.Y, sLowerBound, sUpperBound);
271+
s.Y = Math.Clamp(s.Y, sLowerBound, sUpperBound);
272272
break;
273273

274274
case Axes.Both:
275275
// Here we compute the bounds for the magnitude multiplier of the scale vector
276276
// Therefore the ratio s.X / s.Y will be maintained
277277
(sLowerBound, sUpperBound) = computeBounds(lowerBounds, upperBounds, a * s.X + b * s.Y);
278278
s.X = s.X < 0
279-
? MathHelper.Clamp(s.X, s.X * sUpperBound, s.X * sLowerBound)
280-
: MathHelper.Clamp(s.X, s.X * sLowerBound, s.X * sUpperBound);
279+
? Math.Clamp(s.X, s.X * sUpperBound, s.X * sLowerBound)
280+
: Math.Clamp(s.X, s.X * sLowerBound, s.X * sUpperBound);
281281
s.Y = s.Y < 0
282-
? MathHelper.Clamp(s.Y, s.Y * sUpperBound, s.Y * sLowerBound)
283-
: MathHelper.Clamp(s.Y, s.Y * sLowerBound, s.Y * sUpperBound);
282+
? Math.Clamp(s.Y, s.Y * sUpperBound, s.Y * sLowerBound)
283+
: Math.Clamp(s.Y, s.Y * sLowerBound, s.Y * sUpperBound);
284284
break;
285285
}
286286

osu.Game/Overlays/NotificationOverlayToastTray.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ protected override void Update()
174174
}
175175

176176
height = toastFlow.DrawHeight + 120;
177-
alpha = MathHelper.Clamp(toastFlow.DrawHeight / 41, 0, 1) * maxNotificationAlpha;
177+
alpha = Math.Clamp(toastFlow.DrawHeight / 41, 0, 1) * maxNotificationAlpha;
178178
}
179179

180180
toastContentBackground.Height = (float)Interpolation.DampContinuously(toastContentBackground.Height, height, 10, Clock.ElapsedFrameTime);

osu.Game/Screens/Play/HUDOverlay.cs

+6-6
Original file line numberDiff line numberDiff line change
@@ -277,18 +277,18 @@ protected override void Update()
277277
if (rulesetComponents != null)
278278
processDrawables(rulesetComponents);
279279

280-
if (lowestTopScreenSpaceRight.HasValue)
281-
TopRightElements.Y = MathHelper.Clamp(ToLocalSpace(new Vector2(0, lowestTopScreenSpaceRight.Value)).Y, 0, DrawHeight - TopRightElements.DrawHeight);
280+
if (lowestTopScreenSpaceRight.HasValue && DrawHeight - TopRightElements.DrawHeight > 0)
281+
TopRightElements.Y = Math.Clamp(ToLocalSpace(new Vector2(0, lowestTopScreenSpaceRight.Value)).Y, 0, DrawHeight - TopRightElements.DrawHeight);
282282
else
283283
TopRightElements.Y = 0;
284284

285-
if (lowestTopScreenSpaceLeft.HasValue)
286-
LeaderboardFlow.Y = MathHelper.Clamp(ToLocalSpace(new Vector2(0, lowestTopScreenSpaceLeft.Value)).Y, 0, DrawHeight - LeaderboardFlow.DrawHeight);
285+
if (lowestTopScreenSpaceLeft.HasValue && DrawHeight - LeaderboardFlow.DrawHeight > 0)
286+
LeaderboardFlow.Y = Math.Clamp(ToLocalSpace(new Vector2(0, lowestTopScreenSpaceLeft.Value)).Y, 0, DrawHeight - LeaderboardFlow.DrawHeight);
287287
else
288288
LeaderboardFlow.Y = 0;
289289

290-
if (highestBottomScreenSpace.HasValue)
291-
bottomRightElements.Y = BottomScoringElementsHeight = -MathHelper.Clamp(DrawHeight - ToLocalSpace(highestBottomScreenSpace.Value).Y, 0, DrawHeight - bottomRightElements.DrawHeight);
290+
if (highestBottomScreenSpace.HasValue && DrawHeight - bottomRightElements.DrawHeight > 0)
291+
bottomRightElements.Y = BottomScoringElementsHeight = -Math.Clamp(DrawHeight - ToLocalSpace(highestBottomScreenSpace.Value).Y, 0, DrawHeight - bottomRightElements.DrawHeight);
292292
else
293293
bottomRightElements.Y = 0;
294294

osu.Game/Screens/Utility/CircleGameplay.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,8 @@ protected override void UpdateAtLimitedRate(InputState inputState)
201201
{
202202
double preempt = (float)IBeatmapDifficultyInfo.DifficultyRange(SampleApproachRate.Value, 1800, 1200, 450);
203203

204-
approach.Scale = new Vector2(1 + 4 * (float)MathHelper.Clamp((HitTime - Clock.CurrentTime) / preempt, 0, 100));
205-
Alpha = (float)MathHelper.Clamp((Clock.CurrentTime - HitTime + 600) / 400, 0, 1);
204+
approach.Scale = new Vector2(1 + 4 * (float)Math.Clamp((HitTime - Clock.CurrentTime) / preempt, 0, 100));
205+
Alpha = (float)Math.Clamp((Clock.CurrentTime - HitTime + 600) / 400, 0, 1);
206206

207207
if (Clock.CurrentTime > HitTime + duration)
208208
Expire();

osu.Game/Screens/Utility/SampleComponents/LatencyMovableBox.cs

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
22
// See the LICENCE file in the repository root for full licence text.
33

4+
using System;
45
using osu.Framework.Graphics;
56
using osu.Framework.Graphics.Shapes;
67
using osu.Framework.Input.Events;
@@ -55,22 +56,22 @@ protected override void UpdateAtLimitedRate(InputState inputState)
5556
{
5657
case Key.F:
5758
case Key.Up:
58-
box.Y = MathHelper.Clamp(box.Y - movementAmount, 0.1f, 0.9f);
59+
box.Y = Math.Clamp(box.Y - movementAmount, 0.1f, 0.9f);
5960
break;
6061

6162
case Key.J:
6263
case Key.Down:
63-
box.Y = MathHelper.Clamp(box.Y + movementAmount, 0.1f, 0.9f);
64+
box.Y = Math.Clamp(box.Y + movementAmount, 0.1f, 0.9f);
6465
break;
6566

6667
case Key.Z:
6768
case Key.Left:
68-
box.X = MathHelper.Clamp(box.X - movementAmount, 0.1f, 0.9f);
69+
box.X = Math.Clamp(box.X - movementAmount, 0.1f, 0.9f);
6970
break;
7071

7172
case Key.X:
7273
case Key.Right:
73-
box.X = MathHelper.Clamp(box.X + movementAmount, 0.1f, 0.9f);
74+
box.X = Math.Clamp(box.X + movementAmount, 0.1f, 0.9f);
7475
break;
7576
}
7677
}

osu.Game/Screens/Utility/ScrollingGameplay.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ protected override void UpdateAtLimitedRate(InputState inputState)
165165
{
166166
double preempt = (float)IBeatmapDifficultyInfo.DifficultyRange(SampleApproachRate.Value, 1800, 1200, 450);
167167

168-
Alpha = (float)MathHelper.Clamp((Clock.CurrentTime - HitTime + 600) / 400, 0, 1);
168+
Alpha = (float)Math.Clamp((Clock.CurrentTime - HitTime + 600) / 400, 0, 1);
169169
Y = judgement_position - (float)((HitTime - Clock.CurrentTime) / preempt);
170170

171171
if (Clock.CurrentTime > HitTime + duration)

0 commit comments

Comments
 (0)