sschmid / Entitas

Entitas is a super fast Entity Component System (ECS) Framework specifically made for C# and Unity
MIT License
7.16k stars 1.11k forks source link

Visual debugging Unity crash when calling context.CreateEntity() inside INotificationReceiver #884

Open c0ffeeartc opened 5 years ago

c0ffeeartc commented 5 years ago

Hello, using following code in Unity2019.1.0b9 with Timeline and markers crashes Unity.

public class MarkerReceiver : MonoBehaviour, INotificationReceiver
{
    public void OnNotify( Playable origin, INotification note, object context )
    {
        Contexts.sharedInstance.game.CreateEntity();
    }
}
NullReferenceException
  at (wrapper managed-to-native) UnityEngine.Object:set_hideFlags (UnityEngine.HideFlags)
  at Entitas.VisualDebugging.Unity.EntityBehaviour.Init (IContext context, IEntity entity, System.Collections.Generic.Stack`1 entityBehaviourPool) [0x00000] in <filename unknown>:0 
  at Entitas.VisualDebugging.Unity.ContextObserver.onEntityCreated (IContext context, IEntity entity) [0x00000] in <filename unknown>:0 
  at (wrapper delegate-invoke) Entitas.ContextEntityChanged:invoke_void__this___IContext_IEntity (Entitas.IContext,Entitas.IEntity)
  at Entitas.Context`1[TEntity].CreateEntity () [0x00000] in <filename unknown>:0 

Using Coroutines and delaying context.createEntity() till next frame removes crash. Is this a bug or can someone please explain what's wrong with this code?