Skip to content

Commit ac81d93

Browse files
committed
Refactor EmuClientApi.ShowFuture, throwing on invalid arg
fixes 6223c9d
1 parent c912df3 commit ac81d93

2 files changed

Lines changed: 11 additions & 5 deletions

File tree

src/BizHawk.Client.Common/Api/Classes/EmuClientApi.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -221,14 +221,16 @@ public void SetWindowSize(int size)
221221

222222
public void ShowFuture(ShowFutureCallback/*?*/ preFrameCallback, short maxFrames)
223223
{
224-
if (maxFrames < 1 && preFrameCallback != null)
224+
if (preFrameCallback is not null)
225225
{
226-
_logCallback($"Invalid number of future frames ({maxFrames}); number must be positive.");
227-
return;
226+
if (maxFrames <= 0) throw new ArgumentOutOfRangeException(paramName: nameof(maxFrames), maxFrames, message: "Invalid number of future frames, number must be positive.");
227+
_mainForm.MaxFutureFrames = maxFrames;
228+
}
229+
else
230+
{
231+
_mainForm.MaxFutureFrames = 0;
228232
}
229-
230233
_mainForm.PreFutureFrameCallback = preFrameCallback;
231-
_mainForm.MaxFutureFrames = maxFrames;
232234
}
233235

234236
public void SpeedMode(int percent)

src/BizHawk.Client.Common/Api/Interfaces/IEmuClientApi.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,10 @@ public interface IEmuClientApi : IDisposable, IExternalApi
145145
/// When the callback returns true, emulation will rewind to the real current frame and the just-run future frame will be displayed.
146146
/// <br/>Pass null to disable future frame display.</param>
147147
/// <param name="maxFrames">The maximum number of future frames to emulate. Useful to avoid freezing the client UI in case of accidentally never returning true from the callback.</param>
148+
/// <exception cref="ArgumentOutOfRangeException">
149+
/// <paramref name="maxFrames"/> ≤ <c>0</c>
150+
/// (and <paramref name="preFrameCallback"/> is a delegate, since <paramref name="maxFrames"/> is ignored when it's <see langword="null"/>)
151+
/// </exception>
148152
void ShowFuture(ShowFutureCallback/*?*/ preFrameCallback, short maxFrames);
149153

150154
void SpeedMode(int percent);

0 commit comments

Comments
 (0)