hunted some memory leaks (with success)

This commit is contained in:
2010-04-14 22:01:45 +02:00
parent cad9b49ffd
commit ca21f8c63a
15 changed files with 77 additions and 78 deletions
-10
View File
@@ -21,7 +21,6 @@ Engine::EntityPhysicState* EntityFactory::CreateEntityPhysicState (int type) {
// However to prevent errors we do a simple check vor validity.
if (type < 0 || type > GameEntityTypeLast ) {
Engine::LogError ("Cannot create Entity with type %d: invalid type!", type);
assert (0);
}
// Create the Entity
@@ -32,7 +31,6 @@ Engine::EntityPhysicState* EntityFactory::CreateEntityPhysicState (int type) {
entity_physics = new ShipEntityPhysicState ();
if (!entity_physics) {
Engine::LogError ("Could not allocate enough memory for EntityPhysicState of type '%d'", type);
assert (0);
}
entity_physics->mRadius = 0.5;
entity_physics->mShape = new coll2d::Sphere (entity_physics->mRadius);
@@ -42,7 +40,6 @@ Engine::EntityPhysicState* EntityFactory::CreateEntityPhysicState (int type) {
entity_physics = new AsteroidEntityPhysicState ();
if (!entity_physics) {
Engine::LogError ("Could not allocate enough memory for EntityPhysicState of type '%d'", type);
assert (0);
}
entity_physics->mRadius = 1.;
@@ -53,7 +50,6 @@ Engine::EntityPhysicState* EntityFactory::CreateEntityPhysicState (int type) {
entity_physics = new RocketEntityPhysicState();
if (!entity_physics) {
Engine::LogError ("Could not allocate enough memory for EntityPhysicState of type '%d'", type);
assert (0);
}
entity_physics->mRadius = 0.1;
entity_physics->mShape = new coll2d::Sphere (entity_physics->mRadius);
@@ -62,13 +58,11 @@ Engine::EntityPhysicState* EntityFactory::CreateEntityPhysicState (int type) {
entity_physics->mBaseType = Engine::EntityBaseTypeBlock;
if (!entity_physics) {
Engine::LogError ("Could not allocate enough memory for EntityPhysicState of type '%d'", type);
assert (0);
}
entity_physics->mRadius = 0.1;
entity_physics->mShape = new coll2d::Sphere (entity_physics->mRadius);
} else {
Engine::LogError ("No EntityPhysicState defined for GameEntity type '%d'", type);
assert (0);
}
entity_physics->mType = type;
@@ -81,7 +75,6 @@ Engine::EntityControllerState* EntityFactory::CreateEntityControllerState (int t
// However to prevent errors we do a simple check vor validity.
if (type < 0 || type >> Engine::EntityBaseTypeLast ) {
Engine::LogError ("Cannot create Entity with type %d: invalid type!", type);
assert (0);
}
// Create the Entity
@@ -92,7 +85,6 @@ Engine::EntityControllerState* EntityFactory::CreateEntityControllerState (int t
entity_controller = new Engine::EntityControllerState ();
if (!entity_controller) {
Engine::LogError ("Could not allocate enough memory for EntityControllerState of type '%d'", type);
assert (0);
}
}
@@ -104,7 +96,6 @@ Engine::EntityBase* EntityFactory::CreateEntity (int type) {
// However to prevent errors we do a simple check vor validity.
if (type < 0 || type > GameEntityTypeLast ) {
Engine::LogError ("Cannot create Entity with type %d: invalid type!", type);
assert (0);
}
// Create the Entity
@@ -125,7 +116,6 @@ Engine::EntityBase* EntityFactory::CreateEntity (int type) {
if (!entity) {
Engine::LogError ("Could not allocate enough memory for EntityVisualState of type '%d'", type);
assert (0);
}
entity->mPhysicState = CreateEntityPhysicState (type);
+5
View File
@@ -8,6 +8,7 @@ namespace asteroids {
class Model : public Engine::ModelBase {
public:
virtual ~Model() {};
virtual void Process();
int DoLoadLevel (const char* filename);
int DoSaveLevel (const char* filename);
@@ -26,6 +27,10 @@ class Model : public Engine::ModelBase {
protected:
/** \brief Initializes the system */
virtual int OnInit (int argc, char* argv[]);
virtual void OnDestroy() {
Engine::ModelBase::OnDestroy();
mAsteroids.clear();
};
virtual void OnRegisterCommands ();
virtual void OnCreateEntity (const int type, const unsigned int id);
+12 -4
View File
@@ -30,16 +30,16 @@ int View::OnInit (int argc, char* argv[]) {
ViewBase::OnInit (argc, argv);
// We want menu
mMenuOverlay = new MenuOverlay;
mMenuOverlay = boost::shared_ptr<MenuOverlay> (new MenuOverlay);
mMenuOverlay->SetModel ((Model*) mModel);
mMenuOverlay->Init();
AddOverlay (mMenuOverlay);
// We want the console
Engine::SimpleConsoleOverlay *console = new Engine::SimpleConsoleOverlay;
mConsoleOverlay = boost::shared_ptr<Engine::SimpleConsoleOverlay> (new Engine::SimpleConsoleOverlay);
// We also want to display the log bar
console->SetDrawLogBar (true);
AddOverlay (console);
mConsoleOverlay->SetDrawLogBar (true);
AddOverlay (mConsoleOverlay);
// This is a simple star field that makes the game so spacy
int i;
@@ -73,6 +73,14 @@ int View::OnInit (int argc, char* argv[]) {
void View::OnDestroy() {
delete mAccelerateEventHandler;
delete mShipExplodeEventHandler;
mBackgroundStars.clear();
mShipPartsEntityIds.clear();
mMenuOverlay.reset();
Engine::ViewBase::OnDestroy();
}
/*
+12 -3
View File
@@ -2,9 +2,11 @@
#define _VIEW_H
#include "ViewBase.h"
#include "OverlayBase.h"
#include "mathlib.h"
#include "Sprite.h"
#include "EntityBase.h"
#include "SimpleConsoleOverlay.h"
namespace asteroids {
@@ -20,10 +22,13 @@ struct BackgroundStar {
/** \brief Performs the actual drawing based on Camera and Model
*/
class View : public Engine::ViewBase {
public:
virtual ~View() {};
protected:
/** \brief Initializes the system */
int OnInit (int argc, char* argv[]);
void OnDestroy ();
virtual int OnInit (int argc, char* argv[]);
virtual void OnDestroy ();
/** \brief Updates the camera for further drawing */
virtual void UpdateCamera ();
@@ -38,7 +43,11 @@ class View : public Engine::ViewBase {
void DrawRocket (RocketEntity *asteroid);
void DrawShipPart (Engine::EntityBase *entity);
MenuOverlay *mMenuOverlay;
// Engine::OverlayBasePtr mMenuOverlay;
// Engine::OverlayBasePtr mConsoleOverlay;
boost::shared_ptr<MenuOverlay> mMenuOverlay;
boost::shared_ptr<Engine::SimpleConsoleOverlay> mConsoleOverlay;
std::vector<BackgroundStar> mBackgroundStars;
std::vector<unsigned int> mShipPartsEntityIds;