Skip to content

Conversation

JoNax97
Copy link

@JoNax97 JoNax97 commented Aug 12, 2025

The component registry was incrementing the size twice, causing the 0th element to be null. Now it only increments after assigning.

Also, the version on the csproj was mismatched, causing local builds to generate an incorrect nupkg version.

@genaray
Copy link
Owner

genaray commented Sep 2, 2025

Thanks!
The Tests fail, could you Look into this?

@JoNax97
Copy link
Author

JoNax97 commented Sep 5, 2025

Ok, looks like fixing the component registry uncovered some more issues and patches. I will push another round of fixes now and comment on them

// Calculate new array size that fits the passed index
var amountOfMultiplications = (int)Math.Ceiling(Math.Log((index+1) / (float)Capacity, 2.0f));
var newLength = (int)Math.Pow(2, amountOfMultiplications) * Capacity;
newLength = Math.Max(Capacity, newLength+1);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This logic was failing when trying to grow from capacity = 0 to anything different than capacity = 1.

Because capacity was being used as a denominator it was causing a division by 0 and amountOfMultiplications was undeflowing. Then the multiplication by Capacity neutralized that and made it 0 again, and newLength+1 made it work only for the case where the desired capacity was 1.

var amountOfMultiplications = (int)Math.Ceiling(Math.Log((index+1) / (float)Capacity, 2.0f));
var newLength = (int)Math.Pow(2, amountOfMultiplications) * Capacity;
newLength = Math.Max(Capacity, newLength+1);
var newCapacity = MathExtensions.NextPowerOfTwo(index + 1);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new code uses bit shifting to find the next pow2 size without any floating point arithmetic.

private Archetype GetOrCreateArchetypeByAddEdge(in ComponentType type, Archetype oldArchetype)
{
Archetype archetype;
var edgeIndex = type.Id - 1;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These -1 were compensating for the off-by-one error on ComponentRegistry.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants