Skip to content

Commit 456fbf3

Browse files
committed
Fix null branch UUID parsing
1 parent 929098e commit 456fbf3

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

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

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ public void LoadBranch(int index)
468468
{
469469
if (Engaged())
470470
{
471-
var marker = MarkerListForBranch(branchID).Get(frame);
471+
var marker = MarkerListForBranch(branchID)?.Get(frame);
472472
if (marker != null)
473473
{
474474
return marker.Message;
@@ -479,13 +479,10 @@ public void LoadBranch(int index)
479479
}
480480

481481
/// <remarks>assumes a TAStudio project is loaded</remarks>
482-
private TasMovieMarkerList MarkerListForBranch(string/*?*/ branchID)
483-
{
484-
var found = Guid.TryParseExact(branchID, format: "D", out var parsed)
485-
? Tastudio.CurrentTasMovie.Branches.FirstOrDefault(branch => branch.Uuid == parsed)
486-
: null;
487-
return found?.Markers ?? Tastudio.CurrentTasMovie.Markers;
488-
}
482+
private TasMovieMarkerList/*?*/ MarkerListForBranch(string/*?*/ branchID)
483+
=> Guid.TryParseExact(branchID, format: "D", out var parsed)
484+
? Tastudio.CurrentTasMovie.Branches.FirstOrDefault(branch => branch.Uuid == parsed)?.Markers
485+
: branchID is null ? Tastudio.CurrentTasMovie.Markers : null; // not a typo; null `branchID` indicates main log
489486

490487
[LuaMethodExample("""
491488
local marker_label = tastudio.getmarker(tastudio.find_marker_on_or_before(100));
@@ -496,8 +493,8 @@ private TasMovieMarkerList MarkerListForBranch(string/*?*/ branchID)
496493
+ " This may be the power-on marker at 0."
497494
+ " If branchID is specified, searches the markers in that branch instead.")]
498495
public int FindMarkerOnOrBefore(int frame, string/*?*/ branchID = null)
499-
=> Engaged()
500-
? MarkerListForBranch(branchID).PreviousOrCurrent(frame).Frame
496+
=> Engaged() && MarkerListForBranch(branchID) is TasMovieMarkerList markers
497+
? markers.PreviousOrCurrent(frame).Frame
501498
: default;
502499

503500
[LuaMethodExample("""
@@ -508,8 +505,8 @@ public int FindMarkerOnOrBefore(int frame, string/*?*/ branchID = null)
508505
description: "Returns a list of all the frames which have markers on them."
509506
+ " If branchID is specified, instead returns the frames which have markers in that branch.")]
510507
public LuaTable GetFramesWithMarkers(string/*?*/ branchID = null)
511-
=> Engaged()
512-
? _th.EnumerateToLuaTable(MarkerListForBranch(branchID).Select(static m => m.Frame))
508+
=> Engaged() && MarkerListForBranch(branchID) is TasMovieMarkerList markers
509+
? _th.EnumerateToLuaTable(markers.Select(static m => m.Frame))
513510
: _th.CreateTable();
514511

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

0 commit comments

Comments
 (0)