matter icon indicating copy to clipboard operation
matter copied to clipboard

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

Open TheyCallMeRyan opened this issue 11 months ago • 2 comments

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 avatar Jan 21 '25 13:01 TheyCallMeRyan

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 avatar Jan 21 '25 13:01 TheyCallMeRyan

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

TheyCallMeRyan avatar Jan 21 '25 13:01 TheyCallMeRyan