Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect _size values for deferred spawn/despawn 0.9.0-beta.0 #158

Open
TheyCallMeRyan opened this issue Jan 21, 2025 · 2 comments
Open
Labels
bug Something isn't working

Comments

@TheyCallMeRyan
Copy link

Description

Image
Can get negative sizes when despawning and then immediately spawning within the same commit commands.

This is caused by the spawnAt functionality:

	if not willBeDeleted then
		self._size += 1
	end

executeDespawn will still occur even if a later spawnAt command it executed, and executeDespawn will always decrement the _size by 1, even if markedForDeletion is no longer set.

Steps to reproduce

world:commitCommands()
world:spawnAt(1)
world:commitCommands()
world:despawn(1)
world:spawnAt(1)
world:commitCommands()
world:despawn(1)
world:spawnAt(1)
world:commitCommands()
world:despawn(1)
world:spawnAt(1)
world:commitCommands()
print(world:size())

Expected behavior

Keep the appropriate _size value.

@TheyCallMeRyan TheyCallMeRyan added the bug Something isn't working label Jan 21, 2025
@TheyCallMeRyan
Copy link
Author

Two possible fixes:

  1. Remove the if not willBeDeleted then - this will make size inaccurate until the next commitCommands
  2. Add in executeDespawn a check that it's still markedForDeletion before decrementing the size

@TheyCallMeRyan
Copy link
Author

I'm not sure what people use _size for, I just noticed this while trying to find the indexInArchetype bug yesterday.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant