GL - Fixed memory leaks in LevelLoader.

This commit is contained in:
Pontus Fransson 2014-02-07 14:44:25 +01:00
parent 9bdf258c5d
commit fef40f58f9
2 changed files with 12 additions and 4 deletions

View File

@ -43,14 +43,14 @@ std::vector<SmartPointer<ObjectTypeHeader>> LevelParser::Parse(std::string filen
while(counter < bufferSize) while(counter < bufferSize)
{ {
//Get typeID //Get typeID
ObjectTypeHeader typeID; ObjectType typeID;
ParseObject(&buffer[counter], &typeID, sizeof(typeID)); ParseObject(&buffer[counter], &typeID, sizeof(typeID));
switch((int)typeID.typeID) switch((int)typeID)
{ {
case ObjectType_LevelMetaData: case ObjectType_LevelMetaData:
{ {
LevelMetaData* header = new LevelMetaData; SmartPointer<ObjectTypeHeader> header = new LevelMetaData;
ParseLevelMetaData(&buffer[counter], *header, counter); ParseLevelMetaData(&buffer[counter], *(LevelMetaData*)header.Get(), counter);
objects.push_back(header); objects.push_back(header);
break; break;
} }

View File

@ -126,6 +126,9 @@ namespace GameLogic
struct ObjectTypeHeader struct ObjectTypeHeader
{ {
ObjectType typeID; ObjectType typeID;
//Unless this is here the object destructor wont be called.
virtual ~ObjectTypeHeader(){}
}; };
namespace LevelLoaderInternal namespace LevelLoaderInternal
@ -182,6 +185,9 @@ namespace GameLogic
WorldSize worldSize; WorldSize worldSize;
std::string overviewPicturePath; std::string overviewPicturePath;
std::vector<GameMode> gameModesSupported; std::vector<GameMode> gameModesSupported;
virtual ~LevelMetaData(){}
}; };
struct ObjectHeader : public ObjectTypeHeader, public LevelLoaderInternal::PhysicsObject struct ObjectHeader : public ObjectTypeHeader, public LevelLoaderInternal::PhysicsObject
@ -197,6 +203,8 @@ namespace GameLogic
float angle; float angle;
//Scale //Scale
float scale[3]; float scale[3];
virtual ~ObjectHeader(){}
}; };
/************************************ /************************************