Cleanup bullet objects in the destructors.

loadfix
cc9cii 10 years ago
parent 9337d6533a
commit b46df4034d

@ -96,6 +96,19 @@ CSVRender::Cell::Cell (CSMWorld::Data& data, Ogre::SceneManager *sceneManager,
CSVRender::Cell::~Cell() CSVRender::Cell::~Cell()
{ {
// TODO: maybe store the cell coordinates rather than searching for them in the destructor?
if(mTerrain.get())
{
const CSMWorld::IdCollection<CSMWorld::Land>& land = mData.getLand();
int landIndex = land.searchId(mId);
if (landIndex != -1)
{
const ESM::Land* esmLand = land.getRecord(mId).get().mLand.get();
if(esmLand)
CSVWorld::PhysicsSystem::instance()->removeHeightField(esmLand->mX, esmLand->mY);
}
}
for (std::map<std::string, Object *>::iterator iter (mObjects.begin()); for (std::map<std::string, Object *>::iterator iter (mObjects.begin());
iter!=mObjects.end(); ++iter) iter!=mObjects.end(); ++iter)
delete iter->second; delete iter->second;

@ -33,11 +33,12 @@ void CSVRender::Object::clearSceneNode (Ogre::SceneNode *node)
void CSVRender::Object::clear() void CSVRender::Object::clear()
{ {
if(!mObject.isNull())
CSVWorld::PhysicsSystem::instance()->removeObject(mBase->getName());
mObject.setNull(); mObject.setNull();
clearSceneNode (mBase); clearSceneNode (mBase);
// FIXME: also clear bullet objects
} }
void CSVRender::Object::update() void CSVRender::Object::update()

@ -53,6 +53,15 @@ namespace CSVWorld
PhysicsSystem::~PhysicsSystem() PhysicsSystem::~PhysicsSystem()
{ {
std::map<std::string, std::vector<std::string> >::iterator iter = mSelectedEntities.begin();
for(;iter != mSelectedEntities.end(); ++iter)
{
removeHitPoint(mSceneMgr, iter->first);
Ogre::SceneNode *scene = mSceneMgr->getSceneNode(iter->first);
scene->removeAndDestroyAllChildren();
mSceneMgr->destroySceneNode(iter->first);
}
delete mEngine; delete mEngine;
} }
@ -152,6 +161,11 @@ namespace CSVWorld
mEngine->addHeightField(heights, x, y, yoffset, triSize, sqrtVerts); mEngine->addHeightField(heights, x, y, yoffset, triSize, sqrtVerts);
} }
void PhysicsSystem::removeHeightField(int x, int y)
{
mEngine->removeHeightField(x, y);
}
void PhysicsSystem::toggleDebugRendering() void PhysicsSystem::toggleDebugRendering()
{ {
CSMSettings::UserSettings &userSettings = CSMSettings::UserSettings::instance(); CSMSettings::UserSettings &userSettings = CSMSettings::UserSettings::instance();

@ -53,11 +53,13 @@ namespace CSVWorld
void addHeightField(float* heights, int x, int y, float yoffset, void addHeightField(float* heights, int x, int y, float yoffset,
float triSize, float sqrtVerts); float triSize, float sqrtVerts);
void removeHeightField(int x, int y);
void toggleDebugRendering(); void toggleDebugRendering();
std::pair<bool, std::string> castRay(float mouseX, float mouseY, std::pair<bool, std::string> castRay(float mouseX, float mouseY,
Ogre::Vector3* normal, std::string* hit, Ogre::Vector3* normal, std::string* hit,
Ogre::Camera *camera, bool ignoreHeightMap); Ogre::Camera *camera, bool ignoreHeightMap);
}; };
} }

Loading…
Cancel
Save