mirror of
https://github.com/OpenMW/openmw.git
synced 2025-03-03 13:39:40 +00:00
Stop engine work queue before destructing environment
To avoid access to null and dangling pointers from active work items on quitting.
This commit is contained in:
parent
f8e02000ec
commit
f7a6be053d
3 changed files with 21 additions and 4 deletions
|
@ -407,6 +407,8 @@ OMW::Engine::Engine(Files::ConfigurationManager& configurationManager)
|
||||||
|
|
||||||
OMW::Engine::~Engine()
|
OMW::Engine::~Engine()
|
||||||
{
|
{
|
||||||
|
mWorkQueue->stop();
|
||||||
|
|
||||||
mEnvironment.cleanup();
|
mEnvironment.cleanup();
|
||||||
|
|
||||||
delete mScriptContext;
|
delete mScriptContext;
|
||||||
|
|
|
@ -33,14 +33,25 @@ bool WorkItem::isDone() const
|
||||||
return mDone;
|
return mDone;
|
||||||
}
|
}
|
||||||
|
|
||||||
WorkQueue::WorkQueue(int workerThreads)
|
WorkQueue::WorkQueue(std::size_t workerThreads)
|
||||||
: mIsReleased(false)
|
: mIsReleased(false)
|
||||||
{
|
{
|
||||||
for (int i=0; i<workerThreads; ++i)
|
start(workerThreads);
|
||||||
mThreads.emplace_back(std::make_unique<WorkThread>(*this));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
WorkQueue::~WorkQueue()
|
WorkQueue::~WorkQueue()
|
||||||
|
{
|
||||||
|
stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
void WorkQueue::start(std::size_t workerThreads)
|
||||||
|
{
|
||||||
|
while (mThreads.size() < workerThreads)
|
||||||
|
mThreads.emplace_back(std::make_unique<WorkThread>(*this));
|
||||||
|
mIsReleased = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void WorkQueue::stop()
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
std::unique_lock<std::mutex> lock(mMutex);
|
std::unique_lock<std::mutex> lock(mMutex);
|
||||||
|
|
|
@ -44,9 +44,13 @@ namespace SceneUtil
|
||||||
class WorkQueue : public osg::Referenced
|
class WorkQueue : public osg::Referenced
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
WorkQueue(int numWorkerThreads=1);
|
WorkQueue(std::size_t workerThreads);
|
||||||
~WorkQueue();
|
~WorkQueue();
|
||||||
|
|
||||||
|
void start(std::size_t workerThreads);
|
||||||
|
|
||||||
|
void stop();
|
||||||
|
|
||||||
/// Add a new work item to the back of the queue.
|
/// Add a new work item to the back of the queue.
|
||||||
/// @par The work item's waitTillDone() method may be used by the caller to wait until the work is complete.
|
/// @par The work item's waitTillDone() method may be used by the caller to wait until the work is complete.
|
||||||
/// @param front If true, add item to the front of the queue. If false (default), add to the back.
|
/// @param front If true, add item to the front of the queue. If false (default), add to the back.
|
||||||
|
|
Loading…
Reference in a new issue