Search Unity

Resolved AddSharedComponentData build crash

Discussion in 'Entity Component System' started by szynal, Jul 6, 2020.

  1. szynal

    szynal

    Joined:
    Apr 16, 2014
    Posts:
    8
    Hello, I have huge problem with AddSharedComponentData method.
    It works fine in editor (component is added correctly), but after build (standalone windows) it's instant crash. I tried a lot of things like moving it to ECB, but with no success.

    If I use it when creating an entity and then use SetSharedComponentData, everything is ok, but in my case i need it to be added and removed. I know it's costly, but I I'm using it as filter for my system (GetAllUniqueSharedComponentData and SetSharedComponentFilter).

    Also I noticed that build is fine when building MONO not ILL2CPP.
    From erorr log know it is memory access violation.

    //edit
    Using entityManager.AddComponent also ends with crash.


    Code (CSharp):
    1.  
    2. nknown caused an Access Violation (0xc0000005)
    3.   in module Unknown at 0023:003aef94.
    4. Write to location 003AEF94 caused an access violation.
    5.  
    6. Context:
    7. EDI:    0x49000116  ESI: 0x10607ab8  EAX:   0x00000001
    8. EBX:    0x026db0c0  ECX: 0x00000004  EDX:   0x13688040
    9. EIP:    0x003aef94  EBP: 0x037f4820  SegCs: 0x00000023
    10. EFlags: 0x00210202  ESP: 0x003aef04  SegSs: 0x0000002b
    11.  
    12.  
    13. Bytes at CS:EIP:
    14. 02 00 00 00 01 00 00 00 16 01 00 49 00 00 00 00
    15.  

    Now some code, new project with only two scripts for tests:

    ISharedComponentData class
    Code (CSharp):
    1.  [System.Serializable]
    2.    public struct FoodTarget : ISharedComponentData, IEquatable<FoodTarget> {
    3.       public int foodType;
    4.  
    5.       public bool Equals(FoodTarget other) {
    6.          return foodType == other.foodType;
    7.       }
    8.  
    9.       public override int GetHashCode() {
    10.          return foodType.GetHashCode();
    11.       }
    12.    }
    13.  
    and my entity creator
    Code (CSharp):
    1.  void Spawn() {
    2.  
    3.          var entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
    4.          var entity = entityManager.CreateEntity(
    5.              typeof(Translation),
    6.              typeof(FoodTarget)
    7.         );
    8.          entityManager.SetSharedComponentData<FoodTarget>(entity, new FoodTarget { foodType = 0 });
    9.          Debug.Log("SO FAR SO GOOD");
    10.  
    11.          entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
    12.          entity = entityManager.CreateEntity(
    13.              typeof(Translation)
    14.         );
    15.  
    16.          entityManager.AddSharedComponentData<FoodTarget>(entity, new FoodTarget { foodType = 0 });
    17.       }
    I'm using
    -Unity 2019.3.13f1
    -DOTS v.0.8.0
    -Burst v.1.3.0
    -Entites v.0.11.1



    Maybe there is a better way without using SCD.
    Let's say I have a lot of points where agent can do stuff.
    For now each point have one or many characteristics, each with some unique data.
    Example:

    Code (CSharp):
    1.  
    2. public struct WaterSource {
    3.       int type;
    4.    }
    5.  
    6. public struct FoodVegetable {
    7.       int type;
    8.    }
    9.  
    10.    public struct FoodFruit {
    11.       int type;
    12.       float heightFromGround;
    13.    }
    14.  
    I have also a lot of agents. Each of agents have some statistics about which points he likes. When agent is hungry or thirsty he will choose one of he likes, and then he will look for the closest food with this parameters from all of points.
     
    Last edited: Jul 6, 2020
  2. szynal

    szynal

    Joined:
    Apr 16, 2014
    Posts:
    8
    Ok I'm stupid. It was standalone architecture option in BuildSettings. After changing from x86 to x86_x64 everything is ok.