Invalid Memory Pointer Error with EntityQuery.SetChangedVersionFilter() & ToEntityArray()

The following System code creates an “Invalid memory pointer” error, followed by a job memory leak (shown below).

However, when line 18 is commented out (secondaryQuery.SetChangedVersionFilter…) the error does not occur.

I’m pretty stumped here. Any idea what I might be doing wrong in this example? Thank you sincerely.

Other notes:

  • I’m using Entities 0.3.0
  • This appears in both the editor and development builds.
  • I have 2,000 entities with “Explosion” components in this test, and 1 with a “ListenForExplosion” component.
public class ListenForExplosionSystem : JobComponentSystem
{
    private EntityQuery primaryQuery;
    private EntityQuery secondaryQuery;

    protected override void OnCreate()
    {
        primaryQuery = GetEntityQuery(
            ComponentType.ReadWrite<ListenForExplosion>()
            );

        primaryQuery.SetChangedVersionFilter(ComponentType.ReadWrite<ListenForExplosion>());

        secondaryQuery = GetEntityQuery(
            ComponentType.ReadOnly<Explosion>()
            );

        secondaryQuery.SetChangedVersionFilter(ComponentType.ReadOnly<Explosion>());

        RequireForUpdate(primaryQuery);
        RequireForUpdate(secondaryQuery);
    }

    protected override JobHandle OnUpdate(JobHandle inputDeps)
    {
        NativeArray<Entity> secondaryEntities = secondaryQueryQuery.ToEntityArray(Allocator.TempJob, out JobHandle buildsecondaryEntitiesJobHandle);

        JobHandle dependencies = JobHandle.CombineDependencies(inputDeps, buildsecondaryEntitiesJobHandle);

        return new TestJob
        {
            secondaryEntities = secondaryEntities
        }
        .Schedule(primaryQuery, dependencies);
    }

    [BurstCompile]
    private struct TestJob : IJobForEach_C<ListenForExplosion>
    {
        [ReadOnly]
        [DeallocateOnJobCompletion]
        public NativeArray<Entity> secondaryEntities;

        public void Execute(ref ListenForExplosion listenForExplosion)
        {
        }
    }
}

Error:

I’m not sure how to start debugging an error like this.

Does anyone know what culprits might throw this error?

This has been a tough one. Sincere thanks for any help.