From 633e80cded155919dd01a7f33f2181ce68e6b327 Mon Sep 17 00:00:00 2001 From: Lukasz Gromanowski Date: Sun, 25 Mar 2012 16:12:23 +0200 Subject: [PATCH 1/8] Issue #225: Added cleanup of maps used in PhysicEngine. --- libs/openengine/bullet/physic.cpp | 53 +++++++++++++++++++++++++++---- libs/openengine/bullet/physic.hpp | 10 ++++-- 2 files changed, 55 insertions(+), 8 deletions(-) diff --git a/libs/openengine/bullet/physic.cpp b/libs/openengine/bullet/physic.cpp index 07bad3053..756f3b0c6 100644 --- a/libs/openengine/bullet/physic.cpp +++ b/libs/openengine/bullet/physic.cpp @@ -173,6 +173,7 @@ namespace Physic mShapeLoader = shapeLoader; isDebugCreated = false; + mDebugDrawer = NULL; } void PhysicEngine::createDebugRendering() @@ -202,6 +203,35 @@ namespace Physic PhysicEngine::~PhysicEngine() { + + RigidBodyContainer::iterator rb_it = RigidBodyMap.begin(); + for (; rb_it != RigidBodyMap.end(); ++rb_it) + { + if (rb_it->second != NULL) + { + dynamicsWorld->removeRigidBody(rb_it->second); + + delete rb_it->second; + rb_it->second = NULL; + } + } + + PhysicActorContainer::iterator pa_it = PhysicActorMap.begin(); + for (; pa_it != PhysicActorMap.end(); ++pa_it) + { + if (pa_it->second != NULL) + { + dynamicsWorld->removeCollisionObject(pa_it->second->externalGhostObject); + dynamicsWorld->removeCollisionObject(pa_it->second->internalGhostObject); + dynamicsWorld->removeAction(pa_it->second->mCharacter); + + delete pa_it->second; + pa_it->second = NULL; + } + } + + delete mDebugDrawer; + delete dynamicsWorld; delete solver; delete collisionConfiguration; @@ -239,32 +269,39 @@ namespace Physic dynamicsWorld->addRigidBody(body,COL_WORLD,COL_NOTHING); } body->setActivationState(DISABLE_DEACTIVATION); + RigidBody* oldBody = RigidBodyMap[body->mName]; + if (oldBody != NULL) + { + dynamicsWorld->removeRigidBody(oldBody); + delete oldBody; + } + RigidBodyMap[body->mName] = body; } void PhysicEngine::removeRigidBody(std::string name) { - std::map::iterator it = RigidBodyMap.find(name); + RigidBodyContainer::iterator it = RigidBodyMap.find(name); if (it != RigidBodyMap.end() ) { RigidBody* body = it->second; if(body != NULL) { // broadphase->getOverlappingPairCache()->removeOverlappingPairsContainingProxy(body->getBroadphaseProxy(),dispatcher); - /*std::map::iterator it2 = PhysicActorMap.begin(); + /*PhysicActorContainer::iterator it2 = PhysicActorMap.begin(); for(;it2!=PhysicActorMap.end();it++) { it2->second->internalGhostObject->getOverlappingPairCache()->removeOverlappingPairsContainingProxy(body->getBroadphaseProxy(),dispatcher); it2->second->externalGhostObject->getOverlappingPairCache()->removeOverlappingPairsContainingProxy(body->getBroadphaseProxy(),dispatcher); }*/ - dynamicsWorld->removeRigidBody(RigidBodyMap[name]); + dynamicsWorld->removeRigidBody(body); } } } void PhysicEngine::deleteRigidBody(std::string name) { - std::map::iterator it = RigidBodyMap.find(name); + RigidBodyContainer::iterator it = RigidBodyMap.find(name); if (it != RigidBodyMap.end() ) { RigidBody* body = it->second; @@ -293,6 +330,10 @@ namespace Physic void PhysicEngine::addCharacter(std::string name) { + // Remove character with given name, so we don't make memory + // leak when character would be added twice + removeCharacter(name); + PhysicActor* newActor = new PhysicActor(name); dynamicsWorld->addCollisionObject( newActor->externalGhostObject, COL_ACTOR_EXTERNAL, COL_WORLD |COL_ACTOR_EXTERNAL ); dynamicsWorld->addCollisionObject( newActor->internalGhostObject, COL_ACTOR_INTERNAL, COL_WORLD |COL_ACTOR_INTERNAL ); @@ -303,7 +344,7 @@ namespace Physic void PhysicEngine::removeCharacter(std::string name) { //std::cout << "remove"; - std::map::iterator it = PhysicActorMap.find(name); + PhysicActorContainer::iterator it = PhysicActorMap.find(name); if (it != PhysicActorMap.end() ) { PhysicActor* act = it->second; @@ -311,7 +352,7 @@ namespace Physic { /*broadphase->getOverlappingPairCache()->removeOverlappingPairsContainingProxy(act->externalGhostObject->getBroadphaseHandle(),dispatcher); broadphase->getOverlappingPairCache()->removeOverlappingPairsContainingProxy(act->internalGhostObject->getBroadphaseHandle(),dispatcher); - std::map::iterator it2 = PhysicActorMap.begin(); + PhysicActorContainer::iterator it2 = PhysicActorMap.begin(); for(;it2!=PhysicActorMap.end();it++) { it->second->internalGhostObject->getOverlappingPairCache()->removeOverlappingPairsContainingProxy(act->externalGhostObject->getBroadphaseHandle(),dispatcher); diff --git a/libs/openengine/bullet/physic.hpp b/libs/openengine/bullet/physic.hpp index 88e3699ae..200b96207 100644 --- a/libs/openengine/bullet/physic.hpp +++ b/libs/openengine/bullet/physic.hpp @@ -42,6 +42,8 @@ namespace Physic :btPairCachingGhostObject(),mName(name) { } + virtual ~PairCachingGhostObject(){} + std::string mName; }; @@ -106,6 +108,7 @@ namespace Physic { public: RigidBody(btRigidBody::btRigidBodyConstructionInfo& CI,std::string name); + virtual ~RigidBody() {} std::string mName; //is this body used for raycasting only? @@ -217,8 +220,11 @@ namespace Physic //the NIF file loader. BulletShapeLoader* mShapeLoader; - std::map RigidBodyMap; - std::map PhysicActorMap; + typedef std::map RigidBodyContainer; + RigidBodyContainer RigidBodyMap; + + typedef std::map PhysicActorContainer; + PhysicActorContainer PhysicActorMap; //debug rendering BtOgre::DebugDrawer* mDebugDrawer; From a7ac0e526e2d942df619cddc737204f5c4b2d283 Mon Sep 17 00:00:00 2001 From: Lukasz Gromanowski Date: Sun, 25 Mar 2012 18:12:00 +0200 Subject: [PATCH 2/8] Issue #225: Added cleanup of parts of PhysicEngine. Added cleanup of CMotionState inserted to RigidBody, and btSortedOverlappingPairCache inserted to btDbvtBroadphase in PhysicEngine. --- libs/openengine/bullet/physic.cpp | 13 +++++++++---- libs/openengine/bullet/physic.hpp | 3 ++- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/libs/openengine/bullet/physic.cpp b/libs/openengine/bullet/physic.cpp index 756f3b0c6..8b9f3dfec 100644 --- a/libs/openengine/bullet/physic.cpp +++ b/libs/openengine/bullet/physic.cpp @@ -134,10 +134,15 @@ namespace Physic RigidBody::RigidBody(btRigidBody::btRigidBodyConstructionInfo& CI,std::string name) - :btRigidBody(CI),mName(name) + : btRigidBody(CI) + , mName(name) { + } - }; + RigidBody::~RigidBody() + { + delete getMotionState(); + } @@ -155,8 +160,7 @@ namespace Physic // The actual physics solver solver = new btSequentialImpulseConstraintSolver; - //TODO: memory leak? - btOverlappingPairCache* pairCache = new btSortedOverlappingPairCache(); + pairCache = new btSortedOverlappingPairCache(); //pairCache->setInternalGhostPairCallback( new btGhostPairCallback() ); broadphase = new btDbvtBroadphase(pairCache); @@ -237,6 +241,7 @@ namespace Physic delete collisionConfiguration; delete dispatcher; delete broadphase; + delete pairCache; delete mShapeLoader; } diff --git a/libs/openengine/bullet/physic.hpp b/libs/openengine/bullet/physic.hpp index 200b96207..57ffe9130 100644 --- a/libs/openengine/bullet/physic.hpp +++ b/libs/openengine/bullet/physic.hpp @@ -108,7 +108,7 @@ namespace Physic { public: RigidBody(btRigidBody::btRigidBodyConstructionInfo& CI,std::string name); - virtual ~RigidBody() {} + virtual ~RigidBody(); std::string mName; //is this body used for raycasting only? @@ -211,6 +211,7 @@ namespace Physic std::list PEventList; //Bullet Stuff + btOverlappingPairCache* pairCache; btBroadphaseInterface* broadphase; btDefaultCollisionConfiguration* collisionConfiguration; btSequentialImpulseConstraintSolver* solver; From d3b88b9e34ae0d46153262ebd1acf2627bb15984 Mon Sep 17 00:00:00 2001 From: Lukasz Gromanowski Date: Sun, 25 Mar 2012 20:37:05 +0200 Subject: [PATCH 3/8] Issue #225: Added cleanup of allocated memory in BulletNifLoader and BulletShapeLoader. --- components/nifbullet/bullet_nif_loader.cpp | 22 ++++++++++++++++++-- components/nifbullet/bullet_nif_loader.hpp | 2 +- libs/openengine/bullet/BulletShapeLoader.cpp | 1 + 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/components/nifbullet/bullet_nif_loader.cpp b/components/nifbullet/bullet_nif_loader.cpp index 82e9d7adc..e9aa626db 100644 --- a/components/nifbullet/bullet_nif_loader.cpp +++ b/components/nifbullet/bullet_nif_loader.cpp @@ -51,7 +51,11 @@ using namespace Mangle::VFS; using namespace NifBullet; -//==================================================================================================== +ManualBulletShapeLoader::~ManualBulletShapeLoader() +{ + delete vfs; +} + Ogre::Matrix3 ManualBulletShapeLoader::getMatrix(Nif::Transformation* tr) { Ogre::Matrix3 rot(tr->rotation.v[0].array[0],tr->rotation.v[0].array[1],tr->rotation.v[0].array[2], @@ -135,7 +139,21 @@ void ManualBulletShapeLoader::loadResource(Ogre::Resource *resource) handleNode(node,0,Ogre::Matrix3::IDENTITY,Ogre::Vector3::ZERO,1,hasCollisionNode,false,true); } - currentShape = new btBvhTriangleMeshShape(mTriMesh,true); + struct TriangleMeshShape : public btBvhTriangleMeshShape + { + TriangleMeshShape(btStridingMeshInterface* meshInterface, bool useQuantizedAabbCompression) + : btBvhTriangleMeshShape(meshInterface, useQuantizedAabbCompression) + { + } + + virtual ~TriangleMeshShape() + { + delete getTriangleInfoMap(); + delete m_meshInterface; + } + }; + + currentShape = new TriangleMeshShape(mTriMesh,true); cShape->Shape = currentShape; } diff --git a/components/nifbullet/bullet_nif_loader.hpp b/components/nifbullet/bullet_nif_loader.hpp index 1fa2b6aa5..ed3aceac4 100644 --- a/components/nifbullet/bullet_nif_loader.hpp +++ b/components/nifbullet/bullet_nif_loader.hpp @@ -69,7 +69,7 @@ class ManualBulletShapeLoader : public BulletShapeLoader public: ManualBulletShapeLoader():resourceGroup("General"){vfs = 0;} - virtual ~ManualBulletShapeLoader() {} + virtual ~ManualBulletShapeLoader(); void warn(std::string msg) { diff --git a/libs/openengine/bullet/BulletShapeLoader.cpp b/libs/openengine/bullet/BulletShapeLoader.cpp index 48b87e1e8..4593bad52 100644 --- a/libs/openengine/bullet/BulletShapeLoader.cpp +++ b/libs/openengine/bullet/BulletShapeLoader.cpp @@ -22,6 +22,7 @@ Ogre::Resource(creator, name, handle, group, isManual, loader) BulletShape::~BulletShape() { + deleteShape(Shape); } // farm out to BulletShapeLoader From 5185a28b6002d1e04b89632ff27a00a613634d54 Mon Sep 17 00:00:00 2001 From: Lukasz Gromanowski Date: Sun, 25 Mar 2012 21:56:22 +0200 Subject: [PATCH 4/8] Issue #225: Initialize all class members in constructor. --- apps/openmw/mwgui/layouts.cpp | 16 ++++++++++ apps/openmw/mwgui/stats_window.cpp | 13 ++++++++ apps/openmw/mwgui/window_manager.cpp | 29 ++++++++++++++++-- apps/openmw/mwrender/animation.cpp | 25 ++++++++++++++- apps/openmw/mwrender/animation.hpp | 16 +++++----- libs/openengine/ogre/renderer.hpp | 46 +++++++++++++++++++++------- 6 files changed, 123 insertions(+), 22 deletions(-) diff --git a/apps/openmw/mwgui/layouts.cpp b/apps/openmw/mwgui/layouts.cpp index 9c49c62ac..dbd6154b7 100644 --- a/apps/openmw/mwgui/layouts.cpp +++ b/apps/openmw/mwgui/layouts.cpp @@ -15,6 +15,22 @@ using namespace MWGui; HUD::HUD(int width, int height, int fpsLevel) : Layout("openmw_hud_layout.xml") + , health(NULL) + , magicka(NULL) + , stamina(NULL) + , weapImage(NULL) + , spellImage(NULL) + , weapStatus(NULL) + , spellStatus(NULL) + , effectBox(NULL) + , effect1(NULL) + , minimap(NULL) + , compass(NULL) + , crosshair(NULL) + , fpsbox(NULL) + , fpscounter(NULL) + , trianglecounter(NULL) + , batchcounter(NULL) { setCoord(0,0, width, height); diff --git a/apps/openmw/mwgui/stats_window.cpp b/apps/openmw/mwgui/stats_window.cpp index 243b6272a..12b0dcc79 100644 --- a/apps/openmw/mwgui/stats_window.cpp +++ b/apps/openmw/mwgui/stats_window.cpp @@ -13,9 +13,22 @@ const int StatsWindow::lineHeight = 18; StatsWindow::StatsWindow (WindowManager& parWindowManager) : WindowBase("openmw_stats_window_layout.xml", parWindowManager) + , skillAreaWidget(NULL) + , skillClientWidget(NULL) + , skillScrollerWidget(NULL) , lastPos(0) + , clientHeight(0) + , majorSkills() + , minorSkills() + , miscSkills() + , skillValues() + , skillWidgetMap() + , factionWidgetMap() + , factions() + , birthSignId() , reputation(0) , bounty(0) + , skillWidgets() { setCoord(0,0,498, 342); diff --git a/apps/openmw/mwgui/window_manager.cpp b/apps/openmw/mwgui/window_manager.cpp index fa6dedc77..a04e2dcb8 100644 --- a/apps/openmw/mwgui/window_manager.cpp +++ b/apps/openmw/mwgui/window_manager.cpp @@ -22,15 +22,40 @@ using namespace MWGui; WindowManager::WindowManager(MWWorld::Environment& environment, const Compiler::Extensions& extensions, int fpsLevel, bool newGame, OEngine::Render::OgreRenderer *mOgre, const std::string logpath) - : environment(environment) + : mGuiManager(NULL) + , environment(environment) + , hud(NULL) + , map(NULL) + , menu(NULL) + , stats(NULL) + , mMessageBoxManager(NULL) + , console(NULL) + , mJournal(NULL) , dialogueWindow(nullptr) + , mCharGen(NULL) + , playerClass() + , playerName() + , playerRaceId() + , playerBirthSignId() + , playerAttributes() + , playerMajorSkills() + , playerMinorSkills() + , playerSkillValues() + , playerHealth() + , playerMagicka() + , playerFatigue() + , gui(NULL) , mode(GM_Game) , nextMode(GM_Game) , needModeChange(false) + , garbageDialogs() , shown(GW_ALL) , allowed(newGame ? GW_None : GW_ALL) + , showFPSLevel(fpsLevel) + , mFPS(0.0f) + , mTriangleCount(0) + , mBatchCount(0) { - showFPSLevel = fpsLevel; // Set up the GUI system mGuiManager = new OEngine::GUI::MyGUIManager(mOgre->getWindow(), mOgre->getScene(), false, logpath); diff --git a/apps/openmw/mwrender/animation.cpp b/apps/openmw/mwrender/animation.cpp index 7b0d7015c..f3a8f64d5 100644 --- a/apps/openmw/mwrender/animation.cpp +++ b/apps/openmw/mwrender/animation.cpp @@ -4,7 +4,30 @@ namespace MWRender{ std::map Animation::mUniqueIDs; - Animation::~Animation(){ + Animation::Animation(MWWorld::Environment& _env, OEngine::Render::OgreRenderer& _rend) + : insert(NULL) + , mRend(_rend) + , mEnvironment(_env) + , vecRotPos() + , shapeparts() + , time(0.0f) + , startTime(0.0f) + , stopTime(0.0f) + , animate(0) + , rindexI() + , tindexI() + , shapeNumber(0) + , shapeIndexI() + , shapes(NULL) + , entityparts() + , transformations(NULL) + , textmappings(NULL) + , base(NULL) + { + } + + Animation::~Animation() + { } std::string Animation::getUniqueID(std::string mesh){ diff --git a/apps/openmw/mwrender/animation.hpp b/apps/openmw/mwrender/animation.hpp index d1e8071f0..7692c7128 100644 --- a/apps/openmw/mwrender/animation.hpp +++ b/apps/openmw/mwrender/animation.hpp @@ -60,14 +60,14 @@ class Animation{ std::string getUniqueID(std::string mesh); public: - Animation(MWWorld::Environment& _env, OEngine::Render::OgreRenderer& _rend): mRend(_rend), mEnvironment(_env), animate(0){}; - virtual void runAnimation(float timepassed) = 0; - void startScript(std::string groupname, int mode, int loops); - void stopScript(); - - - virtual ~Animation(); + Animation(MWWorld::Environment& _env, OEngine::Render::OgreRenderer& _rend); + virtual void runAnimation(float timepassed) = 0; + void startScript(std::string groupname, int mode, int loops); + void stopScript(); + + + virtual ~Animation(); }; } -#endif \ No newline at end of file +#endif diff --git a/libs/openengine/ogre/renderer.hpp b/libs/openengine/ogre/renderer.hpp index 6516b0a80..179515aa9 100644 --- a/libs/openengine/ogre/renderer.hpp +++ b/libs/openengine/ogre/renderer.hpp @@ -44,27 +44,51 @@ namespace Render Ogre::SceneManager *mScene; Ogre::Camera *mCamera; Ogre::Viewport *mView; - #ifdef ENABLE_PLUGIN_CgProgramManager +#ifdef ENABLE_PLUGIN_CgProgramManager Ogre::CgPlugin* mCgPlugin; - #endif - #ifdef ENABLE_PLUGIN_OctreeSceneManager +#endif +#ifdef ENABLE_PLUGIN_OctreeSceneManager Ogre::OctreePlugin* mOctreePlugin; - #endif - #ifdef ENABLE_PLUGIN_ParticleFX +#endif +#ifdef ENABLE_PLUGIN_ParticleFX Ogre::ParticleFXPlugin* mParticleFXPlugin; - #endif - #ifdef ENABLE_PLUGIN_GL +#endif +#ifdef ENABLE_PLUGIN_GL Ogre::GLPlugin* mGLPlugin; - #endif - #ifdef ENABLE_PLUGIN_Direct3D9 +#endif +#ifdef ENABLE_PLUGIN_Direct3D9 Ogre::D3D9Plugin* mD3D9Plugin; - #endif +#endif Fader* mFader; bool logging; public: OgreRenderer() - : mRoot(NULL), mWindow(NULL), mScene(NULL), mFader(NULL) {} + : mRoot(NULL) + , mWindow(NULL) + , mScene(NULL) + , mCamera(NULL) + , mView(NULL) +#ifdef ENABLE_PLUGIN_CgProgramManager + , mCgPlugin(NULL) +#endif +#ifdef ENABLE_PLUGIN_OctreeSceneManager + , mOctreePlugin(NULL) +#endif +#ifdef ENABLE_PLUGIN_ParticleFX + , mParticleFXPlugin(NULL) +#endif +#ifdef ENABLE_PLUGIN_GL + , mGLPlugin(NULL) +#endif +#ifdef ENABLE_PLUGIN_Direct3D9 + , mD3D9Plugin(NULL) +#endif + , mFader(NULL) + , logging(false) + { + } + ~OgreRenderer() { cleanup(); } /** Configure the renderer. This will load configuration files and From 2b9845a5b69de39203e970e326b5a15e22731732 Mon Sep 17 00:00:00 2001 From: Lukasz Gromanowski Date: Sun, 25 Mar 2012 23:34:32 +0200 Subject: [PATCH 5/8] Issue #225: Free memory allocated for sending into HardwareVertexBuffer. Free memory allocated for sending into HardwareVertexBuffer in NIFLoader class. --- components/nifogre/ogre_nif_loader.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/components/nifogre/ogre_nif_loader.cpp b/components/nifogre/ogre_nif_loader.cpp index 2e68cfe90..1367c138a 100644 --- a/components/nifogre/ogre_nif_loader.cpp +++ b/components/nifogre/ogre_nif_loader.cpp @@ -509,7 +509,8 @@ void NIFLoader::createOgreSubMesh(NiTriShape *shape, const String &material, std datamod[index+1] = original.y; datamod[index+2] = original.z; } - vbuf->writeData(0, vbuf->getSizeInBytes(), datamod, false); + vbuf->writeData(0, vbuf->getSizeInBytes(), datamod, false); + delete datamod; } else { @@ -550,6 +551,7 @@ void NIFLoader::createOgreSubMesh(NiTriShape *shape, const String &material, std datamod[index+2] = original.z; } vbuf->writeData(0, vbuf->getSizeInBytes(), datamod, false); + delete datamod; } else { @@ -601,6 +603,7 @@ void NIFLoader::createOgreSubMesh(NiTriShape *shape, const String &material, std datamod[i + 1] =y; } vbuf->writeData(0, vbuf->getSizeInBytes(), datamod, false); + delete datamod; } else vbuf->writeData(0, vbuf->getSizeInBytes(), data->uvlist.ptr, false); @@ -644,15 +647,13 @@ void NIFLoader::createOgreSubMesh(NiTriShape *shape, const String &material, std index += 3; } - ibuf->writeData(0, ibuf->getSizeInBytes(), datamod, false); + ibuf->writeData(0, ibuf->getSizeInBytes(), datamod, false); + delete datamod; } else - ibuf->writeData(0, ibuf->getSizeInBytes(), data->triangles.ptr, false); + ibuf->writeData(0, ibuf->getSizeInBytes(), data->triangles.ptr, false); sub->indexData->indexBuffer = ibuf; - - - } // Set material if one was given From f8afc22f04f1224ccd17edf1552adac2555a0e7f Mon Sep 17 00:00:00 2001 From: Lukasz Gromanowski Date: Mon, 26 Mar 2012 23:16:59 +0200 Subject: [PATCH 6/8] Issue #225: Corrected wrong delete operator introduced by one of previous commit. --- components/nifogre/ogre_nif_loader.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/components/nifogre/ogre_nif_loader.cpp b/components/nifogre/ogre_nif_loader.cpp index 1367c138a..f943231d0 100644 --- a/components/nifogre/ogre_nif_loader.cpp +++ b/components/nifogre/ogre_nif_loader.cpp @@ -510,7 +510,7 @@ void NIFLoader::createOgreSubMesh(NiTriShape *shape, const String &material, std datamod[index+2] = original.z; } vbuf->writeData(0, vbuf->getSizeInBytes(), datamod, false); - delete datamod; + delete [] datamod; } else { @@ -551,7 +551,7 @@ void NIFLoader::createOgreSubMesh(NiTriShape *shape, const String &material, std datamod[index+2] = original.z; } vbuf->writeData(0, vbuf->getSizeInBytes(), datamod, false); - delete datamod; + delete [] datamod; } else { @@ -603,7 +603,7 @@ void NIFLoader::createOgreSubMesh(NiTriShape *shape, const String &material, std datamod[i + 1] =y; } vbuf->writeData(0, vbuf->getSizeInBytes(), datamod, false); - delete datamod; + delete [] datamod; } else vbuf->writeData(0, vbuf->getSizeInBytes(), data->uvlist.ptr, false); @@ -648,7 +648,7 @@ void NIFLoader::createOgreSubMesh(NiTriShape *shape, const String &material, std } ibuf->writeData(0, ibuf->getSizeInBytes(), datamod, false); - delete datamod; + delete [] datamod; } else From 6d6ed909bf62a328c927fbbdb52b6a98ef677e28 Mon Sep 17 00:00:00 2001 From: Lukasz Gromanowski Date: Tue, 27 Mar 2012 00:31:15 +0200 Subject: [PATCH 7/8] Issue #225: Deallocate memory used by actors animations. --- apps/openmw/mwrender/actors.cpp | 10 ++++++++++ apps/openmw/mwrender/actors.hpp | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/apps/openmw/mwrender/actors.cpp b/apps/openmw/mwrender/actors.cpp index d8ca78e3a..6eb4a182b 100644 --- a/apps/openmw/mwrender/actors.cpp +++ b/apps/openmw/mwrender/actors.cpp @@ -8,6 +8,15 @@ using namespace Ogre; using namespace MWRender; using namespace NifOgre; +Actors::~Actors(){ + + std::map::iterator it = mAllActors.begin(); + for (; it != mAllActors.end(); ++it) { + delete it->second; + it->second = NULL; + } +} + void Actors::setMwRoot(Ogre::SceneNode* root){ mMwRoot = root; } @@ -61,6 +70,7 @@ void Actors::insertCreature (const MWWorld::Ptr& ptr){ insertBegin(ptr, true, true); CreatureAnimation* anim = new MWRender::CreatureAnimation(ptr, mEnvironment, mRend); //mAllActors.insert(std::pair(ptr,anim)); + delete mAllActors[ptr]; mAllActors[ptr] = anim; //mAllActors.push_back(&anim);*/ } diff --git a/apps/openmw/mwrender/actors.hpp b/apps/openmw/mwrender/actors.hpp index 7179c08fb..d49c6e0f8 100644 --- a/apps/openmw/mwrender/actors.hpp +++ b/apps/openmw/mwrender/actors.hpp @@ -30,7 +30,7 @@ namespace MWRender{ public: Actors(OEngine::Render::OgreRenderer& _rend, MWWorld::Environment& _env): mRend(_rend), mEnvironment(_env){} - ~Actors(){} + ~Actors(); void setMwRoot(Ogre::SceneNode* root); void insertBegin (const MWWorld::Ptr& ptr, bool enabled, bool static_); void insertCreature (const MWWorld::Ptr& ptr); From be94da15272937a8719a849a51162c2fd276374d Mon Sep 17 00:00:00 2001 From: Lukasz Gromanowski Date: Tue, 27 Mar 2012 00:34:06 +0200 Subject: [PATCH 8/8] Issue #225: Initialize class members in constructor. --- apps/openmw/mwrender/sky.cpp | 38 +++++++++++++++++++++++--- apps/openmw/mwsound/mpgsnd_decoder.cpp | 8 +++++- 2 files changed, 41 insertions(+), 5 deletions(-) diff --git a/apps/openmw/mwrender/sky.cpp b/apps/openmw/mwrender/sky.cpp index 5e8578002..a41bc21e0 100644 --- a/apps/openmw/mwrender/sky.cpp +++ b/apps/openmw/mwrender/sky.cpp @@ -254,7 +254,7 @@ void SkyManager::ModVertexAlpha(Entity* ent, unsigned int meshType) // Get a pointer to the vertex colour ves_diffuse->baseVertexPointerToElement( pData, ¤tVertex ); - unsigned char alpha; + unsigned char alpha=0; if (meshType == 0) alpha = i%2 ? 0 : 255; // this is a cylinder, so every second vertex belongs to the bottom-most row else if (meshType == 1) { @@ -292,10 +292,40 @@ void SkyManager::ModVertexAlpha(Entity* ent, unsigned int meshType) ent->getMesh()->getSubMesh(0)->vertexData->vertexBufferBinding->getBuffer(ves_diffuse->getSource())->unlock(); } -SkyManager::SkyManager (SceneNode* pMwRoot, Camera* pCamera, MWWorld::Environment* env) : - mGlareFade(0), mGlareEnabled(false) +SkyManager::SkyManager (SceneNode* pMwRoot, Camera* pCamera, MWWorld::Environment* env) + : mEnvironment(env) + , mHour(0.0f) + , mDay(0) + , mMonth(0) + , mSun(NULL) + , mSunGlare(NULL) + , mMasser(NULL) + , mSecunda(NULL) + , mViewport(NULL) + , mRootNode(NULL) + , mSceneMgr(NULL) + , mAtmosphereDay(NULL) + , mAtmosphereNight(NULL) + , mCloudMaterial() + , mAtmosphereMaterial() + , mCloudFragmentShader() + , mClouds() + , mNextClouds() + , mCloudBlendFactor(0.0f) + , mCloudOpacity(0.0f) + , mCloudSpeed(0.0f) + , mStarsOpacity(0.0f) + , mThunderOverlay(NULL) + , mThunderTextureUnit(NULL) + , mRemainingTransitionTime(0.0f) + , mGlareFade(0.0f) + , mEnabled(true) + , mGlareEnabled(true) + , mSunEnabled(true) + , mMasserEnabled(true) + , mSecundaEnabled(true) { - mEnvironment = env; + mViewport = pCamera->getViewport(); mSceneMgr = pMwRoot->getCreator(); mRootNode = pCamera->getParentSceneNode()->createChildSceneNode(); diff --git a/apps/openmw/mwsound/mpgsnd_decoder.cpp b/apps/openmw/mwsound/mpgsnd_decoder.cpp index f576833a8..9b91b4e74 100644 --- a/apps/openmw/mwsound/mpgsnd_decoder.cpp +++ b/apps/openmw/mwsound/mpgsnd_decoder.cpp @@ -213,7 +213,13 @@ void MpgSnd_Decoder::rewind() } } -MpgSnd_Decoder::MpgSnd_Decoder() : mSndFile(NULL), mMpgFile(NULL) +MpgSnd_Decoder::MpgSnd_Decoder() + : mSndInfo() + , mSndFile(NULL) + , mMpgFile(NULL) + , mDataStream() + , mChanConfig(ChannelConfig_Stereo) + , mSampleRate(0) { static bool initdone = false; if(!initdone)