Release Type: Official Release
Version: All versions up to 4.3.0.2507
Platform(s): Windows (Game Studio)
Describe the bug
Adding a [Display] attribute on a custom asset and not setting the Name property can cause the editor to crash when viewing any asset that references this custom asset.
To Reproduce
Steps to reproduce the behavior:
- Create custom asset
MyAsset (along with all necessary files) with [Display] attribute without setting Name property.
- Create a custom component with
MyAsset property.
- Create
MyAsset, add custom component to a scene then reference MyAsset.
- Restart editor, try open the scene -> crash.
Expected behavior
Not crash.
Additional context
Caused by the code:
|
private void UpdateStats(IEnumerable<AssetViewModel> assets) |
|
{ |
|
var typeCounters = assets.GroupBy(a => a.TypeDisplayName).Select(grp => |
|
{ |
|
var count = grp.Count(); |
|
return $"{count} {Pluralize(grp.Key, count)}"; |
|
}); |
|
TypeCountersAsText = string.Join(", ", typeCounters); |
|
} |
|
|
|
private static string Pluralize(string word, int count) |
|
{ |
|
if (count == 1) |
|
return word; |
|
// exceptions |
|
if (word.ToUpperInvariant() == "ENTITY") |
|
{ |
|
return $"{word.Substring(0, word.Length - 1)}es"; |
|
} |
|
return $"{word}s"; |
|
} |
|
public override string TypeDisplayName { get { var desc = DisplayAttribute.GetDisplay(AssetType); return desc != null ? desc.Name : AssetType.Name; } } |
TypeDisplayName will be null, which is used as the 'GroupBy' key then word.ToUpperInvariant() throws a null exception in the Pluralize method.
Workaround
Set Name property on [Display] attribute on custom asset, or remove [Display] attribute. The .sdtpl file is where the actual display metadata should be set.
Release Type: Official Release
Version: All versions up to 4.3.0.2507
Platform(s): Windows (Game Studio)
Describe the bug
Adding a
[Display]attribute on a custom asset and not setting theNameproperty can cause the editor to crash when viewing any asset that references this custom asset.To Reproduce
Steps to reproduce the behavior:
MyAsset(along with all necessary files) with[Display]attribute without setting Name property.MyAssetproperty.MyAsset, add custom component to a scene then referenceMyAsset.Expected behavior
Not crash.
Additional context
Caused by the code:
stride/sources/editor/Stride.Core.Assets.Editor/ViewModel/ReferencesViewModel.cs
Lines 102 to 122 in fc65d04
stride/sources/editor/Stride.Core.Assets.Editor/ViewModel/AssetViewModel.cs
Line 195 in fc65d04
TypeDisplayNamewill be null, which is used as the 'GroupBy' key thenword.ToUpperInvariant()throws a null exception in thePluralizemethod.Workaround
Set Name property on
[Display]attribute on custom asset, or remove[Display]attribute. The.sdtplfile is where the actual display metadata should be set.