Skip to content

Commit

Permalink
UI - Avoid crashing because of outdated plugins when picking data mod…
Browse files Browse the repository at this point in the history
…el paths
  • Loading branch information
RobertBeekman committed Mar 14, 2024
1 parent ef8359d commit 90ddc30
Showing 1 changed file with 23 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using Artemis.Core;
using Artemis.Core.Modules;
using Artemis.UI.Shared.Services;
using Avalonia;
using ReactiveUI;

namespace Artemis.UI.Shared.DataModelVisualization.Shared;
Expand Down Expand Up @@ -282,12 +281,8 @@ internal void PopulateProperties(IDataModelUIService dataModelUIService, DataMod
foreach (PropertyInfo propertyInfo in modelType.GetProperties(BindingFlags.Public | BindingFlags.Instance).OrderBy(t => t.MetadataToken))
{
string childPath = AppendToPath(propertyInfo.Name);
if (Children.Any(c => c.Path != null && c.Path.Equals(childPath)))
continue;
if (propertyInfo.GetCustomAttribute<DataModelIgnoreAttribute>() != null)
continue;
MethodInfo? getMethod = propertyInfo.GetGetMethod();
if (getMethod == null || getMethod.GetParameters().Any())

if (!ShouldIncludePath(childPath, propertyInfo))
continue;

DataModelVisualizationViewModel? child = CreateChild(dataModelUIService, childPath, GetChildDepth());
Expand Down Expand Up @@ -331,6 +326,27 @@ internal void PopulateProperties(IDataModelUIService dataModelUIService, DataMod
Children.Remove(dataModelVisualizationViewModel);
}

private bool ShouldIncludePath(string childPath, PropertyInfo propertyInfo)
{
// Outdated plugins can cause unpredictable exceptions when resolving types
try
{
if (Children.Any(c => c.Path != null && c.Path.Equals(childPath)))
return false;
if (propertyInfo.GetCustomAttribute<DataModelIgnoreAttribute>() != null)
return false;
MethodInfo? getMethod = propertyInfo.GetGetMethod();
if (getMethod == null || getMethod.GetParameters().Any())
return false;

return true;
}
catch (Exception)
{
return false;
}
}

private DataModelVisualizationViewModel? CreateChild(IDataModelUIService dataModelUIService, string path, int depth)
{
if (DataModel == null)
Expand Down

0 comments on commit 90ddc30

Please sign in to comment.