@@ -88,7 +88,17 @@ namespace Svelto.ECS.Internal | |||
//get all the engines linked to TValue | |||
if (entityViewEnginesDB.TryGetValue(_type, out entityViewsEngines)) | |||
for (int i = 0; i < entityViewsEngines.Count; i++) | |||
(entityViewsEngines[i] as IHandleEntityStructEngine<TValue>).AddInternal(ref entity); | |||
{ | |||
try | |||
{ | |||
(entityViewsEngines[i] as IHandleEntityStructEngine<TValue>).AddInternal(ref entity); | |||
} | |||
catch (Exception e) | |||
{ | |||
throw new ECSException("Code crashed inside Add callback ". | |||
FastConcat(typeof(TValue)).FastConcat("id ").FastConcat(entity.ID.entityID), e); | |||
} | |||
} | |||
} | |||
public void MoveEntityFromDictionaryAndEngines(EGID fromEntityGid, EGID toEntityID, ITypeSafeDictionary toGroup, | |||
@@ -122,7 +132,15 @@ namespace Svelto.ECS.Internal | |||
FasterList<IHandleEntityViewEngineAbstracted> entityViewsEngines; | |||
if (entityViewEnginesDB.TryGetValue(_type, out entityViewsEngines)) | |||
for (int i = 0; i < entityViewsEngines.Count; i++) | |||
(entityViewsEngines[i] as IHandleEntityStructEngine<TValue>).RemoveInternal(ref entity); | |||
try | |||
{ | |||
(entityViewsEngines[i] as IHandleEntityStructEngine<TValue>).RemoveInternal(ref entity); | |||
} | |||
catch (Exception e) | |||
{ | |||
throw new ECSException("Code crashed inside Remove callback ". | |||
FastConcat(typeof(TValue)).FastConcat("id ").FastConcat(entity.ID.entityID), e); | |||
} | |||
} | |||
public void RemoveEntitiesFromEngines(Dictionary<Type, FasterList<IHandleEntityViewEngineAbstracted>> entityViewEnginesDB) | |||
@@ -6,5 +6,8 @@ namespace Svelto.ECS.Internal | |||
{ | |||
public ECSException(string message):base(message) | |||
{} | |||
public ECSException(string message, Exception innerE):base(message, innerE) | |||
{} | |||
} | |||
} |
@@ -61,24 +61,36 @@ namespace Svelto.ECS | |||
#if ENGINE_PROFILER_ENABLED && UNITY_EDITOR | |||
Profiler.EngineProfiler.AddEngine(engine); | |||
#endif | |||
var viewEngine = engine as IHandleEntityViewEngineAbstracted; | |||
if (viewEngine != null) | |||
CheckEntityViewsEngine(viewEngine); | |||
DBC.ECS.Check.Assert(_enginesSet.Contains(engine) == false, "The same engine has been added more than once " | |||
DBC.ECS.Check.Require(_enginesSet.Contains(engine) == false, | |||
"The same engine has been added more than once " | |||
.FastConcat(engine.ToString())); | |||
_enginesSet.Add(engine); | |||
if (engine is IDisposable) | |||
_disposableEngines.Add(engine as IDisposable); | |||
var queryableEntityViewEngine = engine as IQueryingEntitiesEngine; | |||
if (queryableEntityViewEngine != null) | |||
try | |||
{ | |||
var viewEngine = engine as IHandleEntityViewEngineAbstracted; | |||
if (viewEngine != null) | |||
CheckEntityViewsEngine(viewEngine); | |||
_enginesSet.Add(engine); | |||
if (engine is IDisposable) | |||
_disposableEngines.Add(engine as IDisposable); | |||
var queryableEntityViewEngine = engine as IQueryingEntitiesEngine; | |||
if (queryableEntityViewEngine != null) | |||
{ | |||
queryableEntityViewEngine.entitiesDB = _entitiesDB; | |||
queryableEntityViewEngine.Ready(); | |||
} | |||
} | |||
catch (Exception e) | |||
{ | |||
queryableEntityViewEngine.entitiesDB = _entitiesDB; | |||
queryableEntityViewEngine.Ready(); | |||
#if !DEBUG | |||
throw new ECSException("Code crashed while adding engine ".FastConcat(engine.GetType()), e); | |||
#else | |||
Utilities.Console.LogException("Code crashed while adding engine ".FastConcat(engine.GetType()), e); | |||
#endif | |||
} | |||
} | |||
@@ -148,11 +148,20 @@ namespace Svelto.ECS | |||
//otherwise it's a normal static entity descriptor | |||
else | |||
{ | |||
#if DEBUG && !PROFILER | |||
if (correctEntityDescriptorFound == false) | |||
#if RELAXED_ECS | |||
Utilities.Console.LogError(INVALID_DYNAMIC_DESCRIPTOR_ERROR.FastConcat(" ID ").FastConcat(entityGID.entityID) | |||
.FastConcat(" group ID ").FastConcat(entityGID.groupID).FastConcat( | |||
" descriptor found: ", entityInfoView.type.Name, " descriptor Excepted ", | |||
originalDescriptorType.Name)); | |||
#else | |||
throw new ECSException(INVALID_DYNAMIC_DESCRIPTOR_ERROR.FastConcat(" ID ").FastConcat(entityGID.entityID) | |||
.FastConcat(" group ID ").FastConcat(entityGID.groupID).FastConcat( | |||
" descriptor found: ", entityInfoView.type.Name, " descriptor Excepted ", | |||
originalDescriptorType.Name); | |||
#endif | |||
#endif | |||
for (var i = 0; i < entityBuilders.Length; i++) | |||
MoveEntityView(entityGID, toEntityGID, toGroup, fromGroup, entityBuilders[i].GetEntityType()); | |||
@@ -68,10 +68,10 @@ namespace Svelto.ECS | |||
.FastConcat(entitiesOperations[i].fromGroupID) | |||
.FastConcat(" to groupid: ") | |||
.FastConcat(entitiesOperations[i].toGroupID); | |||
Console.LogError(e.Message.FastConcat(" ", str, " ", entitiesOperations[i].trace)); | |||
#if !RELAXED_ECS | |||
throw; | |||
#if RELAXED_ECS | |||
Console.LogException(str.FastConcat(" ").FastConcat(entitiesOperations[i].trace), e); | |||
#else | |||
throw new ECSException(str.FastConcat(" ").FastConcat(entitiesOperations[i].trace), e); | |||
#endif | |||
#else | |||
var str = "Entity Operation is ".FastConcat(entitiesOperations[i].type.ToString()) | |||
@@ -84,7 +84,7 @@ namespace Svelto.ECS | |||
.FastConcat(" to groupid: ") | |||
.FastConcat(entitiesOperations[i].toGroupID); | |||
Console.LogError(e.Message.FastConcat(" ", str)); | |||
Console.LogException(str, e); | |||
#endif | |||
} | |||
} | |||