From 66b31669c3cb3fcb9cae3409cb2c869b25ed0eb7 Mon Sep 17 00:00:00 2001 From: Nikita Edel Date: Mon, 9 Mar 2026 22:48:36 +0100 Subject: [PATCH] new batch of delete operator missmatch --- .../Platform/Common/GameRules/ConsoleSchematicFile.cpp | 4 ++-- .../Platform/Common/Tutorial/LookAtTileHint.h | 2 +- Minecraft.Client/Platform/Common/Tutorial/TakeItemHint.h | 2 +- Minecraft.Client/Platform/Common/Tutorial/TutorialHint.h | 2 +- .../Rendering/EntityRenderers/TileRenderer.cpp | 2 +- Minecraft.World/IO/Streams/BufferedOutputStream.cpp | 6 +++++- Minecraft.World/Items/MapItem.cpp | 2 +- Minecraft.World/Level/Storage/MapItemSavedData.cpp | 2 +- Minecraft.World/Network/Packets/AwardStatPacket.cpp | 9 +++++++-- Minecraft.World/Network/Packets/RemoveEntitiesPacket.cpp | 2 +- Minecraft.World/Util/AABB.cpp | 4 ++-- Minecraft.World/WorldGen/Biomes/BiomeSource.cpp | 4 ++-- .../WorldGen/Sources/TheEndLevelRandomLevelSource.cpp | 3 ++- 13 files changed, 27 insertions(+), 17 deletions(-) diff --git a/Minecraft.Client/Platform/Common/GameRules/ConsoleSchematicFile.cpp b/Minecraft.Client/Platform/Common/GameRules/ConsoleSchematicFile.cpp index 586e29997..f8af5039a 100644 --- a/Minecraft.Client/Platform/Common/GameRules/ConsoleSchematicFile.cpp +++ b/Minecraft.Client/Platform/Common/GameRules/ConsoleSchematicFile.cpp @@ -285,12 +285,12 @@ __int64 ConsoleSchematicFile::applyBlocksAndData(LevelChunk *chunk, AABB *chunkB PIXBeginNamedEvent(0,"Setting Block data"); chunk->setBlockData(blockData); PIXEndNamedEvent(); - delete blockData.data; + delete[] blockData.data; //4jcraft changed to array delete chunk->recalcHeightmapOnly(); PIXBeginNamedEvent(0,"Setting Data data"); chunk->setDataData(dataData); PIXEndNamedEvent(); - delete dataData.data; + delete[] dataData.data; //4jcraft, same here // A basic pass through to roughly do the lighting. At this point of post-processing, we don't have all the neighbouring chunks loaded in, // so any lighting here should be things that won't propagate out of this chunk. diff --git a/Minecraft.Client/Platform/Common/Tutorial/LookAtTileHint.h b/Minecraft.Client/Platform/Common/Tutorial/LookAtTileHint.h index 856dbb63f..1c03e08d6 100644 --- a/Minecraft.Client/Platform/Common/Tutorial/LookAtTileHint.h +++ b/Minecraft.Client/Platform/Common/Tutorial/LookAtTileHint.h @@ -19,4 +19,4 @@ public: ~LookAtTileHint(); virtual bool onLookAt(int id, int iData=0); -}; \ No newline at end of file +}; diff --git a/Minecraft.Client/Platform/Common/Tutorial/TakeItemHint.h b/Minecraft.Client/Platform/Common/Tutorial/TakeItemHint.h index a7641f64b..fe2744f36 100644 --- a/Minecraft.Client/Platform/Common/Tutorial/TakeItemHint.h +++ b/Minecraft.Client/Platform/Common/Tutorial/TakeItemHint.h @@ -16,4 +16,4 @@ public: ~TakeItemHint(); virtual bool onTake( std::shared_ptr item ); -}; \ No newline at end of file +}; diff --git a/Minecraft.Client/Platform/Common/Tutorial/TutorialHint.h b/Minecraft.Client/Platform/Common/Tutorial/TutorialHint.h index 191b021f3..f114392c7 100644 --- a/Minecraft.Client/Platform/Common/Tutorial/TutorialHint.h +++ b/Minecraft.Client/Platform/Common/Tutorial/TutorialHint.h @@ -50,4 +50,4 @@ public: virtual bool onLookAtEntity(eINSTANCEOF type); virtual int tick(); virtual bool allowFade() { return m_allowFade; } -}; \ No newline at end of file +}; diff --git a/Minecraft.Client/Rendering/EntityRenderers/TileRenderer.cpp b/Minecraft.Client/Rendering/EntityRenderers/TileRenderer.cpp index a84a13eeb..30d05c2b3 100644 --- a/Minecraft.Client/Rendering/EntityRenderers/TileRenderer.cpp +++ b/Minecraft.Client/Rendering/EntityRenderers/TileRenderer.cpp @@ -160,7 +160,7 @@ TileRenderer::TileRenderer( LevelSource* level, int xMin, int yMin, int zMin, un TileRenderer::~TileRenderer() { - delete cache; + delete[] cache; //4jcraft, changed to [] } TileRenderer::TileRenderer( LevelSource* level ) diff --git a/Minecraft.World/IO/Streams/BufferedOutputStream.cpp b/Minecraft.World/IO/Streams/BufferedOutputStream.cpp index 4e1051a7c..379686138 100644 --- a/Minecraft.World/IO/Streams/BufferedOutputStream.cpp +++ b/Minecraft.World/IO/Streams/BufferedOutputStream.cpp @@ -15,7 +15,11 @@ BufferedOutputStream::BufferedOutputStream(OutputStream *out, int size) BufferedOutputStream::~BufferedOutputStream() { - delete buf.data; + //4jcraft, changed to [], deallocates internal buffer + //TODO: ArrayWithLength.h doesnt have a destructor. + //this wouldnt need to be done manually. + //but for some reason the destructor is commented out in the source code? + delete[] buf.data; } //Flushes this buffered output stream. This forces any buffered output bytes to be written out to the underlying output stream. diff --git a/Minecraft.World/Items/MapItem.cpp b/Minecraft.World/Items/MapItem.cpp index 292320b27..908d0f776 100644 --- a/Minecraft.World/Items/MapItem.cpp +++ b/Minecraft.World/Items/MapItem.cpp @@ -342,6 +342,6 @@ std::shared_ptr MapItem::getUpdatePacket(std::shared_ptr i if (data.data == NULL || data.length == 0) return nullptr; std::shared_ptr retval = std::shared_ptr(new ComplexItemDataPacket((short) Item::map->id, (short) itemInstance->getAuxValue(), data)); - delete data.data; + delete[] data.data; //4jcraft, changed to [] return retval; } diff --git a/Minecraft.World/Level/Storage/MapItemSavedData.cpp b/Minecraft.World/Level/Storage/MapItemSavedData.cpp index c0ee9b024..ae98d8698 100644 --- a/Minecraft.World/Level/Storage/MapItemSavedData.cpp +++ b/Minecraft.World/Level/Storage/MapItemSavedData.cpp @@ -123,7 +123,7 @@ charArray MapItemSavedData::HoldingPlayer::nextUpdatePacket(std::shared_ptr servPlayer = std::dynamic_pointer_cast(player); for (int d = 0; d < 10; d++) diff --git a/Minecraft.World/Network/Packets/AwardStatPacket.cpp b/Minecraft.World/Network/Packets/AwardStatPacket.cpp index efa503b9b..576cead1b 100644 --- a/Minecraft.World/Network/Packets/AwardStatPacket.cpp +++ b/Minecraft.World/Network/Packets/AwardStatPacket.cpp @@ -16,7 +16,12 @@ AwardStatPacket::AwardStatPacket(int statId, int count) { this->statId = statId; - this->m_paramData.data = (uint8_t *) new int(count); + // 4jcraft, changed from new int(count); to new int[1]; + // and initializing the array with count + // reason: .data needs to be delete with delete[] but its + // allocated with new, not new T[] + this->m_paramData.data = (uint8_t *) new int[1]; + ((int*)this->m_paramData.data)[0] = count; this->m_paramData.length = sizeof(int); } @@ -30,7 +35,7 @@ AwardStatPacket::~AwardStatPacket() { if (m_paramData.data != NULL) { - delete [] m_paramData.data; + delete[] m_paramData.data; m_paramData.data = NULL; } } diff --git a/Minecraft.World/Network/Packets/RemoveEntitiesPacket.cpp b/Minecraft.World/Network/Packets/RemoveEntitiesPacket.cpp index a007849a2..9207ca8bf 100644 --- a/Minecraft.World/Network/Packets/RemoveEntitiesPacket.cpp +++ b/Minecraft.World/Network/Packets/RemoveEntitiesPacket.cpp @@ -16,7 +16,7 @@ RemoveEntitiesPacket::RemoveEntitiesPacket(intArray ids) RemoveEntitiesPacket::~RemoveEntitiesPacket() { - delete ids.data; + delete[] ids.data; //4jcraft, changed to [] } void RemoveEntitiesPacket::read(DataInputStream *dis) //throws IOException diff --git a/Minecraft.World/Util/AABB.cpp b/Minecraft.World/Util/AABB.cpp index b768f76f6..3dc459497 100644 --- a/Minecraft.World/Util/AABB.cpp +++ b/Minecraft.World/Util/AABB.cpp @@ -12,14 +12,14 @@ AABB::ThreadStorage *AABB::tlsDefault = NULL; AABB::ThreadStorage::ThreadStorage() { - pool = new AABB[POOL_SIZE]; + pool = new AABB[POOL_SIZE]; //4jcraft, needs to be deleted with delete[] poolPointer = 0; } AABB::ThreadStorage::~ThreadStorage() { - delete pool; + delete[] pool; //4jcraft, changed to [] } void AABB::CreateNewThreadStorage() diff --git a/Minecraft.World/WorldGen/Biomes/BiomeSource.cpp b/Minecraft.World/WorldGen/Biomes/BiomeSource.cpp index f5c142e12..3a77b436d 100644 --- a/Minecraft.World/WorldGen/Biomes/BiomeSource.cpp +++ b/Minecraft.World/WorldGen/Biomes/BiomeSource.cpp @@ -218,7 +218,7 @@ void BiomeSource::getBiomeBlock(BiomeArray& biomes, int x, int z, int w, int h, { BiomeArray tmp = cache->getBiomeBlockAt(x, z); System::arraycopy(tmp, 0, &biomes, 0, w * h); - delete tmp.data; // MGH - added, the caching creates this array from the indices now. + delete[] tmp.data; // MGH - added, the caching creates this array from the indices now. //4jcraft made it array delete //return biomes; } @@ -635,4 +635,4 @@ bool BiomeSource::getIsMatch(float *frac) // Consider as suitable if we've got all the critical ones, and in total 9 or more - currently there's 8 critical so this just forces at least 1 more others return ( typeCount >= 9 ); -} \ No newline at end of file +} diff --git a/Minecraft.World/WorldGen/Sources/TheEndLevelRandomLevelSource.cpp b/Minecraft.World/WorldGen/Sources/TheEndLevelRandomLevelSource.cpp index 63bfa9837..7280ea617 100644 --- a/Minecraft.World/WorldGen/Sources/TheEndLevelRandomLevelSource.cpp +++ b/Minecraft.World/WorldGen/Sources/TheEndLevelRandomLevelSource.cpp @@ -188,7 +188,8 @@ LevelChunk *TheEndLevelRandomLevelSource::getChunk(int xOffs, int zOffs) levelChunk->recalcHeightmap(); //delete blocks.data; // Don't delete the blocks as the array data is actually owned by the chunk now - delete biomes.data; + //4jcraft changed to [] + delete[] biomes.data; return levelChunk; }