Skip to content

Commit

Permalink
fix: fixes null ref when sort header is null
Browse files Browse the repository at this point in the history
fixes #4
  • Loading branch information
James-Frowen committed Sep 8, 2022
1 parent ad29f2e commit d233036
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions Assets/Mirage.Profiler/Editor/Messages/GroupSorter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,19 @@ namespace Mirage.NetworkProfiler.ModuleGUI.Messages
internal struct GroupSorter
{
private readonly Dictionary<string, Group> _grouped;
private readonly ColumnInfo _sortHeader;
private readonly Func<Group, Group, int> _sortGroupFunc;
private readonly Func<MessageInfo, MessageInfo, int> _sortMessageFunc;

private readonly SortMode _sortMode;

public GroupSorter(Dictionary<string, Group> grouped, ColumnInfo sortHeader, SortMode sortMode)
{
_grouped = grouped;
_sortHeader = sortHeader;
_sortMode = sortMode;

// if header or sort is null, use default
_sortGroupFunc = sortHeader?.SortGroup ?? DefaultGroupSort;
_sortMessageFunc = sortHeader?.SortMessages ?? DefaultMessageSort;
}

public void Sort()
Expand Down Expand Up @@ -45,13 +50,13 @@ public void Sort()

private int CompareGroupSortMode(Group x, Group y)
{
var sort = _sortHeader.SortGroup.Invoke(x, y);
var sort = _sortGroupFunc.Invoke(x, y);
return CheckSortMode(sort);
}

private int CompareDrawnSortMode(DrawnMessage x, DrawnMessage y)
{
var sort = _sortHeader.SortMessages.Invoke(x.Info, y.Info);
var sort = _sortMessageFunc.Invoke(x.Info, y.Info);
return CheckSortMode(sort);
}

Expand Down

0 comments on commit d233036

Please sign in to comment.