fix crash in Debug_GetEntities

main
cosmonaut 2024-02-27 15:47:26 -08:00
parent 079765d009
commit 3b460cf326
1 changed files with 9 additions and 3 deletions

View File

@ -1,8 +1,12 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using MoonTools.ECS.Collections; using MoonTools.ECS.Collections;
#if DEBUG
using System.Reflection;
#endif
namespace MoonTools.ECS; namespace MoonTools.ECS;
public class World : IDisposable public class World : IDisposable
@ -396,8 +400,10 @@ public class World : IDisposable
public IEnumerable<Entity> Debug_GetEntities(Type componentType) public IEnumerable<Entity> Debug_GetEntities(Type componentType)
{ {
var storage = ComponentIndex[ComponentTypeToId[componentType]]; var baseGetComponentStorageMethod = typeof(World).GetMethod(nameof(World.GetComponentStorage), BindingFlags.NonPublic | BindingFlags.Instance)!;
return storage.Debug_GetEntities(); var genericGetComponentStorageMethod = baseGetComponentStorageMethod.MakeGenericMethod(componentType);
var storage = genericGetComponentStorageMethod.Invoke(this, null) as ComponentStorage;
return storage!.Debug_GetEntities();
} }
public IEnumerable<Type> Debug_SearchComponentType(string typeString) public IEnumerable<Type> Debug_SearchComponentType(string typeString)