mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-02-01 22:56:39 +01:00
Fixed a few memory leaks.
This commit is contained in:
@@ -21,7 +21,7 @@
|
||||
|
||||
DBC::DBC(Stream* stream) : StringBlock(NULL), StringBlockSize(0), IsFaulty(true)
|
||||
{
|
||||
stream->Read(4); // Read the magic "WDBC"
|
||||
delete[] stream->Read(4); // Read the magic "WDBC"
|
||||
|
||||
RecordCount = stream->Read<int>();
|
||||
Records.reserve(RecordCount);
|
||||
|
||||
@@ -113,5 +113,10 @@ void LiquidHandler::HandleNewLiquid()
|
||||
Triangles.push_back(Triangle<uint32>(Constants::TRIANGLE_TYPE_WATER, vertOffset + 2, vertOffset + 3, vertOffset + 1));
|
||||
}
|
||||
}
|
||||
|
||||
// At this stage, heights is no longer needed, so we deallocate it
|
||||
for (int j = 0; j < 9; ++j)
|
||||
delete[] heights[j];
|
||||
delete[] heights;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -219,7 +219,6 @@ void MapChunkHeader::Read(Stream* stream)
|
||||
AreaId = stream->Read<uint32>();
|
||||
MapObjectRefs = stream->Read<uint32>();
|
||||
Holes = stream->Read<uint32>();
|
||||
LowQualityTextureMap = new uint32[4];
|
||||
stream->Read(LowQualityTextureMap, sizeof(uint32) * 4);
|
||||
PredTex = stream->Read<uint32>();
|
||||
NumberEffectDoodad = stream->Read<uint32>();
|
||||
@@ -233,8 +232,6 @@ void MapChunkHeader::Read(Stream* stream)
|
||||
|
||||
void MHDR::Read(Stream* stream)
|
||||
{
|
||||
int count = 0;
|
||||
|
||||
Flags = stream->Read<uint32>();
|
||||
OffsetMCIN = stream->Read<uint32>();
|
||||
OffsetMTEX = stream->Read<uint32>();
|
||||
@@ -306,24 +303,20 @@ void ModelHeader::Read(Stream* stream)
|
||||
OffsetBoundingNormals = stream->Read<uint32>();
|
||||
}
|
||||
|
||||
WorldModelHeader WorldModelHeader::Read(Stream* stream)
|
||||
void WorldModelHeader::Read(Stream* stream)
|
||||
{
|
||||
WorldModelHeader ret;
|
||||
int count = 0;
|
||||
ret.CountMaterials = stream->Read<uint32>();
|
||||
ret.CountGroups = stream->Read<uint32>();
|
||||
ret.CountPortals = stream->Read<uint32>();
|
||||
ret.CountLights = stream->Read<uint32>();
|
||||
ret.CountModels = stream->Read<uint32>();
|
||||
ret.CountDoodads = stream->Read<uint32>();
|
||||
ret.CountSets = stream->Read<uint32>();
|
||||
ret.AmbientColorUnk = stream->Read<uint32>();
|
||||
ret.WmoId = stream->Read<uint32>();
|
||||
ret.BoundingBox[0] = Vector3::Read(stream);
|
||||
ret.BoundingBox[1] = Vector3::Read(stream);
|
||||
ret.LiquidTypeRelated = stream->Read<uint32>();
|
||||
|
||||
return ret;
|
||||
CountMaterials = stream->Read<uint32>();
|
||||
CountGroups = stream->Read<uint32>();
|
||||
CountPortals = stream->Read<uint32>();
|
||||
CountLights = stream->Read<uint32>();
|
||||
CountModels = stream->Read<uint32>();
|
||||
CountDoodads = stream->Read<uint32>();
|
||||
CountSets = stream->Read<uint32>();
|
||||
AmbientColorUnk = stream->Read<uint32>();
|
||||
WmoId = stream->Read<uint32>();
|
||||
BoundingBox[0] = Vector3::Read(stream);
|
||||
BoundingBox[1] = Vector3::Read(stream);
|
||||
LiquidTypeRelated = stream->Read<uint32>();
|
||||
}
|
||||
|
||||
DoodadInstance DoodadInstance::Read(Stream* stream)
|
||||
@@ -344,8 +337,9 @@ DoodadInstance DoodadInstance::Read(Stream* stream)
|
||||
DoodadSet DoodadSet::Read(Stream* stream)
|
||||
{
|
||||
DoodadSet ret;
|
||||
|
||||
ret.Name = std::string(stream->Read(20), 20);
|
||||
char* name = stream->Read(20);
|
||||
ret.Name = std::string(name, 20);
|
||||
delete[] name;
|
||||
ret.FirstInstanceIndex = stream->Read<uint32>();
|
||||
ret.CountInstances = stream->Read<uint32>();
|
||||
ret.UnknownZero = stream->Read<uint32>();
|
||||
@@ -353,44 +347,41 @@ DoodadSet DoodadSet::Read(Stream* stream)
|
||||
return ret;
|
||||
}
|
||||
|
||||
LiquidHeader LiquidHeader::Read(Stream* stream)
|
||||
void LiquidHeader::Read(Stream* stream)
|
||||
{
|
||||
LiquidHeader ret;
|
||||
ret.CountXVertices = stream->Read<uint32>();
|
||||
ret.CountYVertices = stream->Read<uint32>();
|
||||
ret.Width = stream->Read<uint32>();
|
||||
ret.Height = stream->Read<uint32>();
|
||||
ret.BaseLocation = Vector3::Read(stream);
|
||||
ret.MaterialId = stream->Read<uint16>();
|
||||
|
||||
return ret;
|
||||
CountXVertices = stream->Read<uint32>();
|
||||
CountYVertices = stream->Read<uint32>();
|
||||
Width = stream->Read<uint32>();
|
||||
Height = stream->Read<uint32>();
|
||||
BaseLocation = Vector3::Read(stream);
|
||||
MaterialId = stream->Read<uint16>();
|
||||
}
|
||||
|
||||
LiquidData LiquidData::Read(Stream* stream, LiquidHeader& header)
|
||||
void LiquidData::Read(Stream* stream, LiquidHeader& header)
|
||||
{
|
||||
LiquidData ret;
|
||||
ret.HeightMap = new float*[header.CountXVertices];
|
||||
for (uint32 i = 0; i < header.CountXVertices; ++i)
|
||||
ret.HeightMap[i] = new float[header.CountYVertices];
|
||||
CountXVertices = header.CountXVertices;
|
||||
Width = header.Width;
|
||||
|
||||
ret.RenderFlags = new uint8*[header.Width];
|
||||
HeightMap = new float*[header.CountXVertices];
|
||||
for (uint32 i = 0; i < header.CountXVertices; ++i)
|
||||
HeightMap[i] = new float[header.CountYVertices];
|
||||
|
||||
RenderFlags = new uint8*[header.Width];
|
||||
for (uint32 i = 0; i < header.Width; ++i)
|
||||
ret.RenderFlags[i] = new uint8[header.Height];
|
||||
RenderFlags[i] = new uint8[header.Height];
|
||||
|
||||
for (uint32 y = 0; y < header.CountYVertices; y++)
|
||||
{
|
||||
for (uint32 x = 0; x < header.CountXVertices; x++)
|
||||
{
|
||||
stream->Read<uint32>(); // Dummy value
|
||||
ret.HeightMap[x][y] = stream->Read<float>();
|
||||
HeightMap[x][y] = stream->Read<float>();
|
||||
}
|
||||
}
|
||||
|
||||
for (uint32 y = 0; y < header.Height; y++)
|
||||
for (uint32 x = 0; x < header.Width; x++)
|
||||
ret.RenderFlags[x][y] = stream->Read<uint8>();
|
||||
|
||||
return ret;
|
||||
RenderFlags[x][y] = stream->Read<uint8>();
|
||||
}
|
||||
|
||||
H2ORenderMask H2ORenderMask::Read(Stream* stream)
|
||||
|
||||
@@ -102,7 +102,7 @@ public:
|
||||
uint32 AreaId;
|
||||
uint32 MapObjectRefs;
|
||||
uint32 Holes;
|
||||
uint32* LowQualityTextureMap;
|
||||
uint32 LowQualityTextureMap[4];
|
||||
uint32 PredTex;
|
||||
uint32 NumberEffectDoodad;
|
||||
uint32 OffsetMCSE;
|
||||
@@ -208,7 +208,7 @@ public:
|
||||
Vector3 BoundingBox[2];
|
||||
uint32 LiquidTypeRelated;
|
||||
|
||||
static WorldModelHeader Read(Stream* stream);
|
||||
void Read(Stream* stream);
|
||||
};
|
||||
|
||||
class DoodadInstance
|
||||
@@ -251,22 +251,36 @@ public:
|
||||
Vector3 BaseLocation;
|
||||
uint16 MaterialId;
|
||||
|
||||
static LiquidHeader Read(Stream* stream);
|
||||
void Read(Stream* stream);
|
||||
};
|
||||
|
||||
class LiquidData
|
||||
{
|
||||
public:
|
||||
LiquidData() {}
|
||||
|
||||
~LiquidData()
|
||||
{
|
||||
for (uint32 i = 0; i < CountXVertices; ++i)
|
||||
delete[] HeightMap[i];
|
||||
delete[] HeightMap;
|
||||
|
||||
for (uint32 i = 0; i < Width; ++i)
|
||||
delete[] RenderFlags[i];
|
||||
delete[] RenderFlags;
|
||||
}
|
||||
|
||||
float** HeightMap;
|
||||
uint8** RenderFlags;
|
||||
uint32 CountXVertices;
|
||||
uint32 Width;
|
||||
|
||||
bool ShouldRender(int x, int y)
|
||||
{
|
||||
return RenderFlags[x][y] != 0x0F;
|
||||
}
|
||||
|
||||
static LiquidData Read(Stream* stream, LiquidHeader& header);
|
||||
void Read(Stream* stream, LiquidHeader& header);
|
||||
};
|
||||
|
||||
class H2ORenderMask
|
||||
|
||||
@@ -70,8 +70,8 @@ void WorldModelGroup::ReadLiquid()
|
||||
|
||||
HasLiquidData = true;
|
||||
Stream* stream = chunk->GetStream();
|
||||
LiquidDataHeader = LiquidHeader::Read(stream);
|
||||
LiquidDataGeometry = LiquidData::Read(stream, LiquidDataHeader);
|
||||
LiquidDataHeader.Read(stream);
|
||||
LiquidDataGeometry.Read(stream, LiquidDataHeader);
|
||||
}
|
||||
|
||||
void WorldModelGroup::ReadVertices()
|
||||
|
||||
@@ -92,5 +92,5 @@ void WorldModelRoot::ReadHeader()
|
||||
return;
|
||||
|
||||
Stream* stream = chunk->GetStream();
|
||||
Header = WorldModelHeader::Read(stream);
|
||||
Header.Read(stream);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user