Search Unity

Bug Attempt to access invalid address. when Allocate NativeBitArray

Discussion in 'Entity Component System' started by seojihyuk, Jul 19, 2021.

  1. seojihyuk

    seojihyuk

    Joined:
    Sep 19, 2014
    Posts:
    30
    hi guys,
    After few minutes running my game in Editor, I got sudden crash, when it allocate NativeBitArray.
    What i can't understand is the job which allocate NativeBitArray running perfectly fine for first few minutes.
    here is my error.log file and my crash.dmp file.
    I think the problem appears here
    ERROR: SymGetSymFromAddr64, GetLastError: 'Attempt to access invalid address.' (Address: 00007FF7259D3E57)
    0x00007FF7259D3E57 (Unity) (function-name not available)
    0x00000210294D96A0 (UnityEngine.CoreModule) Unity.Collections.LowLevel.Unsafe.UnsafeUtility.MemSet()
    .
     

    Attached Files:

  2. WAYNGames

    WAYNGames

    Joined:
    Mar 16, 2019
    Posts:
    992
    What allocator are you using ?
    I had the same kind of error message for my blob map when I realized I was using a temp allocator instead of a persistent one making the memory location invalid.
     
  3. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,296
    Most likely, something is being accessed / written / read incorrectly, which causes a memory corruption.
    (this can be both user code, and actual collections issue, since its wip)

    Make sure to enable safety checks via menu.

    Also, to debug native containers correctly, try running Unity with -debugallocator command argument.
    This should prevent Unity from crashing and you'd get an actual null reference for when accessing pointers incorrectly.

    (Note that you shouldn't always run with debugallocator, as its quite slow, just for debugging purposes)
     
    seojihyuk and WAYNGames like this.
  4. seojihyuk

    seojihyuk

    Joined:
    Sep 19, 2014
    Posts:
    30
    Thanks for reply.
    I was allocate it inside a job, so it was Temp.
    But why does this happen when it use Temp allocator? And I think that using persistent cost huge memory.
     
  5. WAYNGames

    WAYNGames

    Joined:
    Mar 16, 2019
    Posts:
    992
    Temp allocator should only be used inside a job and are disposed at the end of it. If you are trying to access the container after the job then you are accessing invalid memory. If you need to have memory across multiple job you should use the tempJob allocator. If you want to have memory across frame you should use persistent. But in that case I would suggest allocation on on create or on start running.

    Yes persistent allocator are more costly then temp or tempJob so you should avoid allocation every frame.
     
  6. seojihyuk

    seojihyuk

    Joined:
    Sep 19, 2014
    Posts:
    30
    I didn't touch safety check, so it was "on".
    Thank you for noticing me -debugallocator command argument. I haven't known about it. I will try this.

    I've tried -debugallocator command argument, but it's still crashing.
     
    Last edited: Jul 20, 2021
  7. seojihyuk

    seojihyuk

    Joined:
    Sep 19, 2014
    Posts:
    30
    I am disposing the NativeBitArray end of a job. plus the NativeBitArray is only used inside the job. So I don't think this is the case.

    I found that maybe it caused I'm using Collection 0.15.0. But I can't upgrade it cause of the dependency with other packages like Entites 0.17.0
     
    Last edited: Jul 20, 2021
  8. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,685
    You shouldn't dispose Temp allocated container at the end of a job.
     
  9. WAYNGames

    WAYNGames

    Joined:
    Mar 16, 2019
    Posts:
    992
    Sorry for the missunderstanding I did not mean you should dispose of them I just meant they are valid only within the job , as if they were automagicaly disposed at the end of it.
     
  10. seojihyuk

    seojihyuk

    Joined:
    Sep 19, 2014
    Posts:
    30