fix/update exceptions

This commit is contained in:
DCFApixels 2025-04-04 14:40:53 +08:00
parent 48e364bfc9
commit 738e6a7080
5 changed files with 27 additions and 4 deletions

View File

@ -365,6 +365,7 @@ namespace DCFApixels.DragonECS
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public int NewEntity(int entityID) public int NewEntity(int entityID)
{ {
_entityDispenser.Upsize(entityID + 1);
#if DEBUG #if DEBUG
if (IsUsed(entityID)) { Throw.World_EntityIsAlreadyСontained(entityID); } if (IsUsed(entityID)) { Throw.World_EntityIsAlreadyСontained(entityID); }
#elif DRAGONECS_STABILITY_MODE #elif DRAGONECS_STABILITY_MODE
@ -1257,9 +1258,12 @@ namespace DCFApixels.DragonECS
{ {
EntitySlotInfo[] result = new EntitySlotInfo[_world.Count]; EntitySlotInfo[] result = new EntitySlotInfo[_world.Count];
int i = 0; int i = 0;
foreach (var e in _world.ToSpan()) using (_world.DisableAutoReleaseDelEntBuffer())
{ {
result[i++] = _world.GetEntitySlotInfoDebug(e); foreach (var e in _world.ToSpan())
{
result[i++] = _world.GetEntitySlotInfoDebug(e);
}
} }
return result; return result;
} }

View File

@ -91,10 +91,22 @@ namespace DCFApixels.DragonECS.Internal
Execute_Iternal(); Execute_Iternal();
#if DEBUG || DRAGONECS_DEEP_DEBUG #if DEBUG || DRAGONECS_DEEP_DEBUG
var newSpan = new EcsSpan(World.ID, _filteredAllEntities, _filteredAllEntitiesCount); var newSpan = new EcsSpan(World.ID, _filteredAllEntities, _filteredAllEntitiesCount);
foreach (var e in newSpan) using (EcsGroup group = EcsGroup.New(World))
{ {
if (World.IsMatchesMask(Mask, e) == false) foreach (var e in World.Entities)
{ {
if (World.IsMatchesMask(Mask, e))
{
group.Add(e);
}
}
if (group.SetEquals(newSpan) == false)
{
int[] array = new int[_filteredAllEntities.Length];
var count = _iterator.IterateTo(World.Entities, ref array);
EcsDebug.PrintError(newSpan.ToString() + "\r\n" + group.ToSpan().ToString());
Throw.DeepDebugException(); Throw.DeepDebugException();
} }
} }

View File

@ -95,6 +95,7 @@ namespace DCFApixels.DragonECS
{ {
ref int itemIndex = ref _mapping[entityID]; ref int itemIndex = ref _mapping[entityID];
#if DEBUG #if DEBUG
if (_source.IsUsed(entityID) == false) { Throw.Ent_ThrowIsNotAlive(_source, entityID); }
if (itemIndex > 0) { EcsPoolThrowHelper.ThrowAlreadyHasComponent<T>(entityID); } if (itemIndex > 0) { EcsPoolThrowHelper.ThrowAlreadyHasComponent<T>(entityID); }
if (_isLocked) { EcsPoolThrowHelper.ThrowPoolLocked(); } if (_isLocked) { EcsPoolThrowHelper.ThrowPoolLocked(); }
#elif DRAGONECS_STABILITY_MODE #elif DRAGONECS_STABILITY_MODE

View File

@ -104,6 +104,7 @@ namespace DCFApixels.DragonECS
public void Add(int entityID) public void Add(int entityID)
{ {
#if DEBUG #if DEBUG
if (_source.IsUsed(entityID) == false) { Throw.Ent_ThrowIsNotAlive(_source, entityID); }
if (Has(entityID)) { EcsPoolThrowHelper.ThrowAlreadyHasComponent<T>(entityID); } if (Has(entityID)) { EcsPoolThrowHelper.ThrowAlreadyHasComponent<T>(entityID); }
if (_isLocked) { EcsPoolThrowHelper.ThrowPoolLocked(); } if (_isLocked) { EcsPoolThrowHelper.ThrowPoolLocked(); }
#elif DRAGONECS_STABILITY_MODE #elif DRAGONECS_STABILITY_MODE

View File

@ -118,6 +118,11 @@ namespace DCFApixels.DragonECS.Internal
throw new InvalidOperationException($"The method {methodName} can only be executed before creating entities in the world."); throw new InvalidOperationException($"The method {methodName} can only be executed before creating entities in the world.");
} }
[MethodImpl(MethodImplOptions.NoInlining)]
internal static void Ent_ThrowIsNotAlive(EcsWorld world, int entityID)
{
Ent_ThrowIsNotAlive((world, entityID));
}
[MethodImpl(MethodImplOptions.NoInlining)] [MethodImpl(MethodImplOptions.NoInlining)]
internal static void Ent_ThrowIsNotAlive(entlong entity) internal static void Ent_ThrowIsNotAlive(entlong entity)
{ {