From 121846eeaeaa202f22b7de104d9c861cb042524c Mon Sep 17 00:00:00 2001 From: Brant Martin Date: Mon, 3 Jun 2019 19:56:29 -0400 Subject: [PATCH] Fix rare crash in entity view sorting --- Torch.Server/ViewModels/Entities/EntityViewModel.cs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Torch.Server/ViewModels/Entities/EntityViewModel.cs b/Torch.Server/ViewModels/Entities/EntityViewModel.cs index 3a37720..0f52e40 100644 --- a/Torch.Server/ViewModels/Entities/EntityViewModel.cs +++ b/Torch.Server/ViewModels/Entities/EntityViewModel.cs @@ -85,9 +85,20 @@ namespace Torch.Server.ViewModels.Entities public virtual int CompareToSort(EntityViewModel other, EntityTreeViewModel.SortEnum sort) { + if (other == null) + return -1; + switch (sort) { case EntityTreeViewModel.SortEnum.Name: + if (Name == null) + { + if (other.Name == null) + return 0; + return 1; + } + if (other.Name == null) + return -1; return string.Compare(Name, other.Name, StringComparison.InvariantCultureIgnoreCase); case EntityTreeViewModel.SortEnum.Size: return Entity.WorldVolume.Radius.CompareTo(other.Entity.WorldVolume.Radius);