Search Unity

[Hybrid Setup] strange freeze after certain amount of objects in system

Discussion in 'Entity Component System' started by kobi666, Mar 31, 2021.

  1. kobi666

    kobi666

    Joined:
    Oct 13, 2014
    Posts:
    22
    I keep getting a freeze in my Jobs based collision system,
    I've found that it has to do with an iteration of two NativeMultiHashMap inside a monobehavior (not inside a job),
    which I have to iterate over outside of a job to pop events to the gameObjects.

    i've ruled out the function inside the iterations, even with no methods inside the freeze will occur.
    is it not safe to iterate outside of a job on these types of maps?

    for anyone who is curious, here is the code and the iteration that causes the freeze:

    iteration: https://pastebin.com/ea38ed5J
    entire system:
    https://pastebin.com/BR8RMhXu

    is there anyway I can debug this freeze?
     
  2. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,761
    Firstly, why would you do this?

    [NativeDisableParallelForRestriction] public NativeMultiHashMap<int, int> onEnterCollisions;

    Instead of using the AsParallel version?
    You could just be corrupting the hash map by doing parallel writes.
     
    kobi666 likes this.
  3. kobi666

    kobi666

    Joined:
    Oct 13, 2014
    Posts:
    22
    first of all
    NICE CATCH

    secondly,
    i'm not entirely sure why I used the attribute here,
    I think in some other case I had to use it for some bit array or something (still kinda new to this haha..)
    is the parallelWriter sufficient for this?
     
  4. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,761
    I didn't look through for a second error, so I don't know alone if this will fix it but I know corrupted native hash map can cause infinite loops.
     
    kobi666 likes this.
  5. kobi666

    kobi666

    Joined:
    Oct 13, 2014
    Posts:
    22
    OK,
    I have two findings:
    1. when I set the hashmaps to parallel writer,
    I have no crash, so first of all
    THANK YOU.

    2. if I don't use the attribute,
    the whole system doesn't work (IE the functionality doesn't happen).
    for now I kept the attribute but with setting them to pw it works now.

    now I have questions about this attribute...