ArgumentException: Key: -1 is not present in the NativeParallelHashMap

Happens in some cases when i had some problems initializing correct. Happens after i load my savegame, due to a bug in my loading system, due a renamed EntityManager method.

It looks like the RenderFilterSettings was not added to some of the entities.

Is it possible to log a warning or ignore broken entities instead of throwing these exceptions? I guess with Burst the complete game would crash away if it stays like that.

ArgumentException: Key: -1 is not present in the NativeParallelHashMap.
Unity.Collections.NativeParallelHashMap`2[TKey,TValue].ThrowKeyNotPresent (TKey key) (at ./Library/PackageCache/com.unity.collections@2.1.0-pre.18/Unity.Collections/NativeParallelHashMap.cs:800)
Unity.Collections.NativeParallelHashMap`2[TKey,TValue].get_Item (TKey key) (at ./Library/PackageCache/com.unity.collections@2.1.0-pre.18/Unity.Collections/NativeParallelHashMap.cs:268)
Unity.Rendering.EmitDrawCommandsJob.Execute (System.Int32 index) (at ./Packages/com.unity.entities.graphics@1.0.0-pre.65.joe/Unity.Entities.Graphics/DrawCommandGeneration.cs:1042)
Unity.Jobs.IJobParallelForDeferExtensions+JobParallelForDeferProducer`1[T].Execute (T& jobData, System.IntPtr additionalPtr, System.IntPtr bufferRangePatchData, Unity.Jobs.LowLevel.Unsafe.JobRanges& ranges, System.Int32 jobIndex) (at ./Library/PackageCache/com.unity.collections@2.1.0-pre.18/Unity.Collections/Jobs/IJobParallelForDefer.cs:64)

Mhmm, a key equal to -1 is definitely unexpected here. I think it means the type wasn't found in the ECS archetype of the chunk, which shouldn't happen. Since you mentioned initialization issues then it might be related. It would be great to have a ticket with a repro case here so that we can find where the issue stems from and fix things accordingly.

In the meantime it might help to add a simple check to early out from EmitDrawCommandsJob.Execute if the filterIndex is -1.

Yes, -1 was not found, the entity didn't have the RenderFilterSettings. Usually it didn't happen, correct. Just mentioned that its maybe better to add it to the query, to ignore these entities or at least log a warning if that happened.

I guess to reproduce you can try to just remove the RenderFilterSettings from an entity after preparing it to be rendered.

Here my update that fixes that: (i guess a check for -1 would be also work)
DrawCommandGenerator.cs -> EmitDrawCommandsJob

public void Execute(int index) {
            var visibilityItem = VisibilityItems.ElementAt(index);

            var chunk = visibilityItem.Chunk;
            var chunkVisibility = visibilityItem.Visibility;

            int filterIndex = chunk.GetSharedComponentIndex(RenderFilterSettings);
            if (!FilterSettings.ContainsKey(filterIndex)) {
                Debug.LogError($"No RenderFilterSettings were found ({filterIndex}). Ignoring Rendering for these entities.");
                return;
            }
            BatchFilterSettings filterSettings = FilterSettings[filterIndex];