I’m trying to implement pausing in my game, I do so by doing
foreach (var system in World.Active.Systems)
system.Enabled = false;
It works great but I started getting “Internal: JobTempAlloc has allocations that are more than 4 frames old - this is not allowed and likely a leak” spam in my console when pausing. After a lot of debugging I figured out it’s because I was disabling a system in the same frame which was scheduling a job where an EntityCommandBuffer.Concurrent was trying to remove a component. Here’s a pared down example:
public class RemoveComponentSystemTest : JobComponentSystem
{
BeginInitializationEntityCommandBufferSystem initBufferSystem_;
[RequireComponentTag(typeof(Test))]
struct RemoveComponentSystemJob : IJobForEachWithEntity<Translation>
{
public EntityCommandBuffer.Concurrent commandBuffer;
public void Execute(Entity entity, int index, ref Translation c0)
{
commandBuffer.RemoveComponent<Test>(index, entity);
}
}
protected override void OnCreate()
{
initBufferSystem_ = World.GetOrCreateSystem<BeginInitializationEntityCommandBufferSystem>();
}
protected override JobHandle OnUpdate(JobHandle inputDependencies)
{
var job = inputDependencies;
if(Input.GetButtonDown("Jump") )
{
job = new RemoveComponentSystemJob
{
commandBuffer = initBufferSystem_.CreateCommandBuffer().ToConcurrent(),
}.Schedule(this, job);
foreach (var system in World.Systems)
system.Enabled = false;
}
return job;
}
}
Is this a bug or just bad design on my part? (Or possibly both)