PackEntityIntoChunk linked list bug

I believe the PackEntityIntoChunk function has a bug in it.
The code that creates the first Block in a chunk will also be called if there is no room left. And at that point, the new Block should chain the old Block on the list. But this is not done.

1
2
3
4
Chunk->FirstBlock = World->FirstFreeBlock;
World->FirstFreeBlock = Chunk->FirstBlock->Next;

ClearWorldEntityBlock(Chunk->FirstBlock);


This overwrites Chunk->FirstBlock without remembering it.

I think it should become

1
2
3
4
5
6
world_entity_block *OldFirstBlock = Chunk->FirstBlock;
Chunk->FirstBlock = World->FirstFreeBlock;
World->FirstFreeBlock = Chunk->FirstBlock->Next;

ClearWorldEntityBlock(Chunk->FirstBlock);
Chunk->FirstBlock->Next = OldFirstBlock;


Or something like that.

Hope this will prevent any future problems

Regards,
Mox
Thanks! I have logged this as a bug so we will look at it on-stream.

- Casey
Can't seem to reopen the github issue, so leaving a message here too in case you don't get notifications: https://github.com/HandmadeHero/cpp/issues/18
Yes, I always get the notifications! So in theory you don't have to reopen the issue, you just have to reply, and then I can go read it and reopen as necessary.

Is this fixed now for you, BTW?

- Casey