Sfoglia il codice sorgente

Last of mcclure's leak fixes and destructors for examples

Ivan Safrin 13 anni fa
parent
commit
0c3a7d3954
31 ha cambiato i file con 103 aggiunte e 18 eliminazioni
  1. 1 2
      Examples/C++/Contents/2DAudio/HelloPolycodeApp.cpp
  2. 3 0
      Examples/C++/Contents/2DParticles/HelloPolycodeApp.cpp
  3. 3 0
      Examples/C++/Contents/2DPhysics_Basic/HelloPolycodeApp.cpp
  4. 3 0
      Examples/C++/Contents/2DPhysics_Joints/HelloPolycodeApp.cpp
  5. 3 0
      Examples/C++/Contents/2DTransforms/HelloPolycodeApp.cpp
  6. 3 0
      Examples/C++/Contents/3DBasics/HelloPolycodeApp.cpp
  7. 3 0
      Examples/C++/Contents/3DMeshParticles/HelloPolycodeApp.cpp
  8. 3 0
      Examples/C++/Contents/3DParticles/HelloPolycodeApp.cpp
  9. 3 0
      Examples/C++/Contents/3DPhysics_Basic/HelloPolycodeApp.cpp
  10. 3 0
      Examples/C++/Contents/3DPhysics_Character/HelloPolycodeApp.cpp
  11. 3 0
      Examples/C++/Contents/3DPhysics_CollisionOnly/HelloPolycodeApp.cpp
  12. 3 0
      Examples/C++/Contents/3DPhysics_Contacts/HelloPolycodeApp.cpp
  13. 3 0
      Examples/C++/Contents/3DPhysics_RayTest/HelloPolycodeApp.cpp
  14. 3 0
      Examples/C++/Contents/3DPhysics_Vehicle/HelloPolycodeApp.cpp
  15. 3 0
      Examples/C++/Contents/AdvancedLighting/HelloPolycodeApp.cpp
  16. 3 0
      Examples/C++/Contents/BasicImage/HelloPolycodeApp.cpp
  17. 3 0
      Examples/C++/Contents/BasicLighting/HelloPolycodeApp.cpp
  18. 3 0
      Examples/C++/Contents/BasicText/HelloPolycodeApp.cpp
  19. 3 0
      Examples/C++/Contents/EventHandling/HelloPolycodeApp.cpp
  20. 3 0
      Examples/C++/Contents/KeyboardInput/HelloPolycodeApp.cpp
  21. 3 0
      Examples/C++/Contents/MouseInput/HelloPolycodeApp.cpp
  22. 3 0
      Examples/C++/Contents/Networking_Server/HelloPolycodeApp.cpp
  23. 3 1
      Examples/C++/Contents/PlayingSounds/HelloPolycodeApp.cpp
  24. 3 0
      Examples/C++/Contents/ScreenEntities/HelloPolycodeApp.cpp
  25. 3 0
      Examples/C++/Contents/ScreenSprites/HelloPolycodeApp.cpp
  26. 3 0
      Examples/C++/Contents/SkeletalAnimation/HelloPolycodeApp.cpp
  27. 3 0
      Examples/C++/Contents/UpdateLoop/HelloPolycodeApp.cpp
  28. 0 1
      Modules/Contents/2DPhysics/Include/PolyPhysicsScreen.h
  29. 0 1
      Modules/Contents/2DPhysics/Include/PolyPhysicsScreenEntity.h
  30. 13 11
      Modules/Contents/2DPhysics/Source/PolyPhysicsScreen.cpp
  31. 11 2
      Modules/Contents/2DPhysics/Source/PolyPhysicsScreenEntity.cpp

+ 1 - 2
Examples/C++/Contents/2DAudio/HelloPolycodeApp.cpp

@@ -30,8 +30,7 @@ HelloPolycodeApp::HelloPolycodeApp(PolycodeView *view) {
 	screen->addChild(listenerEntity);
 
 	listenerPositionValue = 0;
-	positionValue = 0;
-	
+	positionValue = 0;	
 }
 
 HelloPolycodeApp::~HelloPolycodeApp() {

+ 3 - 0
Examples/C++/Contents/2DParticles/HelloPolycodeApp.cpp

@@ -48,6 +48,9 @@ HelloPolycodeApp::HelloPolycodeApp(PolycodeView *view) {
 	screen->addChild(emitter);
 }
 
+HelloPolycodeApp::~HelloPolycodeApp() {
+}
+
 bool HelloPolycodeApp::Update() {
     return core->Update();
 }

+ 3 - 0
Examples/C++/Contents/2DPhysics_Basic/HelloPolycodeApp.cpp

@@ -24,6 +24,9 @@ HelloPolycodeApp::HelloPolycodeApp(PolycodeView *view) {
 
 }
 
+HelloPolycodeApp::~HelloPolycodeApp() {
+}
+
 bool HelloPolycodeApp::Update() {
     return core->Update();
 }

+ 3 - 0
Examples/C++/Contents/2DPhysics_Joints/HelloPolycodeApp.cpp

@@ -46,6 +46,9 @@ HelloPolycodeApp::HelloPolycodeApp(PolycodeView *view) {
 	screen->addChild(line);
 }
 
+HelloPolycodeApp::~HelloPolycodeApp() {
+}
+
 bool HelloPolycodeApp::Update() {
     return core->Update();
 }

+ 3 - 0
Examples/C++/Contents/2DTransforms/HelloPolycodeApp.cpp

@@ -22,6 +22,9 @@ HelloPolycodeApp::HelloPolycodeApp(PolycodeView *view) : EventHandler() {
 	}
 }
 
+HelloPolycodeApp::~HelloPolycodeApp() {
+}
+
 bool HelloPolycodeApp::Update() {
     return core->Update();
 }

+ 3 - 0
Examples/C++/Contents/3DBasics/HelloPolycodeApp.cpp

@@ -26,6 +26,9 @@ HelloPolycodeApp::HelloPolycodeApp(PolycodeView *view) {
 
 }
 
+HelloPolycodeApp::~HelloPolycodeApp() {
+}
+
 bool HelloPolycodeApp::Update() {
     return core->Update();
 }

+ 3 - 0
Examples/C++/Contents/3DMeshParticles/HelloPolycodeApp.cpp

@@ -75,6 +75,9 @@ HelloPolycodeApp::HelloPolycodeApp(PolycodeView *view) {
 
 }
 
+HelloPolycodeApp::~HelloPolycodeApp() {
+}
+
 bool HelloPolycodeApp::Update() {
     return core->Update();
 }

+ 3 - 0
Examples/C++/Contents/3DParticles/HelloPolycodeApp.cpp

@@ -68,6 +68,9 @@ HelloPolycodeApp::HelloPolycodeApp(PolycodeView *view) {
 	light->lookAt(Vector3(0,0,0));
 }
 
+HelloPolycodeApp::~HelloPolycodeApp() {
+}
+
 bool HelloPolycodeApp::Update() {
     return core->Update();
 }

+ 3 - 0
Examples/C++/Contents/3DPhysics_Basic/HelloPolycodeApp.cpp

@@ -31,6 +31,9 @@ HelloPolycodeApp::HelloPolycodeApp(PolycodeView *view) {
 	
 }
 
+HelloPolycodeApp::~HelloPolycodeApp() {
+}
+
 bool HelloPolycodeApp::Update() {
     return core->Update();
 }

+ 3 - 0
Examples/C++/Contents/3DPhysics_Character/HelloPolycodeApp.cpp

@@ -101,6 +101,9 @@ void HelloPolycodeApp::handleEvent(Event *e) {
 	}
 }
 
