diff --git a/Svelto.ECS/DataStructures/TypeSafeDictionary.cs b/Svelto.ECS/DataStructures/TypeSafeDictionary.cs index d3ad973..e892a2e 100644 --- a/Svelto.ECS/DataStructures/TypeSafeDictionary.cs +++ b/Svelto.ECS/DataStructures/TypeSafeDictionary.cs @@ -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).AddInternal(ref entity); + { + try + { + (entityViewsEngines[i] as IHandleEntityStructEngine).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 entityViewsEngines; if (entityViewEnginesDB.TryGetValue(_type, out entityViewsEngines)) for (int i = 0; i < entityViewsEngines.Count; i++) - (entityViewsEngines[i] as IHandleEntityStructEngine).RemoveInternal(ref entity); + try + { + (entityViewsEngines[i] as IHandleEntityStructEngine).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> entityViewEnginesDB) diff --git a/Svelto.ECS/ECSException.cs b/Svelto.ECS/ECSException.cs index 591d1fd..712edd6 100644 --- a/Svelto.ECS/ECSException.cs +++ b/Svelto.ECS/ECSException.cs @@ -6,5 +6,8 @@ namespace Svelto.ECS.Internal { public ECSException(string message):base(message) {} + + public ECSException(string message, Exception innerE):base(message, innerE) + {} } } \ No newline at end of file diff --git a/Svelto.ECS/EnginesRoot.Engines.cs b/Svelto.ECS/EnginesRoot.Engines.cs index e455f6a..8a3991f 100644 --- a/Svelto.ECS/EnginesRoot.Engines.cs +++ b/Svelto.ECS/EnginesRoot.Engines.cs @@ -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 } } diff --git a/Svelto.ECS/EnginesRoot.Entities.cs b/Svelto.ECS/EnginesRoot.Entities.cs index ec707e4..9cfb763 100644 --- a/Svelto.ECS/EnginesRoot.Entities.cs +++ b/Svelto.ECS/EnginesRoot.Entities.cs @@ -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()); diff --git a/Svelto.ECS/EnginesRoot.Submission.cs b/Svelto.ECS/EnginesRoot.Submission.cs index 66f8fd9..d1f0989 100644 --- a/Svelto.ECS/EnginesRoot.Submission.cs +++ b/Svelto.ECS/EnginesRoot.Submission.cs @@ -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 } }