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)]
public int NewEntity(int entityID)
{
_entityDispenser.Upsize(entityID + 1);
#if DEBUG
if (IsUsed(entityID)) { Throw.World_EntityIsAlreadyСontained(entityID); }
#elif DRAGONECS_STABILITY_MODE
@ -1257,10 +1258,13 @@ namespace DCFApixels.DragonECS
{
EntitySlotInfo[] result = new EntitySlotInfo[_world.Count];
int i = 0;
using (_world.DisableAutoReleaseDelEntBuffer())
{
foreach (var e in _world.ToSpan())
{
result[i++] = _world.GetEntitySlotInfoDebug(e);
}
}
return result;
}
}

View File

@ -91,10 +91,22 @@ namespace DCFApixels.DragonECS.Internal
Execute_Iternal();
#if DEBUG || DRAGONECS_DEEP_DEBUG
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();
}
}

View File

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

View File

@ -104,6 +104,7 @@ namespace DCFApixels.DragonECS
public void Add(int entityID)
{
#if DEBUG
if (_source.IsUsed(entityID) == false) { Throw.Ent_ThrowIsNotAlive(_source, entityID); }
if (Has(entityID)) { EcsPoolThrowHelper.ThrowAlreadyHasComponent<T>(entityID); }
if (_isLocked) { EcsPoolThrowHelper.ThrowPoolLocked(); }
#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.");
}
[MethodImpl(MethodImplOptions.NoInlining)]
internal static void Ent_ThrowIsNotAlive(EcsWorld world, int entityID)
{
Ent_ThrowIsNotAlive((world, entityID));
}
[MethodImpl(MethodImplOptions.NoInlining)]
internal static void Ent_ThrowIsNotAlive(entlong entity)
{