Skip to content

Instantly share code, notes, and snippets.

@cyberium
Created December 31, 2013 17:51
Show Gist options
  • Save cyberium/8200179 to your computer and use it in GitHub Desktop.
Save cyberium/8200179 to your computer and use it in GitHub Desktop.
commit d9b6fee959fb28301e8ac04ffad2cb867f73c062
Author: Cyberium <cybermomo@techemail.com>
Date: Tue Dec 31 13:43:06 2013 +0100
Correct a crash due to invalid pointer.
Add a possibility to abort program before start
diff --git a/contrib/mesh_extractor/src/LiquidHandler.cpp b/contrib/mesh_extractor/src/LiquidHandler.cpp
index fa59d1b..97a92a7 100644
--- a/contrib/mesh_extractor/src/LiquidHandler.cpp
+++ b/contrib/mesh_extractor/src/LiquidHandler.cpp
@@ -44,7 +44,7 @@ void LiquidHandler::HandleNewLiquid()
if (h.LayerCount == 0)
{
// Need to fill in missing data with dummies.
- MCNKData.push_back(MCNKLiquidData(NULL, H2ORenderMask()));
+ MCNKData.push_back(new MCNKLiquidData(NULL, H2ORenderMask()));
continue;
}
stream->Seek(chunk->Offset + h.OffsetInformation, SEEK_SET);
@@ -88,7 +88,7 @@ void LiquidHandler::HandleNewLiquid()
heights[x][y] = information.HeightLevel1;
}
- MCNKData.push_back(MCNKLiquidData(heights, renderMask));
+ MCNKData.push_back(new MCNKLiquidData(heights, renderMask));
for (int y = information.OffsetY; y < (information.OffsetY + information.Height); y++)
{
@@ -113,10 +113,15 @@ 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;
+LiquidHandler::~LiquidHandler()
+{
+ if (!MCNKData.empty())
+ {
+ std::vector<MCNKLiquidData*>::iterator itr = MCNKData.begin();
+ while (itr!=MCNKData.end())
+ delete *itr++;
}
}
diff --git a/contrib/mesh_extractor/src/LiquidHandler.h b/contrib/mesh_extractor/src/LiquidHandler.h
index c053b62..2bb503c 100644
--- a/contrib/mesh_extractor/src/LiquidHandler.h
+++ b/contrib/mesh_extractor/src/LiquidHandler.h
@@ -27,11 +27,12 @@ class LiquidHandler
{
public:
LiquidHandler(ADT* adt);
+ ~LiquidHandler();
ADT* Source;
std::vector<Vector3> Vertices;
std::vector<Triangle<uint32> > Triangles;
- std::vector<MCNKLiquidData> MCNKData;
+ std::vector<MCNKLiquidData*> MCNKData;
private:
void HandleNewLiquid();
};
diff --git a/contrib/mesh_extractor/src/MapChunk.cpp b/contrib/mesh_extractor/src/MapChunk.cpp
index f9d4976..ee6b458 100644
--- a/contrib/mesh_extractor/src/MapChunk.cpp
+++ b/contrib/mesh_extractor/src/MapChunk.cpp
@@ -47,12 +47,12 @@ void MapChunk::GenerateTriangles()
Constants::TriangleType triangleType = Constants::TRIANGLE_TYPE_TERRAIN;
if (Adt->_LiquidHandler && !Adt->_LiquidHandler->MCNKData.empty())
{
- MCNKLiquidData& data = Adt->_LiquidHandler->MCNKData[Index];
+ MCNKLiquidData* data = Adt->_LiquidHandler->MCNKData[Index];
float maxHeight = std::max(
std::max(
std::max(std::max(Vertices[topLeft].z, Vertices[topRight].z), Vertices[bottomLeft].z),
Vertices[bottomRight].z), Vertices[center].z);
- if (data.IsWater(x, y, maxHeight))
+ if (data->IsWater(x, y, maxHeight))
triangleType = Constants::TRIANGLE_TYPE_WATER;
}
diff --git a/contrib/mesh_extractor/src/MeshExtractor.cpp b/contrib/mesh_extractor/src/MeshExtractor.cpp
index f756bf0..b46f25f 100644
--- a/contrib/mesh_extractor/src/MeshExtractor.cpp
+++ b/contrib/mesh_extractor/src/MeshExtractor.cpp
@@ -62,7 +62,7 @@ void ExtractMMaps(std::set<uint32>& mapIds, uint32 threads)
Utils::CreateDir(basePath);
DBC* dbc = MPQHandler->GetDBC("Map");
- printf("Map.dbc contains " SIZEFMTD " rows.\n", dbc->Records.size());
+ printf("Map.dbc contains %u rows.\n", dbc->Records.size());
for (std::vector<Record*>::iterator itr = dbc->Records.begin(); itr != dbc->Records.end(); ++itr)
{
uint32 mapId = (*itr)->Values[0];
@@ -389,6 +389,18 @@ void LoadTile(dtNavMesh*& navMesh, const char* tile)
fclose(f);
}
+// just for debug purposes
+bool AskUser()
+{
+ printf("Please push enter to continue or escape to exit.\n");
+ std::string s;
+ std::getline(std::cin, s);
+ if (strcmp(s.c_str(), "y") == 0)
+ return true;
+ else
+ return false;
+}
+
int main(int argc, char* argv[])
{
uint32 threads = 4, extractFlags = 0;
@@ -406,7 +418,10 @@ int main(int argc, char* argv[])
PrintUsage();
return -1;
}
-
+
+ if (!AskUser())
+ return 0;
+
Cache = new CacheClass();
MPQHandler = new MPQManager();
MPQHandler->Initialize();
diff --git a/contrib/mesh_extractor/src/Utils.cpp b/contrib/mesh_extractor/src/Utils.cpp
index 937de4b..2d271fc 100644
--- a/contrib/mesh_extractor/src/Utils.cpp
+++ b/contrib/mesh_extractor/src/Utils.cpp
@@ -403,6 +403,17 @@ bool MCNKLiquidData::IsWater(int x, int y, float height)
return false;
}
+MCNKLiquidData::~MCNKLiquidData()
+{
+ if (Heights)
+ {
+ for (int j = 0; j < 9; ++j)
+ delete[] Heights[j];
+ delete[] Heights;
+ Heights = NULL;
+ }
+}
+
H2OHeader H2OHeader::Read(Stream* stream)
{
H2OHeader ret;
diff --git a/contrib/mesh_extractor/src/Utils.h b/contrib/mesh_extractor/src/Utils.h
index 07a7628..e8fb56b 100644
--- a/contrib/mesh_extractor/src/Utils.h
+++ b/contrib/mesh_extractor/src/Utils.h
@@ -302,7 +302,7 @@ class MCNKLiquidData
public:
MCNKLiquidData() {}
MCNKLiquidData(float** heights, H2ORenderMask mask) : Heights(heights), Mask(mask) {}
-
+ ~MCNKLiquidData();
float** Heights;
H2ORenderMask Mask;
diff --git a/contrib/mesh_extractor/win/mesh_extractor.vcxproj b/contrib/mesh_extractor/win/mesh_extractor.vcxproj
index cac4f49..e19f626 100644
--- a/contrib/mesh_extractor/win/mesh_extractor.vcxproj
+++ b/contrib/mesh_extractor/win/mesh_extractor.vcxproj
@@ -64,7 +64,8 @@
<AdditionalLibraryDirectories>..\bin\$(Platform)_$(Configuration)\lib</AdditionalLibraryDirectories>
</Link>
<PostBuildEvent>
- <Command>xcopy /y ..\bin\$(Platform)_$(Configuration)\lib\*.dll ..\bin\$(Platform)_$(Configuration)</Command>
+ <Command>xcopy /y ..\bin\$(Platform)_$(Configuration)\lib\*.dll ..\bin\$(Platform)_$(Configuration)
+xcopy /y ..\bin\$(Platform)_$(Configuration)\*.* "d:\World Of Warcraft - 335 - momo-srv"</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
@@ -86,7 +87,8 @@
<AdditionalLibraryDirectories>..\..\..\deb\lib\$(Platform)_$(Configuration);..\bin\$(Platform)_$(Configuration)\lib</AdditionalLibraryDirectories>
</Link>
<PostBuildEvent>
- <Command>xcopy /y ..\bin\$(Platform)_$(Configuration)\lib\*.dll ..\bin\$(Platform)_$(Configuration)</Command>
+ <Command>xcopy /y ..\bin\$(Platform)_$(Configuration)\lib\*.dll ..\bin\$(Platform)_$(Configuration)
+xcopy /y ..\bin\$(Platform)_$(Configuration)\*.* "d:\World Of Warcraft - 335 - momo-srv"</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemGroup>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment