I’m at a loss with an issue I’m having with the job system at the moment. I wrote a really nice couple of jobs but every now and even though I don’t have any JobTemp allocations I get the, “Internal: JobTempAlloc has allocations that are more than 4 frames old” warning.
However I’m not using any temp allocators. I only use 2:
- _revealerDataList which is declared as NativeList(Allocator.Persistent);
- I also use Texture2D.GetRawTextureData() which I thought would be the issue but I ruled it out after I changed to use a cached NativeArray(size, Allocator.Persistent) which didn’t help.
private void RunJob()
{
_jobHandle = new JobHandle();
// _revealerDataList = new NativeList<RevealerData>(Allocator.Persistent);
_revealerDataList.Clear();
foreach (var revealer in _revealers)
_revealerDataList.Add(new RevealerData(revealer.VisionRage, revealer.Position, revealer.Faction));
foreach (FactionData faction in _factions)
{
// Thought this might be issue, but I changed to a cached
// NativeArray<Color32>(size, Allocator.Persistent) which didn't help
var dataBuffer = faction.MapDataTexture.GetRawTextureData<Color32>();
var resetFactionJob = new ResetFactionJob
{
DataBuffer = dataBuffer,
CoverSpeed = _settings.CoverSpeed,
RevealOpacities = _settings.RevealOpacities,
RevealSpeed = _settings.RevealSpeed,
Time = Time.deltaTime
}.Schedule(dataBuffer.Length, 256);
var calculateVisionJob = new CalculateVisionJob
{
DataBuffer = dataBuffer,
Size = _settings.Size,
Revealer = _revealerDataList,
Offset = _fullOffset,
Scale = _settings.Scale,
Faction = faction.Faction
}.Schedule(_revealerDataList.Length, 64, resetFactionJob);
_jobHandle = JobHandle.CombineDependencies(_jobHandle, calculateVisionJob);
}
}
Now I think the issue is I’m trying to do this job over multiple frames as it’s costly. On my machine at the moment it takes on average takes 3 frames (when I’m running at 250fps) but occasionally takes 4-5 which is when the warnings popup.
void ITickable.Tick()
{
if (_settings.ForceUpdateEveryFrame || _jobHandle.IsCompleted)
{
_jobHandle.Complete();
// Do work on main thread
RunJob();
}
}
Are multi frame jobs just not supported? I intentionally avoided any temp allocators so I thought it’d be fine. I might just have to change back to using my own workers.