Unity Issue Tracker - Creating an empty ComponentTypeSet throws IndexOutOfRangeException
Fixed
ECSB-315
Creating an empty ComponentTypeSet throws IndexOutOfRangeException
Package: Entity Component System (ECS)
Fixed
1.0.X
Reported externally as [Internal link] , and discussed on Slack here
The following code throws an IndexOutOfRangeException:
namespace DefaultNamespace
{
publicclass Repro : MonoBehaviour
{
private void Awake()
{
var empty = new FixedList128Bytes<ComponentType>();
new ComponentTypeSet(empty);
}
}
}
The issue is that ComponentTypeSet.CheckForDuplicates() assumes there is at least one element in the set. This is a bug; an empty ComponentTypeSet is pointless, but technically valid.
We should fix the bug in CheckForDuplicates(), but also add some tests to existing methods that take ComponentTypeSet and make sure they work correctly if the type set is empty. In most cases, the correct behavior would be to early-out ASAP.
Prioritise and Follow this issue
Have a workaround or additional info about this issue?