mirror of
https://github.com/minetest/minetest.git
synced 2024-11-27 10:03:45 +01:00
Fix use of previously deallocated EmergeManager
This commit is contained in:
parent
6e352e3cbf
commit
9b978db0c2
@ -92,6 +92,11 @@ EmergeManager::EmergeManager(IGameDef *gamedef) {
|
|||||||
this->biomedef = new BiomeDefManager();
|
this->biomedef = new BiomeDefManager();
|
||||||
this->params = NULL;
|
this->params = NULL;
|
||||||
|
|
||||||
|
// Note that accesses to this variable are not synchronized.
|
||||||
|
// This is because the *only* thread ever starting or stopping
|
||||||
|
// EmergeThreads should be the ServerThread.
|
||||||
|
this->threads_active = false;
|
||||||
|
|
||||||
this->luaoverride_params = NULL;
|
this->luaoverride_params = NULL;
|
||||||
this->luaoverride_params_modified = 0;
|
this->luaoverride_params_modified = 0;
|
||||||
this->luaoverride_flagmask = 0;
|
this->luaoverride_flagmask = 0;
|
||||||
@ -128,9 +133,11 @@ EmergeManager::EmergeManager(IGameDef *gamedef) {
|
|||||||
|
|
||||||
EmergeManager::~EmergeManager() {
|
EmergeManager::~EmergeManager() {
|
||||||
for (unsigned int i = 0; i != emergethread.size(); i++) {
|
for (unsigned int i = 0; i != emergethread.size(); i++) {
|
||||||
emergethread[i]->Stop();
|
if (threads_active) {
|
||||||
emergethread[i]->qevent.signal();
|
emergethread[i]->Stop();
|
||||||
emergethread[i]->Wait();
|
emergethread[i]->qevent.signal();
|
||||||
|
emergethread[i]->Wait();
|
||||||
|
}
|
||||||
delete emergethread[i];
|
delete emergethread[i];
|
||||||
delete mapgen[i];
|
delete mapgen[i];
|
||||||
}
|
}
|
||||||
@ -252,9 +259,32 @@ Mapgen *EmergeManager::getCurrentMapgen() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void EmergeManager::startAllThreads() {
|
void EmergeManager::startThreads() {
|
||||||
|
if (threads_active)
|
||||||
|
return;
|
||||||
|
|
||||||
for (unsigned int i = 0; i != emergethread.size(); i++)
|
for (unsigned int i = 0; i != emergethread.size(); i++)
|
||||||
emergethread[i]->Start();
|
emergethread[i]->Start();
|
||||||
|
|
||||||
|
threads_active = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void EmergeManager::stopThreads() {
|
||||||
|
if (!threads_active)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// Request thread stop in parallel
|
||||||
|
for (unsigned int i = 0; i != emergethread.size(); i++) {
|
||||||
|
emergethread[i]->Stop();
|
||||||
|
emergethread[i]->qevent.signal();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Then do the waiting for each
|
||||||
|
for (unsigned int i = 0; i != emergethread.size(); i++)
|
||||||
|
emergethread[i]->Wait();
|
||||||
|
|
||||||
|
threads_active = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -87,6 +87,8 @@ public:
|
|||||||
std::vector<Mapgen *> mapgen;
|
std::vector<Mapgen *> mapgen;
|
||||||
std::vector<EmergeThread *> emergethread;
|
std::vector<EmergeThread *> emergethread;
|
||||||
|
|
||||||
|
bool threads_active;
|
||||||
|
|
||||||
//settings
|
//settings
|
||||||
MapgenParams *params;
|
MapgenParams *params;
|
||||||
bool mapgen_debug_info;
|
bool mapgen_debug_info;
|
||||||
@ -119,7 +121,8 @@ public:
|
|||||||
Mapgen *createMapgen(std::string mgname, int mgid,
|
Mapgen *createMapgen(std::string mgname, int mgid,
|
||||||
MapgenParams *mgparams);
|
MapgenParams *mgparams);
|
||||||
MapgenParams *createMapgenParams(std::string mgname);
|
MapgenParams *createMapgenParams(std::string mgname);
|
||||||
void startAllThreads();
|
void startThreads();
|
||||||
|
void stopThreads();
|
||||||
bool enqueueBlockEmerge(u16 peer_id, v3s16 p, bool allow_generate);
|
bool enqueueBlockEmerge(u16 peer_id, v3s16 p, bool allow_generate);
|
||||||
|
|
||||||
void registerMapgen(std::string name, MapgenFactory *mgfactory);
|
void registerMapgen(std::string name, MapgenFactory *mgfactory);
|
||||||
|
@ -917,8 +917,9 @@ Server::~Server()
|
|||||||
stop();
|
stop();
|
||||||
delete m_thread;
|
delete m_thread;
|
||||||
|
|
||||||
//shutdown all emerge threads first!
|
// stop all emerge threads before deleting players that may have
|
||||||
delete m_emerge;
|
// requested blocks to be emerged
|
||||||
|
m_emerge->stopThreads();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Delete clients
|
Delete clients
|
||||||
@ -938,6 +939,10 @@ Server::~Server()
|
|||||||
|
|
||||||
// Delete things in the reverse order of creation
|
// Delete things in the reverse order of creation
|
||||||
delete m_env;
|
delete m_env;
|
||||||
|
|
||||||
|
// N.B. the EmergeManager should be deleted after the Environment since Map
|
||||||
|
// depends on EmergeManager to write its current params to the map meta
|
||||||
|
delete m_emerge;
|
||||||
delete m_rollback;
|
delete m_rollback;
|
||||||
delete m_banmanager;
|
delete m_banmanager;
|
||||||
delete m_event;
|
delete m_event;
|
||||||
@ -1684,7 +1689,7 @@ void Server::AsyncRunStep(bool initial_step)
|
|||||||
{
|
{
|
||||||
counter = 0.0;
|
counter = 0.0;
|
||||||
|
|
||||||
m_emerge->startAllThreads();
|
m_emerge->startThreads();
|
||||||
|
|
||||||
// Update m_enable_rollback_recording here too
|
// Update m_enable_rollback_recording here too
|
||||||
m_enable_rollback_recording =
|
m_enable_rollback_recording =
|
||||||
|
Loading…
Reference in New Issue
Block a user