ECS - breaking changes, again

New 20180722 version of ECS framework was released and time to break something again :)

New 20180722 version of ECS framework was released and time to break something again :)

Changes

  • Namespace will be changed from LeopotamGroup.Ecs to Leopotam.Ecs to respect main domain name.
  • All marshal-by-reference (classes except strings) fields of component will be checked to null value on removing component from entity.
    It will help to find possible memory leaks and fix it. If you are sure that field should not be nulled (any collection, for example) on component removing, [EcsIgnoreNullCheck] attribute can be used on this field to skip null-check

    • Example with memory leak

      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      class Data { }

      class Component2 {
      public Data Data;
      }
      ...
      Component2 c;
      var entity = world.CreateEntityWith<Component2>(out c);
      c.Data = new Data();
      world.RemoveComponent<Component2>(entity);

      You will get exception here:

      Memory leak for “Component2” component: “Data” field not nulled. If you are sure that it’s not - mark field with [EcsIgnoreNullCheck] attribute

    • Example without memory leak:

      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      class Data { }

      class Component2 {
      // Preinited field and we want to keep it not nulled.
      [EcsIgnoreNullCheck]
      public Data Data = new Data();
      }
      ...
      Component2 c;
      var entity = world.CreateEntityWith<Component2>(out c);
      c.Data = new Data();
      world.RemoveComponent<Component2>(entity);

      No exception here.