Commit 5ab2f2ea authored by Anakin's avatar Anakin

fixed the memory garbage problem

parent 5c5b9ac2
......@@ -24,7 +24,7 @@ struct Segment {
std::uint32_t textureIndex = 0;
float* vertex = nullptr;
float* uv = nullptr;
std::vector<std::vector<std::uint32_t>*> meshIndices; // indices into vertex array
std::vector<std::vector<std::uint32_t>> meshIndices; // indices into vertex array
};
struct Modl {
......
......@@ -434,7 +434,7 @@ void Object::analyseSegmChunks(Modl * dataDestination, std::list<ChunkHeader*>&
fsMesh.read(reinterpret_cast<char*>(&tempSize), sizeof(tempSize));
int highBitCount(0);
std::vector<uint32_t>* tempPoly = new std::vector<uint32_t>;
std::vector<uint32_t> tempPoly; // = new std::vector<uint32_t>;
for (unsigned int i = 0; i < tempSize; i++)
{
......@@ -449,7 +449,7 @@ void Object::analyseSegmChunks(Modl * dataDestination, std::list<ChunkHeader*>&
tempValue = (std::uint16_t(tempValue << 1) >> 1);
}
tempPoly->push_back((std::uint32_t)tempValue);
tempPoly.push_back((std::uint32_t)tempValue);
// new Polygon found
if (highBitCount == 2)
......@@ -461,18 +461,20 @@ void Object::analyseSegmChunks(Modl * dataDestination, std::list<ChunkHeader*>&
std::uint32_t saveData[2];
for (int i = 0; i < 2; i++)
{
saveData[i] = tempPoly->back();
tempPoly->pop_back();
saveData[i] = tempPoly.back();
tempPoly.pop_back();
}
// ..and save them in the new vector
std::vector<uint32_t>* newPointer = new std::vector<uint32_t>;
tempData->meshIndices.push_back(tempPoly);
tempPoly.clear();
for (int i = 1; i >= 0; i--)
newPointer->push_back(saveData[i]);
tempPoly.push_back(saveData[i]);
// save the old vector and set the pointer to the new one
tempData->meshIndices.push_back(tempPoly);
tempPoly = newPointer;
//tempData->meshIndices.push_back(tempPoly);
//tempPoly = newPointer;
} // if high bit set
} // for all values
......@@ -542,19 +544,19 @@ void Object::analyseClthChunks(Modl * dataDestination, std::list<ChunkHeader*>&
fsMesh.seekg((*it)->position);
fsMesh.read(reinterpret_cast<char*>(&tempSize), sizeof(tempSize));
std::vector<uint32_t>* tempPoly;
std::vector<uint32_t> tempPoly;
// for every triangle..
for (unsigned int i = 0; i < tempSize; i += 3)
{
tempPoly = new std::vector<uint32_t>;
tempPoly.clear();
// ..get the 3 indices and save them
for (int j = 0; j < 3; j++)
{
std::uint32_t tempValue;
fsMesh.read(reinterpret_cast<char*>(&tempValue), sizeof(std::uint32_t));
tempPoly->push_back(tempValue);
tempPoly.push_back(tempValue);
}
tempData->meshIndices.push_back(tempPoly);
}
......
......@@ -126,10 +126,10 @@ void OpenGLController::deleteVectors()
while (!segmCuror->meshIndices.empty())
{
std::vector<std::uint32_t>* meshCursor = segmCuror->meshIndices.back();
meshCursor->clear();
while (!segmCuror->meshIndices.back().empty())
segmCuror->meshIndices.back().pop_back();
segmCuror->meshIndices.pop_back();
delete meshCursor;
}
delete segmCuror;
......@@ -350,7 +350,7 @@ void OpenGLController::updateScene()
// calculate the number of vertex
unsigned int vertexCount(0);
for (auto& it : segIt->meshIndices)
vertexCount += (it->size() - 2) * 3;
vertexCount += (it.size() - 2) * 3;
glDrawArrays(GL_TRIANGLES, instanceOffset, vertexCount);
......@@ -393,10 +393,10 @@ void OpenGLController::loadMsh(const char * path)
{
for (auto& mshIt : segIt->meshIndices) // for every polygon
{
if (mshIt->size() >= 3) // multipoly
if (mshIt.size() >= 3) // multipoly
{
// for every triangle of the multi polygon
for (unsigned int tri = 0; tri < mshIt->size() - 2; tri++)
for (unsigned int tri = 0; tri < mshIt.size() - 2; tri++)
{
// for every edge of the triangle
for (int triEdge = 0; triEdge < 3; triEdge++)
......@@ -404,7 +404,7 @@ void OpenGLController::loadMsh(const char * path)
Vertex tempVertex;
// every edge has 3 coordinates
for (int j = 0; j < 3; j++)
tempVertex.position[j] = (GLfloat)segIt->vertex[(*mshIt)[tri + triEdge - ((tri % 2) * (triEdge - 1) * 2)] * 3 + j];
tempVertex.position[j] = (GLfloat)segIt->vertex[mshIt[tri + triEdge - ((tri % 2) * (triEdge - 1) * 2)] * 3 + j];
// and 2 UV
if (segIt->uv == NULL)
......@@ -415,7 +415,7 @@ void OpenGLController::loadMsh(const char * path)
else
{
for (int j = 0; j < 2; j++)
tempVertex.uv[j] = (GLfloat)segIt->uv[(*mshIt)[tri + triEdge - ((tri % 2) * (triEdge - 1) * 2)] * 2 + j];
tempVertex.uv[j] = (GLfloat)segIt->uv[mshIt[tri + triEdge - ((tri % 2) * (triEdge - 1) * 2)] * 2 + j];
}
tempBufferData.push_back(tempVertex);
}
......@@ -441,6 +441,8 @@ void OpenGLController::loadMsh(const char * path)
);
glBindBuffer(GL_ARRAY_BUFFER, 0);
tempBufferData.clear();
// get textures path
std::string tempPath = path;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment