Просмотр исходного кода

Merged in a bunch of mcclure's memory leak fixes

Ivan Safrin 13 лет назад
Родитель
Сommit
8666e09cbe
55 измененных файлов с 176 добавлено и 93 удалено
  1. 0 1
      Bindings/Scripts/create_lua_library/create_lua_library.py
  2. 1 1
      Core/Contents/Include/PolyBezierCurve.h
  3. 1 1
      Core/Contents/Include/PolyBone.h
  4. 1 1
      Core/Contents/Include/PolyCamera.h
  5. 1 1
      Core/Contents/Include/PolyColor.h
  6. 1 1
      Core/Contents/Include/PolyCubemap.h
  7. 7 2
      Core/Contents/Include/PolyEntity.h
  8. 1 1
      Core/Contents/Include/PolyEvent.h
  9. 1 1
      Core/Contents/Include/PolyEventHandler.h
  10. 1 1
      Core/Contents/Include/PolyFixedShader.h
  11. 1 1
      Core/Contents/Include/PolyFont.h
  12. 1 1
      Core/Contents/Include/PolyGLSLProgram.h
  13. 1 1
      Core/Contents/Include/PolyImage.h
  14. 1 1
      Core/Contents/Include/PolyInputEvent.h
  15. 1 1
      Core/Contents/Include/PolyLabel.h
  16. 1 1
      Core/Contents/Include/PolyMesh.h
  17. 1 1
      Core/Contents/Include/PolyObject.h
  18. 2 2
      Core/Contents/Include/PolyParticleEmitter.h
  19. 1 1
      Core/Contents/Include/PolyPolygon.h
  20. 1 1
      Core/Contents/Include/PolyQuaternionCurve.h
  21. 6 1
      Core/Contents/Include/PolyScene.h
  22. 1 1
      Core/Contents/Include/PolySceneLabel.h
  23. 1 1
      Core/Contents/Include/PolySceneLine.h
  24. 13 2
      Core/Contents/Include/PolySceneMesh.h
  25. 1 1
      Core/Contents/Include/PolySceneRenderTexture.h
  26. 6 1
      Core/Contents/Include/PolyScreen.h
  27. 1 1
      Core/Contents/Include/PolyScreenCurve.h
  28. 1 1
      Core/Contents/Include/PolyScreenEntity.h
  29. 1 1
      Core/Contents/Include/PolyScreenEvent.h
  30. 1 1
      Core/Contents/Include/PolyScreenImage.h
  31. 1 1
      Core/Contents/Include/PolyScreenLabel.h
  32. 1 1
      Core/Contents/Include/PolyScreenLine.h
  33. 1 1
      Core/Contents/Include/PolyScreenMesh.h
  34. 1 1
      Core/Contents/Include/PolyScreenSprite.h
  35. 1 1
      Core/Contents/Include/PolySkeleton.h
  36. 1 1
      Core/Contents/Include/PolySound.h
  37. 1 1
      Core/Contents/Include/PolyThreaded.h
  38. 1 1
      Core/Contents/Include/PolyTimer.h
  39. 1 1
      Core/Contents/Include/PolyTween.h
  40. 6 0
      Core/Contents/Include/PolyVector3.h
  41. 5 3
      Core/Contents/Source/OSBasics.cpp
  42. 1 0
      Core/Contents/Source/PolyCocoaCore.mm
  43. 6 0
      Core/Contents/Source/PolyEntity.cpp
  44. 1 1
      Core/Contents/Source/PolyFont.cpp
  45. 1 0
      Core/Contents/Source/PolyGLSLShaderModule.cpp
  46. 6 8
      Core/Contents/Source/PolyImage.cpp
  47. 11 11
      Core/Contents/Source/PolyScene.cpp
  48. 14 7
      Core/Contents/Source/PolySceneMesh.cpp
  49. 7 2
      Core/Contents/Source/PolyScreen.cpp
  50. 5 0
      Core/Contents/Source/PolyScreenLabel.cpp
  51. 10 0
      Core/Contents/Source/PolySkeleton.cpp
  52. 4 0
      Core/Contents/Source/PolyVector3.cpp
  53. 8 3
      Modules/Contents/3DPhysics/Include/PolyCollisionScene.h
  54. 21 15
      Modules/Contents/3DPhysics/Source/PolyCollisionScene.cpp
  55. 3 1
      Modules/Contents/3DPhysics/Source/PolyCollisionSceneEntity.cpp

+ 0 - 1
Bindings/Scripts/create_lua_library/create_lua_library.py

@@ -54,7 +54,6 @@ def createLUABindings(inputPath, prefix, mainInclude, libSmallName, libName, api
 		out += "class LuaEventHandler : public EventHandler {\n"
 		out += "public:\n"
 		out += "	LuaEventHandler() : EventHandler() {}\n"
-		out += "	~LuaEventHandler();\n"
 		out += "	void handleEvent(Event *e) {\n"
 		out += "		lua_rawgeti( L, LUA_REGISTRYINDEX, wrapperIndex );\n"
 		out += "		lua_getfield(L, -1, \"__handleEvent\");\n"

+ 1 - 1
Core/Contents/Include/PolyBezierCurve.h

@@ -81,7 +81,7 @@ namespace Polycode {
 			* Default constructor.
 			*/
 			BezierCurve();
-			~BezierCurve();
+			virtual ~BezierCurve();
 
 		/**
 		* Returns a control point by index.

+ 1 - 1
Core/Contents/Include/PolyBone.h

@@ -41,7 +41,7 @@ namespace Polycode {
 			* @param boneName Name of the bone.
 			*/				
 			Bone(const String& boneName);
-			~Bone();
+			virtual ~Bone();
 			
 			void enableBoneLabel(const String& labelFont, Number size, Number scale, Color labelColor);
 			

+ 1 - 1
Core/Contents/Include/PolyCamera.h

@@ -43,7 +43,7 @@ namespace Polycode {
 			* @param parentScene Scene to add the camera to.
 			*/
 			Camera(Scene *parentScene);
-			~Camera();
+			virtual ~Camera();
 			
 			void buildFrustrumPlanes();
 			

+ 1 - 1
Core/Contents/Include/PolyColor.h

@@ -67,7 +67,7 @@ namespace Polycode {
 			*/															
 			Color(unsigned int hex);
 		
-			~Color();
+			virtual ~Color();
 			
 			/** 
 			* Multiplies the color with another color.

+ 1 - 1
Core/Contents/Include/PolyCubemap.h

@@ -31,7 +31,7 @@ namespace Polycode {
 	class _PolyExport Cubemap : public Resource {
 		public:
 			Cubemap(Texture *t0, Texture *t1, Texture *t2, Texture *t3, Texture *t4, Texture *t5);
-			~Cubemap();	
+			virtual ~Cubemap();	
 		
 		protected:		
 		

+ 7 - 2
Core/Contents/Include/PolyEntity.h

@@ -44,7 +44,7 @@ namespace Polycode {
 	class _PolyExport Entity {
 		public:
 			Entity();
-			~Entity();
+			virtual ~Entity();
 
 			/**
 			* Main render method. Override this to do your own drawing.
@@ -170,6 +170,11 @@ namespace Polycode {
 			* @return Child entity at specified index or NULL of index out of range.
 			*/			
 			Entity *getChildAtIndex(unsigned int index);
+			
+			/**
+			* If set to true, will automatically delete children upon destruction. (defaults to false).
+			*/ 
+			bool ownsChildren;										
 				
 			//@}
 			// ----------------------------------------------------------------------------------------------------------------
@@ -580,7 +585,7 @@ namespace Polycode {
 			void setBlendingMode(int newBlendingMode);
 				
 			Vector3 getChildCenter() const;
-							
+			
 			std::vector <EntityProp> entityProps;
 			String getEntityProp(const String& propName);
 			

+ 1 - 1
Core/Contents/Include/PolyEvent.h

@@ -43,7 +43,7 @@ namespace Polycode {
 			* @param eventCode Event code to initalize with.
 			*/ 			
 			Event(int eventCode);
-			~Event();
+			virtual ~Event();
 			
 			/**
 			* Returns the event code for this event.

+ 1 - 1
Core/Contents/Include/PolyEventHandler.h

@@ -35,7 +35,7 @@ namespace Polycode {
 			* Default constructor
 			*/
 			EventHandler();
-			~EventHandler();
+			virtual ~EventHandler();
 
 		void secondaryHandler(Event *event);		
 		

+ 1 - 1
Core/Contents/Include/PolyFixedShader.h

@@ -32,7 +32,7 @@ namespace Polycode {
 	class _PolyExport FixedShader : public Shader {
 		public:
 			FixedShader();
-			~FixedShader();
+			virtual ~FixedShader();
 			
 			ShaderBinding *createBinding();
 

+ 1 - 1
Core/Contents/Include/PolyFont.h

@@ -32,7 +32,7 @@ namespace Polycode {
 	class _PolyExport Font {
 		public:
 			Font(const String& fileName);
-			~Font();
+			virtual ~Font();
 			
 			FT_Face getFace();
 			bool isValid() const;

+ 1 - 1
Core/Contents/Include/PolyGLSLProgram.h

@@ -92,7 +92,7 @@ class _PolyExport GLSLProgramParam {
 	class _PolyExport GLSLProgram : public Resource {
 		public:
 			GLSLProgram(int type);
-			~GLSLProgram();
+			virtual ~GLSLProgram();
 			
 			void addParam(const String& name, bool isAuto, int autoID, int paramType, void *defaultData);
 		

+ 1 - 1
Core/Contents/Include/PolyImage.h

@@ -63,7 +63,7 @@ namespace Polycode {
 			*/ 						
 			Image(Image *copyImage);		
 			Image();			
-			~Image();
+			virtual ~Image();
 
 			/**
 			* Load an image from a file

+ 1 - 1
Core/Contents/Include/PolyInputEvent.h

@@ -43,7 +43,7 @@ namespace Polycode {
 			InputEvent(Vector2 mousePosition,int timestamp);
 //			InputEvent(PolyKEY key, int timestamp);
 			InputEvent(PolyKEY key, wchar_t charCode, int timestamp);			
-			~InputEvent();
+			virtual ~InputEvent();
 		
 			// ----------------------------------------------------------------------------------------------------------------
 			/** @name Input event types.

+ 1 - 1
Core/Contents/Include/PolyLabel.h

@@ -35,7 +35,7 @@ namespace Polycode {
 		public:
 			
 			Label(Font *font, const String& text, int size, int antiAliasMode);
-			~Label();
+			virtual ~Label();
 			void setText(const String& text);
 			const String& getText() const;
 			

+ 1 - 1
Core/Contents/Include/PolyMesh.h

@@ -129,7 +129,7 @@ namespace Polycode {
 			*/
 			Mesh(const String& fileName);
 
-			~Mesh();
+			virtual ~Mesh();
 			
 			/**
 			* Adds a polygon to the mesh.

+ 1 - 1
Core/Contents/Include/PolyObject.h

@@ -196,7 +196,7 @@ namespace Polycode {
 		* Default constructor
 		*/	
 		Object();
-		~Object();
+		virtual ~Object();
 		
 		/**
 		* Loads data from XML file into the object. 

+ 2 - 2
Core/Contents/Include/PolyParticleEmitter.h

@@ -263,7 +263,7 @@ namespace Polycode {
 		* @param emitter If this is specified, particles will be emitted from this meshe's vertices.
 		*/
 		SceneParticleEmitter(const String& materialName, Scene *particleParentScene, int particleType, int emitterType, Number lifespan, unsigned int numParticles, Vector3 direction, Vector3 gravity, Vector3 deviation, Vector3 emitterRadius, Mesh *particleMesh = NULL, SceneMesh *emitter = NULL);
-		~SceneParticleEmitter();		
+		virtual ~SceneParticleEmitter();		
 		
 		/**
 		* Returns the emitter (helper method for LUA).
@@ -288,7 +288,7 @@ namespace Polycode {
 	class _PolyExport ScreenParticleEmitter : public ScreenEntity, public ParticleEmitter {
 	public:
 		ScreenParticleEmitter(const String& imageFile, Screen *particleParentScreen, int particleType, int emitterType, Number lifespan, unsigned int numParticles, Vector3 direction, Vector3 gravity, Vector3 deviation, Vector3 emitterRadius, Mesh *particleMesh = NULL, ScreenMesh *emitter = NULL);
-		~ScreenParticleEmitter();		
+		virtual ~ScreenParticleEmitter();		
 		
 		/**
 		* Returns the emitter (helper method for LUA).

+ 1 - 1
Core/Contents/Include/PolyPolygon.h

@@ -40,7 +40,7 @@ namespace Polycode {
 			* Default constructor.
 			*/
 			Polygon();
-			~Polygon();
+			virtual ~Polygon();
 			
 			/**
 			* Returns the number of vertices in the polygon.

+ 1 - 1
Core/Contents/Include/PolyQuaternionCurve.h

@@ -39,7 +39,7 @@ namespace Polycode {
 	class _PolyExport QuaternionCurve {
 		public:
 			QuaternionCurve(BezierCurve *wCurve, BezierCurve *xCurve, BezierCurve *yCurve, BezierCurve *zCurve);
-			~QuaternionCurve();
+			virtual ~QuaternionCurve();
 		
 			Quaternion interpolate(Number t, bool useShortestPath);
 			Quaternion interpolate(unsigned int fromIndex, Number t, bool useShortestPath);

+ 6 - 1
Core/Contents/Include/PolyScene.h

@@ -190,7 +190,12 @@ namespace Polycode {
 		/**
 		* If this is set to false, the scene is not rendered or updated during the render loop.
 		*/
-		bool enabled;		
+		bool enabled;
+		
+		/**
+		* If ownsChildren is set to true, the scene will delete its children upon destruction (defaults to false).
+		*/
+		bool ownsChildren;
 		
 	protected:
 		

+ 1 - 1
Core/Contents/Include/PolySceneLabel.h

@@ -47,7 +47,7 @@ namespace Polycode {
 			* @param Anti-aliasing mode. Can be Label::ANTIALIAS_FULL or Label::ANTIALIAS_NONE.
 			*/			
 			SceneLabel(const String& fontName, const String& text, int size, Number scale, int amode);
-			~SceneLabel();			
+			virtual ~SceneLabel();			
 		
 			/**
 			* Sets new text for the labe.

+ 1 - 1
Core/Contents/Include/PolySceneLine.h

@@ -41,7 +41,7 @@ namespace Polycode {
 			*/
 			SceneLine(SceneEntity *ent1, SceneEntity *ent2);
 			SceneLine(Vector3 start, Vector3 end);
-			~SceneLine();
+			virtual ~SceneLine();
 			
 			void setStart(Vector3 start);
 			void setEnd(Vector3 end);

+ 13 - 2
Core/Contents/Include/PolySceneMesh.h

@@ -133,9 +133,20 @@ namespace Polycode {
 			unsigned int lightmapIndex;
 			
 			bool showVertexNormals;
-			
+	
+					
 			Number lineWidth;
-			bool lineSmooth;	
+			bool lineSmooth;
+			
+			/**
+			* If true, will delete its Mesh upon destruction. (defaults to true)
+			*/ 
+			bool ownsMesh;
+
+			/**
+			* If true, will delete its Skeleton upon destruction. (defaults to true)
+			*/ 			
+			bool ownsSkeleton;
 		
 		protected:
 		

+ 1 - 1
Core/Contents/Include/PolySceneRenderTexture.h

@@ -43,7 +43,7 @@ namespace Polycode {
 			* @param floatingPoint Pass true if you want fp16 target renders			
 			*/
 			SceneRenderTexture(Scene *targetScene, Camera *targetCamera, int renderWidth,int renderHeight, bool floatingPoint = false);
-			~SceneRenderTexture();
+			virtual ~SceneRenderTexture();
 			
 			void drawScreen();
 			

+ 6 - 1
Core/Contents/Include/PolyScreen.h

@@ -46,7 +46,7 @@ namespace Polycode {
 		* Default constructor.
 		*/
 		Screen();
-		~Screen();
+		virtual ~Screen();
 		
 		/**
 		* Adds a ScreenEntity to the 2d rendering pipeline.
@@ -151,6 +151,11 @@ namespace Polycode {
 		*/		
 		bool processTouchEventsAsMouse;
 		
+		/**
+		* If ownsChildren is set to true, the scene will delete its children upon destruction (defaults to false).
+		*/
+		bool ownsChildren;		
+		
 	protected:
 		
 		bool useNormalizedCoordinates;

+ 1 - 1
Core/Contents/Include/PolyScreenCurve.h

@@ -31,7 +31,7 @@ namespace Polycode {
 	class _PolyExport ScreenCurve : public ScreenShape {
 		public:
 			ScreenCurve(BezierCurve *curve, int numVertices);
-			~ScreenCurve();
+			virtual ~ScreenCurve();
 			
 		protected:
 		

+ 1 - 1
Core/Contents/Include/PolyScreenEntity.h

@@ -42,7 +42,7 @@ class _PolyExport ScreenEntity : public Entity, public EventDispatcher {
 		using Entity::setScale;		
 	
 		ScreenEntity();
-		~ScreenEntity();
+		virtual ~ScreenEntity();
 		
 		/**
 		* Set 2d position.

+ 1 - 1
Core/Contents/Include/PolyScreenEvent.h

@@ -31,7 +31,7 @@ namespace Polycode {
 	class _PolyExport ScreenEvent : public Event {
 		public:
 			ScreenEvent();
-			~ScreenEvent();
+			virtual ~ScreenEvent();
 		
 			static const int ENTITY_MOVE_TOP = 0;
 			static const int ENTITY_MOVE_BOTTOM = 1;

+ 1 - 1
Core/Contents/Include/PolyScreenImage.h

@@ -42,7 +42,7 @@ namespace Polycode {
 		* @param image Image to create from.
 		*/		
 		ScreenImage(Image *image);		
-		~ScreenImage();
+		virtual ~ScreenImage();
 		
 		/**
 		* Changes which part of the image is displayed.

+ 1 - 1
Core/Contents/Include/PolyScreenLabel.h

@@ -43,7 +43,7 @@ namespace Polycode {
 			* @param Anti-aliasing mode.
 			*/
 			ScreenLabel(const String& text, int size, const String& fontName = "sans", int amode = 0);
-			~ScreenLabel();		
+			virtual ~ScreenLabel();		
 		
 			/**
 			* Adds a drop shadow to the label.

+ 1 - 1
Core/Contents/Include/PolyScreenLine.h

@@ -46,7 +46,7 @@ namespace Polycode {
 			* @target2 Ending target.
 			*/			
 			ScreenLine(ScreenEntity* target1, ScreenEntity* target2);
-			~ScreenLine();
+			virtual ~ScreenLine();
 			
 
 			void Update();

+ 1 - 1
Core/Contents/Include/PolyScreenMesh.h

@@ -51,7 +51,7 @@ namespace Polycode {
 			* Create an empty screen mesh of specified type. See Mesh for available mesh types.
 			*/
 			ScreenMesh(int meshType);
-			~ScreenMesh();
+			virtual ~ScreenMesh();
 			
 			void Render();
 			

+ 1 - 1
Core/Contents/Include/PolyScreenSprite.h

@@ -49,7 +49,7 @@ class _PolyExport ScreenSprite : public ScreenShape
 		* @param spriteWidth Pixel height of each sprite cell.		
 		*/
 		ScreenSprite(const String& fileName, Number spriteWidth, Number spriteHeight);
-		~ScreenSprite();
+		virtual ~ScreenSprite();
 		
 		/**
 		* Adds a new animation to the sprite. Animations are added by specifying a list of frame indexes and then can be played back by the specified name.

+ 1 - 1
Core/Contents/Include/PolySkeleton.h

@@ -149,7 +149,7 @@ namespace Polycode {
 			*/ 
 			void loadSkeleton(const String& fileName);
 			
-			~Skeleton();
+			virtual ~Skeleton();
 		
 			/**
 			* Play back a loaded animation.

+ 1 - 1
Core/Contents/Include/PolySound.h

@@ -53,7 +53,7 @@ namespace Polycode {
 		*/ 
 		Sound(const String& fileName);
 		Sound(const char *data, int size, int channels = 1, ALsizei freq = 44100, int bps = 16);
-		~Sound();
+		virtual ~Sound();
 		
 		/**
 		* Play the sound once or in a loop.

+ 1 - 1
Core/Contents/Include/PolyThreaded.h

@@ -34,7 +34,7 @@ namespace Polycode{
 	class _PolyExport Threaded {
 	public:
 		Threaded(){ threadRunning = true; }
-		~Threaded(){}
+		virtual ~Threaded(){}
 		
 		/**
 		* Sets the thread running flag to false.

+ 1 - 1
Core/Contents/Include/PolyTimer.h

@@ -38,7 +38,7 @@ namespace Polycode {
 			* @param msecs Timer frequency in milliseconds.
 			*/
 			Timer(bool triggerMode, int msecs);
-			~Timer();
+			virtual ~Timer();
 
 		/** 
 		* Pauses and resumes the timer.

+ 1 - 1
Core/Contents/Include/PolyTween.h

@@ -48,7 +48,7 @@ namespace Polycode {
 		* @param repeat If true, this tween will repeat over and over.
 		*/
 		Tween(Number *target, int easeType, Number startVal, Number endVal, Number time, bool repeat=false, bool deleteOnComplete=false);
-		~Tween();
+		virtual ~Tween();
 		
 		void handleEvent(Event *event);
 		Number interpolateTween();

+ 6 - 0
Core/Contents/Include/PolyVector3.h

@@ -43,6 +43,12 @@ namespace Polycode {
 			* @param z Z coordinate.						
 			*/					
 			Vector3(Number x,Number y,Number z);		
+
+			/**
+			* Create from single value for all coordinates
+			* @param val Value for all coordinates
+			*/					
+			Vector3(Number val);
 			
 			/**
 			* Default constructor.

+ 5 - 3
Core/Contents/Source/OSBasics.cpp

@@ -130,15 +130,17 @@ OSFILE *OSBasics::open(const String& filename, const String& opts) {
 }
 
 int OSBasics::close(OSFILE *file) {
+	int result = 0;
 	switch(file->fileType) {
 		case OSFILE::TYPE_FILE:
-			return fclose(file->file);
+			result = fclose(file->file);
 			break;
 		case OSFILE::TYPE_ARCHIVE_FILE:
-			return PHYSFS_close(file->physFSFile);
+			result = PHYSFS_close(file->physFSFile);
 			break;			
 	}
-	return 0;
+	delete file;
+	return result;
 }
 
 long OSBasics::tell(OSFILE * stream) {

+ 1 - 0
Core/Contents/Source/PolyCocoaCore.mm

@@ -105,6 +105,7 @@ CocoaCore::CocoaCore(PolycodeView *view, int xRes, int yRes, bool fullScreen, bo
 	}
 	
 	context = [[NSOpenGLContext alloc] initWithFormat: format shareContext:nil];
+	[format release];
 
 	if (context == nil) {
         NSLog(@"Failed to create open gl context");

+ 6 - 0
Core/Contents/Source/PolyEntity.cpp

@@ -54,6 +54,7 @@ Entity::Entity() {
 	maskEntity = NULL;
 	isMask = false;
 	hasMask = false;
+	ownsChildren = false;
 }
 
 void Entity::setUserData(void *userData) {
@@ -186,6 +187,11 @@ void Entity::setBBoxRadius(Number rad) {
 }
 
 Entity::~Entity() {
+	if(ownsChildren) {
+		for(int i=0; i < children.size(); i++) {	
+			delete children[i];
+		}
+	}
 }
 
 Vector3 Entity::getChildCenter() const {

+ 1 - 1
Core/Contents/Source/PolyFont.cpp

@@ -40,7 +40,7 @@ Font::Font(const String& fileName) {
 		buffer = (unsigned char*)malloc(progsize);
 		memset(buffer, 0, progsize);
 		OSBasics::read(buffer, progsize, 1, file);
-	
+		OSBasics::close(file);
 		valid = true;
 		if(FT_New_Memory_Face(FTLibrary, buffer, progsize, 0, &ftFace) != 0) {
 			Logger::log("Error loading font %s\n", fileName.c_str());

+ 1 - 0
Core/Contents/Source/PolyGLSLShaderModule.cpp

@@ -825,6 +825,7 @@ void GLSLShaderModule::recreateGLSLProgram(GLSLProgram *prog, const String& file
 	char *buffer = (char*)malloc(progsize+1);
 	memset(buffer, 0, progsize+1);
 	OSBasics::read(buffer, progsize, 1, file);
+	OSBasics::close(file);
 	
 	if(type == GLSLProgram::TYPE_VERT) {
 		prog->program =  glCreateShader(GL_VERTEX_SHADER);

+ 6 - 8
Core/Contents/Source/PolyImage.cpp

@@ -94,8 +94,7 @@ Image::Image() {
 }
 
 Image::~Image() {
-	if(imageData != NULL)
-		free(imageData);
+	free(imageData);
 }
 
 char *Image::getPixels() {
@@ -149,8 +148,7 @@ unsigned int Image::getHeight() const {
 }
 
 void Image::createEmpty(unsigned int width, unsigned int height) {
-	if(imageData != NULL)
-		free(imageData);
+	free(imageData);
 		
 	imageData = (char*)malloc(width*height*pixelSize);
 	this->width = width;
@@ -160,13 +158,13 @@ void Image::createEmpty(unsigned int width, unsigned int height) {
 }
 
 void Image::perlinNoise(int seed, bool alpha) {
-	Perlin *perlin = new Perlin(12,33,1,seed);
+	Perlin perlin = Perlin(12,33,1,seed);
 	unsigned int *imageData32 = (unsigned int*)imageData;
 	Color pixelColor;
 	Number noiseVal;
 	
 	for(int i=0; i < width*height;i++) {
-			noiseVal = fabs(1.0f/perlin->Get( 0.1+(0.9f/((Number)width)) * (i%width), (1.0f/((Number)height)) *   (i - (i%width))));
+			noiseVal = fabs(1.0f/perlin.Get( 0.1+(0.9f/((Number)width)) * (i%width), (1.0f/((Number)height)) *   (i - (i%width))));
 			if(alpha)
 				pixelColor.setColor(noiseVal, noiseVal, noiseVal, noiseVal);
 			else
@@ -480,8 +478,8 @@ void Image::line(int x0, int y0, int x1, int y1, Color col) {
 }
 
 void Image::fill(Number r, Number g, Number b, Number a) {
-	Color *color = new Color(r,g,b,a);
-	unsigned int val = color->getUint();
+	Color color = Color(r,g,b,a);
+	unsigned int val = color.getUint();
 	unsigned int *imageData32 = (unsigned int*) imageData;
 	for(int i=0; i< width*height; i++) {
 		imageData32[i] = val;

+ 11 - 11
Core/Contents/Source/PolyScene.cpp

@@ -45,24 +45,24 @@ Scene::Scene() : EventDispatcher() {
 	lightingEnabled = false;
 	enabled = true;
 	isSceneVirtual = false;
-	
 	hasLightmaps = false;
 	clearColor.setColor(0.13f,0.13f,0.13f,1.0f); 
 	ambientColor.setColor(0.0,0.0,0.0,1.0);
-	useClearColor = false;	
+	useClearColor = false;
+	ownsChildren = false;	
 }
 
-Scene::Scene(bool virtualScene) {
+Scene::Scene(bool virtualScene) : EventDispatcher() {
 	defaultCamera = new Camera(this);
 	activeCamera = defaultCamera;	
 	fogEnabled = false;
 	lightingEnabled = false;
 	enabled = true;
-	isSceneVirtual = virtualScene;
-	
+	isSceneVirtual = virtualScene;	
 	hasLightmaps = false;
 	clearColor.setColor(0.13f,0.13f,0.13f,1.0f); 
-	useClearColor = false;	
+	useClearColor = false;
+	ownsChildren = false;
 }
 
 void Scene::setActiveCamera(Camera *camera) {
@@ -94,13 +94,13 @@ void Scene::Update() {
 }
 
 Scene::~Scene() {
-	Logger::log("Cleaning scene...\n");
-	for(int i=0; i < entities.size(); i++) {	
-//		delete entities[i];
+	if(ownsChildren) {
+		for(int i=0; i < entities.size(); i++) {	
+			delete entities[i];
+		}
 	}
-	entities.clear();	
 	CoreServices::getInstance()->getSceneManager()->removeScene(this);	
-//	delete defaultCamera;
+	delete defaultCamera;
 }
 
 void Scene::enableLighting(bool enable) {

+ 14 - 7
Core/Contents/Source/PolySceneMesh.cpp

@@ -35,40 +35,43 @@
 
 using namespace Polycode;
 
-SceneMesh::SceneMesh(const String& fileName) : SceneEntity(), texture(NULL), material(NULL) {
+SceneMesh::SceneMesh(const String& fileName) : SceneEntity(), texture(NULL), material(NULL), skeleton(NULL), localShaderOptions(NULL) {
 	mesh = new Mesh(fileName);
 	bBoxRadius = mesh->getRadius();
 	bBox = mesh->calculateBBox();
-	skeleton = NULL;
 	lightmapIndex=0;
 	showVertexNormals = false;
 	useVertexBuffer = false;
 	lineSmooth = false;
+	ownsMesh = true;
+	ownsSkeleton = true;
 	lineWidth = 1.0;
 }
 
-SceneMesh::SceneMesh(Mesh *mesh) : SceneEntity(), texture(NULL), material(NULL) {
+SceneMesh::SceneMesh(Mesh *mesh) : SceneEntity(), texture(NULL), material(NULL), skeleton(NULL), localShaderOptions(NULL) {
 	this->mesh = mesh;
 	bBoxRadius = mesh->getRadius();
 	bBox = mesh->calculateBBox();
-	skeleton = NULL;
 	lightmapIndex=0;
 	showVertexNormals = false;	
 	useVertexBuffer = false;
 	lineSmooth = false;
+	ownsMesh = true;
+	ownsSkeleton = true;	
 	lineWidth = 1.0;
 		
 }
 
-SceneMesh::SceneMesh(int meshType) : texture(NULL), material(NULL) {
+SceneMesh::SceneMesh(int meshType) : texture(NULL), material(NULL), skeleton(NULL), localShaderOptions(NULL) {
 	mesh = new Mesh(meshType);
 	bBoxRadius = mesh->getRadius();
 	bBox = mesh->calculateBBox();
-	skeleton = NULL;
 	lightmapIndex=0;
 	showVertexNormals = false;	
 	useVertexBuffer = false;	
 	lineSmooth = false;
+	ownsMesh = true;
+	ownsSkeleton = true;	
 	lineWidth = 1.0;	
 }
 
@@ -82,7 +85,11 @@ void SceneMesh::setMesh(Mesh *mesh) {
 
 
 SceneMesh::~SceneMesh() {
-	delete mesh;
+	if(ownsSkeleton)
+		delete skeleton;
+	if(ownsMesh)
+		delete mesh;	
+	delete localShaderOptions;
 }
 
 Mesh *SceneMesh::getMesh() {

+ 7 - 2
Core/Contents/Source/PolyScreen.cpp

@@ -47,11 +47,16 @@ Screen::Screen() : EventDispatcher() {
 	rootEntity = new ScreenEntity();
 	addChild(rootEntity);
 	processTouchEventsAsMouse = false;
+	ownsChildren = false;
 }
 
 Screen::~Screen() {
-	for(int i=0; i<children.size();i++) {
-		//	delete children[i];
+	if(ownsChildren) {
+		for(int i=0; i < children.size(); i++) {	
+			delete children[i];
+		}
+	} else {
+		delete rootEntity;
 	}
 	CoreServices::getInstance()->getScreenManager()->removeScreen(this);	
 }

+ 5 - 0
Core/Contents/Source/PolyScreenLabel.cpp

@@ -34,6 +34,7 @@ using namespace Polycode;
 
 ScreenLabel::ScreenLabel(const String& text, int size, const String& fontName, int amode) : ScreenShape(ScreenShape::SHAPE_RECT,1,1) {
 	label = new Label(CoreServices::getInstance()->getFontManager()->getFontByName(fontName), text, size, amode);
+	dropShadowImage = NULL;
 	texture = NULL;
 	setText(text);		
 	mesh->getPolygon(0)->flipUVY();	
@@ -43,6 +44,8 @@ ScreenLabel::ScreenLabel(const String& text, int size, const String& fontName, i
 }
 
 ScreenLabel::~ScreenLabel() {
+	delete label;
+	delete dropShadowImage;
 }
 
 Label *ScreenLabel::getLabel() const {
@@ -50,9 +53,11 @@ Label *ScreenLabel::getLabel() const {
 }
 
 void ScreenLabel::addDropShadow(Color color, Number size, Number offsetX, Number offsetY) {
+	delete dropShadowImage;
 	Image *labelImage = new Image(label);
 	labelImage->fastBlur(size);
 	dropShadowImage = new ScreenImage(labelImage);	
+	delete labelImage;
 	addChild(dropShadowImage);
 	dropShadowImage->setColor(color);
 	dropShadowImage->setPositionMode(POSITION_TOPLEFT);

+ 10 - 0
Core/Contents/Source/PolySkeleton.cpp

@@ -375,6 +375,16 @@ BoneTrack::BoneTrack(Bone *bone, Number length) {
 }
 
 BoneTrack::~BoneTrack() {
+	delete scaleX;
+	delete scaleY;
+	delete scaleZ;
+	delete QuatW;
+	delete QuatX;
+	delete QuatY;
+	delete QuatZ;
+	delete LocX;
+	delete LocY;
+	delete LocZ;
 }
 
 

+ 4 - 0
Core/Contents/Source/PolyVector3.cpp

@@ -39,6 +39,10 @@ Vector3::Vector3(Number x,Number y,Number z) {
 	set(x,y,z);
 }
 
+Vector3::Vector3(Number val) {
+	set(val,val,val);
+}
+
 void Vector3::Normalize() {
 	Number tL = sqrtf( x * x + y * y + z * z );
 	if(tL > 1e-08 ) {

+ 8 - 3
Modules/Contents/3DPhysics/Include/PolyCollisionScene.h

@@ -24,6 +24,7 @@ THE SOFTWARE.
 #include "PolyGlobals.h"
 #include "PolyScene.h"
 #include "PolyVector3.h"
+#include "btBulletCollisionCommon.h"
 #include <vector>
 
 class btCollisionObject;
@@ -86,11 +87,11 @@ struct CollisionResult {
 			/**
 			* Creates a collision scene.
 			*/
-			CollisionScene();
-			CollisionScene(bool virtualScene);		
+			CollisionScene(Vector3 size = Vector3(2000));
+			CollisionScene(bool virtualScene, Vector3 size = Vector3(2000));		
 			virtual ~CollisionScene();
 		
-			void initCollisionScene();
+			void initCollisionScene(Vector3 size);
 		
 			virtual void Update();
 			
@@ -123,6 +124,10 @@ struct CollisionResult {
 		
 			std::vector<CollisionSceneEntity*> collisionChildren;
 			btCollisionWorld *world;
+			
+			btDefaultCollisionConfiguration *collisionConfiguration;
+			btCollisionDispatcher *dispatcher;
+			btAxisSweep3 *broadphase;
 	};
 
 }

+ 21 - 15
Modules/Contents/3DPhysics/Source/PolyCollisionScene.cpp

@@ -21,29 +21,28 @@ THE SOFTWARE.
 */
 
 #include "PolyCollisionScene.h"
-#include "btBulletCollisionCommon.h"
 #include "PolyCollisionSceneEntity.h"
 #include "PolySceneEntity.h"
 
 using namespace Polycode;
 
-CollisionScene::CollisionScene() : Scene() {
-	initCollisionScene();
+CollisionScene::CollisionScene(Vector3 size) : Scene() {
+	initCollisionScene(size);
 }
 
-CollisionScene::CollisionScene(bool virtualScene) : Scene(virtualScene) { 
-	initCollisionScene();
+CollisionScene::CollisionScene(bool virtualScene, Vector3 size) : Scene(virtualScene) { 
+	initCollisionScene(size);
 }
 
-void CollisionScene::initCollisionScene() {
+void CollisionScene::initCollisionScene(Vector3 size) {
 	
-	btVector3	worldAabbMin(-1000,-1000,-1000);
-	btVector3	worldAabbMax(1000,1000,1000);
+	btVector3	worldAabbMin(-size.x * 0.5, -size.y * 0.5, -size.z * 0.5);
+	btVector3	worldAabbMax(size.x * 0.5, size.y * 0.5, size.z * 0.5);
 	
-	btDefaultCollisionConfiguration* collisionConfiguration = new btDefaultCollisionConfiguration();
-	btCollisionDispatcher* dispatcher = new btCollisionDispatcher(collisionConfiguration);
+	collisionConfiguration = new btDefaultCollisionConfiguration();
+	dispatcher = new btCollisionDispatcher(collisionConfiguration);
 	//	dispatcher->setNearCallback(customNearCallback);
-	btAxisSweep3*	broadphase = new btAxisSweep3(worldAabbMin,worldAabbMax);
+	broadphase = new btAxisSweep3(worldAabbMin,worldAabbMax);
 	world = new btCollisionWorld(dispatcher,broadphase,collisionConfiguration);	
 }
 
@@ -196,7 +195,13 @@ CollisionResult CollisionScene::testCollision(SceneEntity *ent1, SceneEntity *en
 }
 
 CollisionScene::~CollisionScene() {
-
+	for(int i=0; i < collisionChildren.size(); i++) {
+		delete collisionChildren[i];
+	}
+	delete world;
+	delete broadphase;
+	delete dispatcher;
+	delete collisionConfiguration;
 }
 
 void CollisionScene::removeCollision(SceneEntity *entity) {
@@ -205,10 +210,11 @@ void CollisionScene::removeCollision(SceneEntity *entity) {
 		world->removeCollisionObject(cEnt->collisionObject);
 		for(int i=0; i < collisionChildren.size(); i++) {
 			if(collisionChildren[i] == cEnt) {
-				collisionChildren.erase(collisionChildren.begin()+i);
+				std::vector<CollisionSceneEntity*>::iterator target = collisionChildren.begin()+i;
+				delete *target;
+				collisionChildren.erase(target);
 			}
-		}			
-		delete cEnt;
+		}
 	}
 
 }

+ 3 - 1
Modules/Contents/3DPhysics/Source/PolyCollisionSceneEntity.cpp

@@ -32,6 +32,7 @@ using namespace Polycode;
 
 CollisionSceneEntity::CollisionSceneEntity(SceneEntity *entity, int type) {
 	sceneEntity = entity;
+	shape = NULL;
 	
 	this->type = type;
 	enabled = true;	
@@ -137,5 +138,6 @@ SceneEntity *CollisionSceneEntity::getSceneEntity() {
 }
 
 CollisionSceneEntity::~CollisionSceneEntity() {
-
+	delete shape;
+	delete collisionObject;
 }