Search Unity

[Jobs][Lags] JobTempAlloc has allocations that are more than 4 frames old

Discussion in 'Data Oriented Technology Stack' started by dyox, Jan 18, 2018.

  1. Hans-D

    Hans-D

    Joined:
    Sep 24, 2013
    Posts:
    32
    I'm glad the 4 frames limit on jobs is being removed, it's something that severely limits the use cases of jobs where they would otherwise be ideal. It also ties your code to the framerate, causing all sorts of "different hardware" problems. Say your job takes 30ms to finish; no bug at 60FPS, hard to track bug at 144FPS.
     
  2. LightYarn

    LightYarn

    Joined:
    Nov 18, 2012
    Posts:
    55
    After some research I found another case when this problem occurs. In our case while using WebGL and the Particle System..... kind of like @castor76 problem but slightly different.

    I'm using Unity 2018.3.0f2

    Here are some details of the bug-report

    EDIT: It's even simpler. Just publish an empty scene with fresh out-of-the-box particle system and (de)activate the Trail-Module. If active it will trigger the error.
     
    Last edited: Jan 4, 2019
  3. Marco-Trivellato

    Marco-Trivellato

    Unity Technologies

    Joined:
    Jul 9, 2013
    Posts:
    1,652
    Would you please submit a bug report and post the bug number here?
     
  4. EssencyStudios

    EssencyStudios

    Joined:
    May 18, 2018
    Posts:
    6
    I'm having this issue and between the hundreds of "JobTempAlloc has allocations that are more than 4 frames old.."
    it says "To Debug, enable the define: TLA_DEBUG_STACK_LEAK in ThreadsafeLinearAllocator.cpp. This will output the callstacks of the leaked allocations"

    Anyone figure out how to do this? I cant seem to.
    Here are some of those crash reports:

    one dude: https://pastebin.com/CcjPkuHj
    other dude: https://pastebin.com/Ce0TL821
    another dude: https://pastebin.com/CiNyXn04
     
  5. LightYarn

    LightYarn

    Joined:
    Nov 18, 2012
    Posts:
    55
    Peter77 likes this.
  6. LightYarn

    LightYarn

    Joined:
    Nov 18, 2012
    Posts:
    55
    Not fixed in 2018.3.1f1

    Build Target: WebGL
    Empty Scene -> New Particle System -> Active trails will trigger the error in build
     
  7. PieterAlbers

    PieterAlbers

    Joined:
    Dec 2, 2014
    Posts:
    109
    That is some sad news - was happy to see a new build today but looking at the release notes I was kinda let down :(
     
  8. nsmith1024

    nsmith1024

    Joined:
    Mar 18, 2014
    Posts:
    586
    Has this been fixed? I have the problem now in 2018.3 where its saying this in the browser:

    Internal: JobTempAlloc has allocations that are more than 4 frames old - this is not allowed and likely a leak


    Then gives memory warnings

    UnityLoader.js:4 GC Warning: Repeated allocation of very large block (appr. size 7192576):
    printErr @ UnityLoader.js:4
    UnityLoader.js:4 May lead to memory leak and poor performance
    printErr @ UnityLoader.js:4
    UnityLoader.js:4 GC Warning: Repeated allocation of very large block (appr. size 3596288):
    printErr @ UnityLoader.js:4
    UnityLoader.js:4 May lead to memory leak and poor performance


    Then crashes because of out of memory
     
    LightYarn likes this.
  9. seldom

    seldom

    Joined:
    Dec 4, 2013
    Posts:
    108
    Same here. 2018.3.0f2 WebGL build spams the console with this error. Going back to 2018.2 makes it go away.
     
  10. JoleEh

    JoleEh

    Joined:
    Jan 29, 2017
    Posts:
    2
    Any estimate on when the 4 frame limit will be completed? Also would it be bad if i had jobs runnning for up to 15 seconds?
     
  11. LightYarn

    LightYarn

    Joined:
    Nov 18, 2012
    Posts:
    55
  12. LightYarn

    LightYarn

    Joined:
    Nov 18, 2012
    Posts:
    55

    Hey everyone:
    Version 2018.3.4 fixed the problem! *yaay* :)
     
  13. Zephus

    Zephus

    Joined:
    May 25, 2015
    Posts:
    175
    ...it did? I am on 2018.3.4 and I'm here because I'm getting spammed by the warning right now.
     
  14. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    4,575
    We didn't fix anything relating to it in 2018.3.4.

    In 19.1 next week beta build has a fix.
     
    FROS7 likes this.
  15. LightYarn

    LightYarn

    Joined:
    Nov 18, 2012
    Posts:
    55
    @Joachim_Ante

    Well, your own patchnotes say that you did :confused:

    Unbenannt.PNG

    And I tested it: New scene -> add particle system -> activate trails -> build as WebGL -> no problem

    Maybe we are talking about two different problems?
     
  16. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    4,575
    I am pretty sure that that is specifically not the issue the thread was originally about.

    What is being discussed here is C# jobs in user projects that take longer than 1 frame causing the warning. That should be fixed in 19.1, i am sure the particle system specific issue indeed was fixed in 18.3 as the release notes state.
     
  17. Gregorik

    Gregorik

    Joined:
    Dec 11, 2014
    Posts:
    331
    Getting the same error all the time in 2018.3.5 when using a particle system.
     
  18. LightYarn

    LightYarn

    Joined:
    Nov 18, 2012
    Posts:
    55
    Ah, I see! Thank you for clarifying that.
    In my case the bug was indeed only about the particle system, I did not recognized any other problems regarding the job system. Sorry for mixing things up.
     
  19. BillBucky

    BillBucky

    Joined:
    Nov 4, 2016
    Posts:
    7
    Hello,

    This is still happening to me as well on Unity 2018.2.14f1. Any fixes for this, I don't believe I am using any job system.

    Thanks!
     
  20. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    4,575
    19.1 fixes it.
     
  21. alligator76

    alligator76

    Joined:
    Nov 24, 2018
    Posts:
    6
    Hello
    I get this problem with 2018.3.6f1, only when i enable "deep profile" in the profiler.
    I get even more message /details with 2019.1.0b4 and 2019.2.0a6.

    That happens randomly depending on the state of the project (sometimes disappears, sometimes come back), and greatly disturbs the profiler (FPS greatly reduced).

    I am not using jobsystem (but i tried it briefly and cancelled).
     
    Sylmerria likes this.
  22. Aeolus_Codes

    Aeolus_Codes

    Joined:
    Mar 6, 2019
    Posts:
    2
    I am having the same problem, even with no self-made code. Help?
     
  23. Rich_A

    Rich_A

    Joined:
    Nov 22, 2016
    Posts:
    141
    Any chance of adding this fix to your only LTS release so far (2017.4)? Getting this bug when importing assets from the store.
     
  24. TomPo

    TomPo

    Joined:
    Nov 30, 2013
    Posts:
    65
    So in general...
    Example with documentation like a+b is..... no comment.
    Question then is: how to use jobs in real scenarios?
    We can't use references, we can't use static data (sic!)

    so let's imagine real world scenario - pathfinding being calculated on separate thread.

    we have a List<Tile> MapTiles - keeping information albout all tiles on the map
    now how to use job system to calculate pathinding and get the result
    (result should be Tile[] or int[] (tiles have own ID) or List<Tile>)

    we can't pass our MapTiles to the job, we can't refer to it, we can't make MapTIles static to be accessible from the job...

    So... for what purposes is this job system for?

    BTW - 2019.1.0f2 - problem still exists
     
    Last edited: Apr 19, 2019
  25. superpig

    superpig

    Quis aedificabit ipsos aedificatores? Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,154
    You must marshal your data into a blittable format. In the case of pathfinding, that might mean:

    • A TileData struct which contains the information about a tile in blittable format - its ID, maybe the terrain type identifier, etc
    • A NativeArray<TileData> that contains all your tiles - List<T> and T[] cannot be used in jobs but NativeArray<T> can be
    • A NativeList<int> for storing the result

    This allows the engine to guarantee of your data because it is able to reason about ownership of the native containers. More information in the manual.
     
  26. Stephen-Hodgson

    Stephen-Hodgson

    Joined:
    Jul 15, 2014
    Posts:
    23
    I've been seeing this warning a lot in clean projects lately.

    Mainly when switching scenes.

    Using 2019.1
     
    AutoRotate likes this.
  27. malkere

    malkere

    Joined:
    Dec 6, 2013
    Posts:
    1,042
    Wrymnn likes this.
  28. Kmsxkuse

    Kmsxkuse

    Joined:
    Feb 15, 2019
    Posts:
    12
    I'm getting the same problem randomly it seems.

    It goes away for roughly 20 min or so whenever I restart my editor but then comes back. I made no changes to any code between restart and warning appearing. I've also started and stopped my code (still unchanged) multiple times without the warning showing up. Very strange.

    upload_2019-4-26_0-15-53.png
     
  29. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    696
    I think I have managed to find the cause for this and it seems like it is a Unity bug.

    Background: I have an IJobParallelFor set up that is scheduled in one FixedUpdate() and finished in the next FixedUpdate(). The same frame it is finished it gets re-scheduled again and so the cycle continues. This job calculates some physics forces so this is needed. If I limit the framerate through V-Sync this message disappears which leads me to believe that there is some code checking if the job has been finished inside 4 Update() calls, not taking into account if the job was scheduled inside FixedUpdate() since only one FixedUpdate() passes between scheduling and finishing. It also means that the error is entirely framerate dependent.
    In the official Unity documentation it says that finishing the job just after it was scheduled is a bad design, and yet if we want to use job system with physics that would mean either finishing jobs inside Update() instead of FixedUpdate() which is not always practical. So please investigate this.
     
    AutoRotate and Wrymnn like this.
  30. Wrymnn

    Wrymnn

    Joined:
    Sep 24, 2014
    Posts:
    296
    This bug still appears on 2019.1.1f1, specifically with LocalNavMeshBuilder using AsyncOperation.
    When restarting unity and not running AsyncOperation from NavMeshBuilder.UpdateNavMeshDataAsync(), the leak is not there, everything is fine.

    It seems async does not stop, keeps running even after exiting play mode, it will eventually freeze editor for me
     
  31. NWHCoding

    NWHCoding

    Joined:
    Jul 12, 2012
    Posts:
    696
    I have managed to get rid of the error by getting rid of the struct I was allocating inside the job. Still - it is still a bit weird that we can not use structs if we want to run jobs in FixedUpdate().
     
  32. AutoRotate

    AutoRotate

    Joined:
    Aug 1, 2014
    Posts:
    119
    I am getting the same thing on 2019.1.6

    If I create and dispose the NativeArray on the same frame, I do NOT get this warning message. However, if I were to create, for example, in OnEnable() and dispose in OnDisable() I get this message. Does the create/dispose has to be done in the same frame?

    What am I doing wrong here?

    Here's the code:
    This gives me the message in question (4 frames old...)

    Code (CSharp):
    1. using Unity.Collections;
    2. using Unity.Jobs;
    3. using Unity.Mathematics;
    4. using UnityEngine;
    5. using UnityEngine.Jobs;
    6. using Unity.Burst;
    7. public class TestJob : MonoBehaviour
    8. {
    9.     public float3 velocity;
    10.     public float3[] velocities;
    11.     public float3[] positions;
    12.     public Transform testPrefab;
    13.     public Transform[] transforms;
    14.     public int count = 1000;
    15.     public bool update;
    16.     public bool useJobs;
    17.  
    18.     public SimpleMoveJob simpleMoveJob = new SimpleMoveJob();
    19.  
    20.     private void Awake()
    21.     {
    22.         Unity.Mathematics.Random random = new Unity.Mathematics.Random(1);
    23.         velocities = new float3[count];
    24.         positions = new float3[count];
    25.  
    26.         transforms = new Transform[count];
    27.         for (int i = 0; i < count; i++)
    28.         {
    29.             transforms[i] = Instantiate<Transform>(testPrefab);
    30.             float3 bulletPos = transform.position;
    31.             bulletPos += random.NextFloat3(10, 60f);
    32.             transforms[i].position = bulletPos;
    33.             velocities[i] = velocity;
    34.             positions[i] = transforms[i].position;
    35.         }
    36.  
    37.    
    38.     }
    39.  
    40.     private void OnEnable()
    41.     {
    42.         simpleMoveJob.posX = new NativeArray<float>(count, Allocator.TempJob);
    43.         simpleMoveJob.posY = new NativeArray<float>(count, Allocator.TempJob);
    44.         simpleMoveJob.posZ = new NativeArray<float>(count, Allocator.TempJob);
    45.  
    46.         simpleMoveJob.vX = new NativeArray<float>(count, Allocator.TempJob);
    47.         simpleMoveJob.vY = new NativeArray<float>(count, Allocator.TempJob);
    48.         simpleMoveJob.vZ = new NativeArray<float>(count, Allocator.TempJob);
    49.     }
    50.  
    51.     private void OnDisable()
    52.     {
    53.         simpleMoveJob.posX.Dispose();
    54.         simpleMoveJob.posY.Dispose();
    55.         simpleMoveJob.posZ.Dispose();
    56.  
    57.         simpleMoveJob.vX.Dispose();
    58.         simpleMoveJob.vY.Dispose();
    59.         simpleMoveJob.vZ.Dispose();
    60.     }
    61.  
    62.     private void Update()
    63.     {
    64.         if (update)
    65.         {
    66.             if (!useJobs)
    67.             {
    68.                 float deltaTime = Time.deltaTime;
    69.  
    70.                 for (int i = 0; i < count; i++)
    71.                 {
    72.                     positions[i] += velocities[i] * deltaTime;
    73.                     transforms[i].position = positions[i];
    74.                 }
    75.             }
    76.             else
    77.             {
    78.  
    79.                 for (int i = 0; i < count; i++)
    80.                 {
    81.                     simpleMoveJob.posX[i] = positions[i].x;
    82.                     simpleMoveJob.posY[i] = positions[i].y;
    83.                     simpleMoveJob.posZ[i] = positions[i].z;
    84.  
    85.                     simpleMoveJob.vX[i] = velocities[i].x;
    86.                     simpleMoveJob.vY[i] = velocities[i].y;
    87.                     simpleMoveJob.vZ[i] = velocities[i].z;
    88.                 }
    89.  
    90.                 simpleMoveJob.deltaTime = Time.deltaTime;
    91.  
    92.                 JobHandle simpleMoveJobHandle = simpleMoveJob.Schedule(count, 1000);
    93.                 simpleMoveJobHandle.Complete();
    94.  
    95.                 for (int i = 0; i < count; i++)
    96.                 {
    97.                     positions[i].x = simpleMoveJob.posX[i];
    98.                     positions[i].y = simpleMoveJob.posY[i];
    99.                     positions[i].z = simpleMoveJob.posZ[i];
    100.  
    101.                     transforms[i].position = positions[i];
    102.                 }
    103.             }
    104.         }
    105.     }
    106. }
    107.  
    108. [BurstCompile]
    109. public struct SimpleMoveJob : IJobParallelFor
    110. {
    111.     public NativeArray<float> posX, posY, posZ;
    112.  
    113.     [ReadOnly]
    114.     public NativeArray<float>vX, vY, vZ;
    115.     [ReadOnly]
    116.     public float deltaTime;
    117.  
    118.     public void Execute(int i)
    119.     {
    120.         posX[i] += vX[i] * deltaTime;
    121.         posY[i] += vY[i] * deltaTime;
    122.         posZ[i] += vZ[i] * deltaTime;
    123.     }
    124. }
    This one runs with no warnings:
    Code (CSharp):
    1. using Unity.Collections;
    2. using Unity.Jobs;
    3. using Unity.Mathematics;
    4. using UnityEngine;
    5. using UnityEngine.Jobs;
    6. using Unity.Burst;
    7. public class TestJob : MonoBehaviour
    8. {
    9.     public float3 velocity;
    10.     public float3[] velocities;
    11.     public float3[] positions;
    12.     public Transform testPrefab;
    13.     public Transform[] transforms;
    14.     public int count = 1000;
    15.     public bool update;
    16.     public bool useJobs;
    17.  
    18.     public SimpleMoveJob simpleMoveJob = new SimpleMoveJob();
    19.  
    20.     private void Awake()
    21.     {
    22.         Unity.Mathematics.Random random = new Unity.Mathematics.Random(1);
    23.         velocities = new float3[count];
    24.         positions = new float3[count];
    25.  
    26.         transforms = new Transform[count];
    27.         for (int i = 0; i < count; i++)
    28.         {
    29.             transforms[i] = Instantiate<Transform>(testPrefab);
    30.             float3 bulletPos = transform.position;
    31.             bulletPos += random.NextFloat3(10, 60f);
    32.             transforms[i].position = bulletPos;
    33.             velocities[i] = velocity;
    34.             positions[i] = transforms[i].position;
    35.         }
    36.  
    37.    
    38.     }
    39.  
    40.  
    41.     private void Update()
    42.     {
    43.         if (update)
    44.         {
    45.             if (!useJobs)
    46.             {
    47.                 float deltaTime = Time.deltaTime;
    48.  
    49.                 for (int i = 0; i < count; i++)
    50.                 {
    51.                     positions[i] += velocities[i] * deltaTime;
    52.                     transforms[i].position = positions[i];
    53.                 }
    54.             }
    55.             else
    56.             {
    57.  
    58.                 simpleMoveJob.posX = new NativeArray<float>(count, Allocator.TempJob);
    59.                 simpleMoveJob.posY = new NativeArray<float>(count, Allocator.TempJob);
    60.                 simpleMoveJob.posZ = new NativeArray<float>(count, Allocator.TempJob);
    61.  
    62.                 simpleMoveJob.vX = new NativeArray<float>(count, Allocator.TempJob);
    63.                 simpleMoveJob.vY = new NativeArray<float>(count, Allocator.TempJob);
    64.                 simpleMoveJob.vZ = new NativeArray<float>(count, Allocator.TempJob);
    65.  
    66.                 for (int i = 0; i < count; i++)
    67.                 {
    68.                     simpleMoveJob.posX[i] = positions[i].x;
    69.                     simpleMoveJob.posY[i] = positions[i].y;
    70.                     simpleMoveJob.posZ[i] = positions[i].z;
    71.  
    72.                     simpleMoveJob.vX[i] = velocities[i].x;
    73.                     simpleMoveJob.vY[i] = velocities[i].y;
    74.                     simpleMoveJob.vZ[i] = velocities[i].z;
    75.                 }
    76.  
    77.                 simpleMoveJob.deltaTime = Time.deltaTime;
    78.  
    79.                 JobHandle simpleMoveJobHandle = simpleMoveJob.Schedule(count, 1000);
    80.                 simpleMoveJobHandle.Complete();
    81.  
    82.                 for (int i = 0; i < count; i++)
    83.                 {
    84.                     positions[i].x = simpleMoveJob.posX[i];
    85.                     positions[i].y = simpleMoveJob.posY[i];
    86.                     positions[i].z = simpleMoveJob.posZ[i];
    87.  
    88.                     transforms[i].position = positions[i];
    89.                 }
    90.  
    91.                 simpleMoveJob.posX.Dispose();
    92.                 simpleMoveJob.posY.Dispose();
    93.                 simpleMoveJob.posZ.Dispose();
    94.  
    95.                 simpleMoveJob.vX.Dispose();
    96.                 simpleMoveJob.vY.Dispose();
    97.                 simpleMoveJob.vZ.Dispose();
    98.             }
    99.         }
    100.     }
    101. }
    102.  
    103. [BurstCompile]
    104. public struct SimpleMoveJob : IJobParallelFor
    105. {
    106.     public NativeArray<float> posX, posY, posZ;
    107.  
    108.     [ReadOnly]
    109.     public NativeArray<float>vX, vY, vZ;
    110.     [ReadOnly]
    111.     public float deltaTime;
    112.  
    113.     public void Execute(int i)
    114.     {
    115.         posX[i] += vX[i] * deltaTime;
    116.         posY[i] += vY[i] * deltaTime;
    117.         posZ[i] += vZ[i] * deltaTime;
    118.     }
    119. }
     

    Attached Files:

  33. AutoRotate

    AutoRotate

    Joined:
    Aug 1, 2014
    Posts:
    119
    Never mind, I think I figured it out.

    If I set these as Allocator.Persistent no warnings.

    Code (CSharp):
    1.     private void OnEnable()
    2.     {
    3.         posX = new NativeArray<float>(count, Allocator.Persistent);
    4.         posY = new NativeArray<float>(count, Allocator.Persistent);
    5.         posZ = new NativeArray<float>(count, Allocator.Persistent);
    6.  
    7.         vX = new NativeArray<float>(count, Allocator.Persistent);
    8.         vY = new NativeArray<float>(count, Allocator.Persistent);
    9.         vZ = new NativeArray<float>(count, Allocator.Persistent);
    10.     }
    Can someone please explain the difference between Allocator.Temp and Allocator.TempJob? How should the life cycle of each be? are they both intended to work during one frame?

    https://docs.unity3d.com/ScriptReference/Unity.Collections.Allocator.html
    Doc. doesn't really explain much.
     
  34. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    1,280
    Temp is for new containers allocated inside job
     
    AutoRotate likes this.
  35. mattKsp

    mattKsp

    Joined:
    Jul 15, 2014
    Posts:
    7
    I am getting this error on 2019.2.0b3 and 2019.3.0a5, using Native Arrays and Native Hash Maps.
     
  36. Nyanpas

    Nyanpas

    Joined:
    Dec 29, 2016
    Posts:
    38
    I am on Unity 2019.1.5f1 and am suddenly getting this error now. It was fine a few days ago, but now all of a sudden it starts every time I click play. I cannot find the source of the issue as it was as stated fine a few days ago, and I am currently not using ECS or Jobs in my project, except for in the ECS and Jobs example files from the GitHubs.

    Is there some sort of update feature I am unaware of for this?
     
  37. AutoRotate

    AutoRotate

    Joined:
    Aug 1, 2014
    Posts:
    119
    Not sure if this is related but, I believe some of the dependencies (forget exactly which) were updated. Might want to check the package manager. I'd back things up though since these updates may create other errors etc..