Skip to content

Commit

Permalink
Merge pull request ppy#6174 from Susko3/RequireStaticDelegate-annotation
Browse files Browse the repository at this point in the history
Add `[RequireStaticDelegate]` annotations
  • Loading branch information
smoogipoo authored Feb 17, 2024
2 parents b89c970 + 82174f4 commit 5d98a51
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 8 deletions.
3 changes: 2 additions & 1 deletion osu.Framework/Allocation/InvokeOnDisposal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// See the LICENCE file in the repository root for full licence text.

using System;
using JetBrains.Annotations;

namespace osu.Framework.Allocation
{
Expand Down Expand Up @@ -58,7 +59,7 @@ public class InvokeOnDisposal<T> : IDisposable
/// </summary>
/// <param name="sender">The sender which should appear in the <paramref name="action"/> callback.</param>
/// <param name="action">The action to invoke during disposal.</param>
public InvokeOnDisposal(T sender, Action<T> action)
public InvokeOnDisposal(T sender, [RequireStaticDelegate(IsError = true)] Action<T> action)
{
this.sender = sender;
this.action = action ?? throw new ArgumentNullException(nameof(action));
Expand Down
3 changes: 2 additions & 1 deletion osu.Framework/Allocation/ValueInvokeOnDisposal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// See the LICENCE file in the repository root for full licence text.

using System;
using JetBrains.Annotations;

namespace osu.Framework.Allocation
{
Expand Down Expand Up @@ -62,7 +63,7 @@ public void Dispose()
/// </summary>
/// <param name="sender">The sender which should appear in the <paramref name="action"/> callback.</param>
/// <param name="action">The action to invoke during disposal.</param>
public ValueInvokeOnDisposal(T sender, Action<T> action)
public ValueInvokeOnDisposal(T sender, [RequireStaticDelegate(IsError = true)] Action<T> action)
{
this.sender = sender;
this.action = action ?? throw new ArgumentNullException(nameof(action));
Expand Down
4 changes: 2 additions & 2 deletions osu.Framework/Graphics/BufferedDrawNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ protected IDisposable BindFrameBuffer(IFrameBuffer frameBuffer)

frameBuffer.Bind();

return new ValueInvokeOnDisposal<IFrameBuffer>(frameBuffer, b => b.Unbind());
return new ValueInvokeOnDisposal<IFrameBuffer>(frameBuffer, static b => b.Unbind());
}

private IDisposable establishFrameBufferViewport(IRenderer renderer)
Expand All @@ -175,7 +175,7 @@ private IDisposable establishFrameBufferViewport(IRenderer renderer)
renderer.PushScissor(new RectangleI(0, 0, (int)frameBufferSize.X, (int)frameBufferSize.Y));
renderer.PushScissorOffset(screenSpaceMaskingRect.Location);

return new ValueInvokeOnDisposal<(BufferedDrawNode node, IRenderer renderer)>((this, renderer), tup => tup.node.returnViewport(tup.renderer));
return new ValueInvokeOnDisposal<(BufferedDrawNode node, IRenderer renderer)>((this, renderer), static tup => tup.node.returnViewport(tup.renderer));
}

private void returnViewport(IRenderer renderer)
Expand Down
4 changes: 2 additions & 2 deletions osu.Framework/Graphics/Transforms/Transformable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ public IDisposable BeginDelayedSequence(double delay, bool recursive = true)
AddDelay(delay, recursive);
double newTransformDelay = TransformDelay;

return new ValueInvokeOnDisposal<DelayedSequenceSender>(new DelayedSequenceSender(this, delay, recursive, newTransformDelay), sender =>
return new ValueInvokeOnDisposal<DelayedSequenceSender>(new DelayedSequenceSender(this, delay, recursive, newTransformDelay), static sender =>
{
if (!Precision.AlmostEquals(sender.NewTransformDelay, sender.Transformable.TransformDelay))
{
Expand All @@ -292,7 +292,7 @@ public IDisposable BeginDelayedSequence(double delay, bool recursive = true)
$"(begin={sender.NewTransformDelay} end={sender.Transformable.TransformDelay})");
}
AddDelay(-sender.Delay, sender.Recursive);
sender.Transformable.AddDelay(-sender.Delay, sender.Recursive);
});
}

Expand Down
5 changes: 3 additions & 2 deletions osu.Framework/Platform/NativeMemoryTracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// See the LICENCE file in the repository root for full licence text.

using System;
using JetBrains.Annotations;
using osu.Framework.Allocation;
using osu.Framework.Statistics;

Expand All @@ -22,7 +23,7 @@ public static class NativeMemoryTracker
public static NativeMemoryLease AddMemory(object source, long amount)
{
getStatistic(source).Value += amount;
return new NativeMemoryLease((source, amount), sender => removeMemory(sender.source, sender.amount));
return new NativeMemoryLease((source, amount), static sender => removeMemory(sender.source, sender.amount));
}

/// <summary>
Expand All @@ -42,7 +43,7 @@ private static void removeMemory(object source, long amount)
/// </summary>
public class NativeMemoryLease : InvokeOnDisposal<(object source, long amount)>
{
internal NativeMemoryLease((object source, long amount) sender, Action<(object source, long amount)> action)
internal NativeMemoryLease((object source, long amount) sender, [RequireStaticDelegate(IsError = true)] Action<(object source, long amount)> action)
: base(sender, action)
{
}
Expand Down

0 comments on commit 5d98a51

Please sign in to comment.