fix: mitigate entity id overflow and crash for max chunk updates

This commit is contained in:
sylvessa 2026-03-15 00:48:15 -05:00
parent 5444ad63cf
commit 8fb071fcdf
3 changed files with 18 additions and 1 deletions

View file

@ -146,7 +146,8 @@ void ServerPlayer::flagEntitiesToBeRemoved(unsigned int *flags, bool *removedFou
if( ( *removedFound ) == false )
{
*removedFound = true;
memset(flags, 0, 2048/32);
// before this left 192 bytes uninitialized!!!!!
memset(flags, 0, (2048 / 32) * sizeof(unsigned int));
}
for(int index : entitiesToRemove)

View file

@ -96,9 +96,20 @@ int Entity::getSmallId()
puiUsedFlags++;
}
#ifdef MINECRAFT_SERVER_BUILD
// in mc server dedi, a server with 8+ playerrs can cause this to go wack
int fallbackId = Entity::entityCounter++;
if (entityCounter == 0x7ffffff)
{
entityCounter = 2048;
}
return fallbackId;
#else
app.DebugPrintf("Out of small entity Ids... possible leak?\n");
__debugbreak();
return -1;
#endif
}
void Entity::countFlagsForPIX()

View file

@ -16,7 +16,12 @@ using namespace std;
// 4J Stu - This value should be big enough that we don't get any crashes causes by memory overwrites,
// however it does seem way too large for what is actually needed. Needs further investigation
#ifdef MINECRAFT_SERVER_BUILD
// fixes a crash when 8+ players are present
#define LEVEL_CHUNKS_TO_UPDATE_MAX (32*32*8)
#else
#define LEVEL_CHUNKS_TO_UPDATE_MAX (19*19*8)
#endif
class Vec3;
class ChunkSource;