Looks like calling the destructor manually is not a good idea.

This commit is contained in:
Simon Robertshaw 2012-08-19 20:44:50 +01:00
parent b1df1e164c
commit c0c30bd305
2 changed files with 32 additions and 4 deletions

View File

@ -9,6 +9,7 @@
#include <iostream>
#include <sstream>
#include <cmath>
#include <vector>
#include <bzlib.h>
#include "Config.h"
#include "bson/BSON.h"
@ -97,7 +98,7 @@ GameSave::GameSave(std::vector<char> data)
catch(ParseException & e)
{
std::cout << e.what() << std::endl;
this->~GameSave(); //Free any allocated memory
dealloc(); //Free any allocated memory
throw;
}
Collapse();
@ -129,7 +130,7 @@ GameSave::GameSave(std::vector<unsigned char> data)
catch(ParseException & e)
{
std::cout << e.what() << std::endl;
this->~GameSave(); //Free any allocated memory
dealloc(); //Free any allocated memory
throw;
}
Collapse();
@ -161,7 +162,7 @@ GameSave::GameSave(char * data, int dataSize)
catch(ParseException & e)
{
std::cout << e.what() << std::endl;
this->~GameSave(); //Free any allocated memory
dealloc(); //Free any allocated memory
throw;
}
//Collapse();
@ -2007,20 +2008,46 @@ fin:
return (char*)outputData;
}
GameSave::~GameSave()
void GameSave::dealloc()
{
if(particles)
{
delete[] particles;
particles = NULL;
}
if(blockMap)
{
delete[] blockMap;
blockMap = NULL;
}
if(blockMapPtr)
{
delete[] blockMapPtr;
blockMapPtr = NULL;
}
if(fanVelX)
{
delete[] fanVelX;
fanVelX = NULL;
}
if(fanVelXPtr)
{
delete[] fanVelXPtr;
fanVelXPtr = NULL;
}
if(fanVelY)
{
delete[] fanVelY;
fanVelY = NULL;
}
if(fanVelYPtr)
{
delete[] fanVelYPtr;
fanVelYPtr = NULL;
}
}
GameSave::~GameSave()
{
}

View File

@ -97,6 +97,7 @@ private:
std::vector<char> originalData;
void dealloc();
void read(char * data, int dataSize);
void readOPS(char * data, int dataLength);
void readPSv(char * data, int dataLength);