+HelloPolycodeApp::~HelloPolycodeApp() {
+}
+
 bool HelloPolycodeApp::Update() {
 	Number elapsed = core->getElapsed();
 	playerDirection += rotateSpeed * elapsed;

+ 3 - 0
Examples/C++/Contents/3DPhysics_CollisionOnly/HelloPolycodeApp.cpp

@@ -35,6 +35,9 @@ HelloPolycodeApp::HelloPolycodeApp(PolycodeView *view) {
 	swingValue = 0;
 }
 
+HelloPolycodeApp::~HelloPolycodeApp() {
+}
+
 bool HelloPolycodeApp::Update() {
 	Number elapsed = core->getElapsed();
 	swingValue += elapsed;

+ 3 - 0
Examples/C++/Contents/3DPhysics_Contacts/HelloPolycodeApp.cpp

@@ -31,6 +31,9 @@ HelloPolycodeApp::HelloPolycodeApp(PolycodeView *view) : EventHandler() {
 	
 }
 
+HelloPolycodeApp::~HelloPolycodeApp() {
+}
+
 void HelloPolycodeApp::handleEvent(Event *event) {
 
 }

+ 3 - 0
Examples/C++/Contents/3DPhysics_RayTest/HelloPolycodeApp.cpp

@@ -44,6 +44,9 @@ HelloPolycodeApp::HelloPolycodeApp(PolycodeView *view) {
 	lastEntity = NULL;
 }
 
+HelloPolycodeApp::~HelloPolycodeApp() {
+}
+
 void HelloPolycodeApp::handleEvent(Event *e) {
 	
 	if(e->getDispatcher() == core->getInput()) {

+ 3 - 0
Examples/C++/Contents/3DPhysics_Vehicle/HelloPolycodeApp.cpp

@@ -148,6 +148,9 @@ void HelloPolycodeApp::handleEvent(Event *e) {
 	}
 }
 
+HelloPolycodeApp::~HelloPolycodeApp() {
+}
+
 bool HelloPolycodeApp::Update() {
 	Number elapsed = core->getElapsed();
 	

+ 3 - 0
Examples/C++/Contents/AdvancedLighting/HelloPolycodeApp.cpp

@@ -63,6 +63,9 @@ HelloPolycodeApp::HelloPolycodeApp(PolycodeView *view) : EventHandler() {
 
 }
 
+HelloPolycodeApp::~HelloPolycodeApp() {
+}
+
 bool HelloPolycodeApp::Update() {
     return core->Update();
 }

+ 3 - 0
Examples/C++/Contents/BasicImage/HelloPolycodeApp.cpp

@@ -16,6 +16,9 @@ HelloPolycodeApp::HelloPolycodeApp(PolycodeView *view) : EventHandler() {
 	screen->addChild(image);	
 }
 
+HelloPolycodeApp::~HelloPolycodeApp() {
+}
+
 bool HelloPolycodeApp::Update() {
     return core->Update();
 }

+ 3 - 0
Examples/C++/Contents/BasicLighting/HelloPolycodeApp.cpp

@@ -30,6 +30,9 @@ HelloPolycodeApp::HelloPolycodeApp(PolycodeView *view) : EventHandler() {
 	scene->getDefaultCamera()->lookAt(Vector3(0,0,0));
 }
 
+HelloPolycodeApp::~HelloPolycodeApp() {
+}
+
 bool HelloPolycodeApp::Update() {
     return core->Update();
 }

+ 3 - 0
Examples/C++/Contents/BasicText/HelloPolycodeApp.cpp

@@ -16,6 +16,9 @@ HelloPolycodeApp::HelloPolycodeApp(PolycodeView *view) : EventHandler() {
 	screen->addChild(label);
 }
 
+HelloPolycodeApp::~HelloPolycodeApp() {
+}
+
 bool HelloPolycodeApp::Update() {
     return core->Update();
 }

+ 3 - 0
Examples/C++/Contents/EventHandling/HelloPolycodeApp.cpp

@@ -19,6 +19,9 @@ HelloPolycodeApp::HelloPolycodeApp(PolycodeView *view) : EventHandler() {
 	screen->addChild(image);	
 }
 
+HelloPolycodeApp::~HelloPolycodeApp() {
+}
+
 void HelloPolycodeApp::handleEvent(Event *e) {
 	if(e->getDispatcher() == rotateTimer && e->getEventCode() == Timer::EVENT_TRIGGER) {
 		image->setRotation(image->getRotation() + 90);

+ 3 - 0
Examples/C++/Contents/KeyboardInput/HelloPolycodeApp.cpp

@@ -23,6 +23,9 @@ HelloPolycodeApp::HelloPolycodeApp(PolycodeView *view) : EventHandler() {
 	
 }
 
+HelloPolycodeApp::~HelloPolycodeApp() {
+}
+
 void HelloPolycodeApp::handleEvent(Event *e) {
 	if(e->getDispatcher() == core->getInput()) {
 		InputEvent *inputEvent = (InputEvent*)e;

+ 3 - 0
Examples/C++/Contents/MouseInput/HelloPolycodeApp.cpp

@@ -21,6 +21,9 @@ HelloPolycodeApp::HelloPolycodeApp(PolycodeView *view) : EventHandler() {
 	core->getInput()->addEventListener(this, InputEvent::EVENT_MOUSEUP);
 }
 
+HelloPolycodeApp::~HelloPolycodeApp() {
+}
+
 void HelloPolycodeApp::handleEvent(Event *e) {
 	
 	if(e->getDispatcher() == core->getInput()) {

+ 3 - 0
Examples/C++/Contents/Networking_Server/HelloPolycodeApp.cpp

@@ -26,6 +26,9 @@ HelloPolycodeApp::HelloPolycodeApp(PolycodeView *view) : ServerWorld(), EventHan
 	server->addEventListener(this, ServerEvent::EVENT_CLIENT_DISCONNECTED);		
 }
 
+HelloPolycodeApp::~HelloPolycodeApp() {
+}
+
 void HelloPolycodeApp::updateWorld(Number elapsed) {
 
 	

+ 3 - 1
Examples/C++/Contents/PlayingSounds/HelloPolycodeApp.cpp

@@ -19,6 +19,9 @@ HelloPolycodeApp::HelloPolycodeApp(PolycodeView *view) : EventHandler() {
 	testSound = new Sound("Resources/test.wav");
 }
 
+HelloPolycodeApp::~HelloPolycodeApp() {
+}
+
 void HelloPolycodeApp::handleEvent(Event *e) {
 	
 	if(e->getDispatcher() == core->getInput()) {
@@ -31,7 +34,6 @@ void HelloPolycodeApp::handleEvent(Event *e) {
 	}	
 }
 
-
 HelloPolycodeApp::~HelloPolycodeApp() {
     
 }

+ 3 - 0
Examples/C++/Contents/ScreenEntities/HelloPolycodeApp.cpp

@@ -34,6 +34,9 @@ HelloPolycodeApp::HelloPolycodeApp(PolycodeView *view) {
 	
 }
 
+HelloPolycodeApp::~HelloPolycodeApp() {
+}
+
 bool HelloPolycodeApp::Update() {
 	Number elapsed = core->getElapsed();
 	planetRotation += elapsed ;

+ 3 - 0
Examples/C++/Contents/ScreenSprites/HelloPolycodeApp.cpp

@@ -21,6 +21,9 @@ HelloPolycodeApp::HelloPolycodeApp(PolycodeView *view) : EventHandler() {
 	sprite->playAnimation("ExampleAnimation", 0, false);
 }
 
+HelloPolycodeApp::~HelloPolycodeApp() {
+}
+
 bool HelloPolycodeApp::Update() {
     return core->Update();
 }

+ 3 - 0
Examples/C++/Contents/SkeletalAnimation/HelloPolycodeApp.cpp

@@ -26,6 +26,9 @@ HelloPolycodeApp::HelloPolycodeApp(PolycodeView *view) : EventHandler() {
 
 }
 
+HelloPolycodeApp::~HelloPolycodeApp() {
+}
+
 bool HelloPolycodeApp::Update() {
     return core->Update();
 }

+ 3 - 0
Examples/C++/Contents/UpdateLoop/HelloPolycodeApp.cpp

@@ -16,6 +16,9 @@ HelloPolycodeApp::HelloPolycodeApp(PolycodeView *view) {
 	screen->addChild(image);	
 }
 
+HelloPolycodeApp::~HelloPolycodeApp() {
+}
+
 bool HelloPolycodeApp::Update() {
 	Number elapsed = core->getElapsed();
 	image->setRotation(image->getRotation()+(elapsed*100));

+ 0 - 1
Modules/Contents/2DPhysics/Include/PolyPhysicsScreen.h

@@ -368,7 +368,6 @@ protected:
 	
 	void init(Number worldScale, Number physicsTimeStep, int physicsIterations, Vector2 physicsGravity);
 
-	Timer *updateTimer;
 	std::vector <PhysicsScreenEntity*> physicsChildren;
 	std::vector<b2Contact*> contacts;
 	b2World *world;

+ 0 - 1
Modules/Contents/2DPhysics/Include/PolyPhysicsScreenEntity.h

@@ -71,7 +71,6 @@ namespace Polycode {
 		
 			b2Fixture *fixture;		
 			b2Body* body;
-			b2BodyDef *bodyDef;
 			b2Shape *shape;
 			
 			bool collisionOnly;

+ 13 - 11
Modules/Contents/2DPhysics/Source/PolyPhysicsScreen.cpp

@@ -173,9 +173,6 @@ void PhysicsScreen::init(Number worldScale, Number physicsTimeStep, int physicsI
 	world  = new b2World(gravity, doSleep);
 	
 	world->SetContactListener(this);
-
-//	updateTimer = new Timer(true, 3);
-//	updateTimer->addEventListener(this, Timer::EVENT_TRIGGER);
 }
 
 void PhysicsScreen::setGravity(Vector2 newGravity) {
@@ -401,8 +398,11 @@ ScreenEntity *PhysicsScreen::getEntityAtPosition(Number x, Number y) {
 	
 	for(int i=0;i<physicsChildren.size();i++) {
 		PhysicsScreenEntity *ent = physicsChildren[i];
-		if(ent->shape->TestPoint(ent->body->GetTransform(), mousePosition))
-			return ent->getScreenEntity();
+		if(ent->shape) {
+			if(ent->shape->TestPoint(ent->body->GetTransform(), mousePosition)) {
+				return ent->getScreenEntity();
+			}
+		}
 	}	
 	return ret;
 }
@@ -417,11 +417,13 @@ bool PhysicsScreen::testEntityAtPosition(ScreenEntity *ent, Number x, Number y)
 	mousePosition.x = x/worldScale;
 	mousePosition.y = y/worldScale;
 	
-	if(pEnt->shape->TestPoint(pEnt->body->GetTransform(), mousePosition))
-		return true;
-	else
-		return false;
-	
+	if(pEnt->shape) {
+		if(pEnt->shape->TestPoint(pEnt->body->GetTransform(), mousePosition))
+			return true;
+		else
+			return false;
+	}
+	return false;
 }
 
 void PhysicsScreen::destroyMouseJoint(b2MouseJoint *mJoint) {
@@ -467,10 +469,10 @@ void PhysicsScreen::Shutdown() {
 }
 
 PhysicsScreen::~PhysicsScreen() {
-	delete world;
 	for(int i=0; i<physicsChildren.size();i++) {
 			delete physicsChildren[i];
 	}
+	delete world;	
 }
 
 PhysicsScreenEntity *PhysicsScreen::getPhysicsEntityByFixture(b2Fixture *fixture) {

+ 11 - 2
Modules/Contents/2DPhysics/Source/PolyPhysicsScreenEntity.cpp

@@ -39,7 +39,9 @@ PhysicsScreenEntity::PhysicsScreenEntity(ScreenEntity *entity, b2World *world, N
 	
 	screenEntity = entity;
 	
-	bodyDef = new b2BodyDef();
+	shape = NULL;
+		
+	b2BodyDef *bodyDef = new b2BodyDef();	
 	bodyDef->position.Set(screenEntity->getPosition().x/worldScale, screenEntity->getPosition().y/worldScale);
 	bodyDef->angle = screenEntity->getRotation()*(PI/180.0f);	
 	bodyDef->bullet = isSensor;	
@@ -51,6 +53,7 @@ PhysicsScreenEntity::PhysicsScreenEntity(ScreenEntity *entity, b2World *world, N
 		bodyDef->type = b2_dynamicBody;	
 	}
 	body = world->CreateBody(bodyDef);
+	delete bodyDef;
 		
 	b2FixtureDef fDef;
 	fDef.friction = friction;
@@ -163,5 +166,11 @@ void PhysicsScreenEntity::Update() {
 }
 
 PhysicsScreenEntity::~PhysicsScreenEntity() {
-
+	if (body) {
+		if (fixture) {	
+			body->DestroyFixture(fixture);
+		}	
+		body->GetWorld()->DestroyBody(body);	
+	}
+	delete shape;
 }