From 5cda89c15d261bfc371a481794f48094bb6aa544 Mon Sep 17 00:00:00 2001 From: scrawl Date: Tue, 29 Mar 2016 00:48:47 +0200 Subject: [PATCH] Don't attempt to preload more exterior cells than the cache can hold (Bug #3273) --- apps/openmw/mwworld/cellpreloader.cpp | 5 +++++ apps/openmw/mwworld/cellpreloader.hpp | 2 ++ apps/openmw/mwworld/scene.cpp | 3 +++ 3 files changed, 10 insertions(+) diff --git a/apps/openmw/mwworld/cellpreloader.cpp b/apps/openmw/mwworld/cellpreloader.cpp index a8f146024..48b058d9e 100644 --- a/apps/openmw/mwworld/cellpreloader.cpp +++ b/apps/openmw/mwworld/cellpreloader.cpp @@ -260,6 +260,11 @@ namespace MWWorld mMaxCacheSize = num; } + unsigned int CellPreloader::getMaxCacheSize() const + { + return mMaxCacheSize; + } + void CellPreloader::setWorkQueue(osg::ref_ptr workQueue) { mWorkQueue = workQueue; diff --git a/apps/openmw/mwworld/cellpreloader.hpp b/apps/openmw/mwworld/cellpreloader.hpp index f78e66e75..e236a3783 100644 --- a/apps/openmw/mwworld/cellpreloader.hpp +++ b/apps/openmw/mwworld/cellpreloader.hpp @@ -44,6 +44,8 @@ namespace MWWorld /// The maximum number of preloaded cells. void setMaxCacheSize(unsigned int num); + unsigned int getMaxCacheSize() const; + void setWorkQueue(osg::ref_ptr workQueue); private: diff --git a/apps/openmw/mwworld/scene.cpp b/apps/openmw/mwworld/scene.cpp index 392374753..33ea9b6a8 100644 --- a/apps/openmw/mwworld/scene.cpp +++ b/apps/openmw/mwworld/scene.cpp @@ -737,11 +737,14 @@ namespace MWWorld { int x = cell->getCell()->getGridX(); int y = cell->getCell()->getGridY(); + unsigned int numpreloaded = 0; for (int dx = -mHalfGridSize; dx <= mHalfGridSize; ++dx) { for (int dy = -mHalfGridSize; dy <= mHalfGridSize; ++dy) { mPreloader->preload(MWBase::Environment::get().getWorld()->getExterior(x+dx, y+dy), mRendering.getReferenceTime()); + if (++numpreloaded >= mPreloader->getMaxCacheSize()) + break; } } }