Skip to content

Commit babc51f

Browse files
committed
Avoid throwing when new functions called with nonexistent branch index
1 parent ac5e389 commit babc51f

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/BizHawk.Client.EmuHawk/tools/Lua/Libraries/TAStudioLuaLibrary.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -462,9 +462,9 @@ public void LoadBranch(int index)
462462
}
463463

464464
/// <remarks>assumes a TAStudio project is loaded</remarks>
465-
private TasMovieMarkerList MarkerListForBranch(int? branchIndex)
465+
private TasMovieMarkerList/*?*/ MarkerListForBranch(int? branchIndex)
466466
=> branchIndex is int i
467-
? Tastudio.CurrentTasMovie.Branches[i].Markers
467+
? Tastudio.CurrentTasMovie.Branches.ElementAtOrDefault(i)?.Markers
468468
: Tastudio.CurrentTasMovie.Markers;
469469

470470
[LuaMethodExample("""
@@ -476,8 +476,8 @@ private TasMovieMarkerList MarkerListForBranch(int? branchIndex)
476476
+ " This may be the power-on marker at 0. Returns nil if the arguments are invalid or TAStudio isn't active."
477477
+ " If branchIndex is specified, searches the markers in that branch instead.")]
478478
public int? FindMarkerOnOrBefore(int frame, int? branchIndex = null)
479-
=> Engaged()
480-
? MarkerListForBranch(branchIndex).PreviousOrCurrent(frame)?.Frame
479+
=> Engaged() && MarkerListForBranch(branchIndex) is TasMovieMarkerList markers
480+
? markers.PreviousOrCurrent(frame)?.Frame
481481
: null;
482482

483483
[LuaMethodExample("""
@@ -488,8 +488,8 @@ private TasMovieMarkerList MarkerListForBranch(int? branchIndex)
488488
description: "Returns a list of all the frames which have markers on them."
489489
+ " If branchIndex is specified, instead returns the frames which have markers in that branch.")]
490490
public LuaTable GetFramesWithMarkers(int? branchIndex = null)
491-
=> Engaged()
492-
? _th.EnumerateToLuaTable(MarkerListForBranch(branchIndex).Select(static m => m.Frame))
491+
=> Engaged() && MarkerListForBranch(branchIndex) is TasMovieMarkerList markers
492+
? _th.EnumerateToLuaTable(markers.Select(static m => m.Frame))
493493
: _th.CreateTable();
494494

495495
[LuaMethodExample("tastudio.removemarker( 500 );")]

0 commit comments

Comments
 (0)