Add CellPreloader::clear to avoid potential dangling CellStore pointer and to more aggressively clear preload state from a previous game

coverity_scan^2
scrawl 8 years ago
parent 0be86f69bc
commit 3f3d00ffc9

@ -272,13 +272,31 @@ namespace MWWorld
}
}
void CellPreloader::clear()
{
for (PreloadMap::iterator it = mPreloadCells.begin(); it != mPreloadCells.end();)
{
if (it->second.mWorkItem)
{
it->second.mWorkItem->abort();
mUnrefQueue->push(it->second.mWorkItem);
}
mPreloadCells.erase(it++);
}
}
void CellPreloader::updateCache(double timestamp)
{
for (PreloadMap::iterator it = mPreloadCells.begin(); it != mPreloadCells.end();)
{
if (mPreloadCells.size() >= mMinCacheSize && it->second.mTimeStamp < timestamp - mExpiryDelay)
{
it->second.mWorkItem->abort();
if (it->second.mWorkItem)
{
it->second.mWorkItem->abort();
mUnrefQueue->push(it->second.mWorkItem);
}
mPreloadCells.erase(it++);
}
else

@ -37,6 +37,8 @@ namespace MWWorld
void notifyLoaded(MWWorld::CellStore* cell);
void clear();
/// Removes preloaded cells that have not had a preload request for a while.
void updateCache(double timestamp);

@ -315,13 +315,15 @@ namespace MWWorld
mPreloader->notifyLoaded(cell);
}
void Scene::changeToVoid()
void Scene::clear()
{
CellStoreCollection::iterator active = mActiveCells.begin();
while (active!=mActiveCells.end())
unloadCell (active++);
assert(mActiveCells.empty());
mCurrentCell = NULL;
mPreloader->clear();
}
void Scene::playerMoved(const osg::Vec3f &pos)

@ -113,7 +113,7 @@ namespace MWWorld
///< Move to exterior cell.
/// @param changeEvent Set cellChanged flag?
void changeToVoid();
void clear();
///< Change into a void
void markCellAsUnchanged();

@ -290,7 +290,7 @@ namespace MWWorld
mProjectileManager->clear();
mLocalScripts.clear();
mWorldScene->changeToVoid();
mWorldScene->clear();
mStore.clearDynamic();
mStore.setUp();

Loading…
Cancel
Save