Merge pull request #558 from Bigpet/modunload

unload modules upon stopping
This commit is contained in:
B1ackDaemon 2014-07-13 01:08:25 +03:00
commit f240690ff5
2 changed files with 13 additions and 3 deletions

View File

@ -271,7 +271,7 @@ initialized(false)
ModuleManager::~ModuleManager() ModuleManager::~ModuleManager()
{ {
m_mod_init.clear(); UnloadModules();
} }
bool ModuleManager::IsLoadedFunc(u32 id) bool ModuleManager::IsLoadedFunc(u32 id)
@ -332,6 +332,7 @@ u32 ModuleManager::GetFuncNumById(u32 id)
return id; return id;
} }
//to load the default modules after calling this call Init() again
void ModuleManager::UnloadModules() void ModuleManager::UnloadModules()
{ {
for (u32 i = 0; i<3; ++i) for (u32 i = 0; i<3; ++i)
@ -345,6 +346,16 @@ void ModuleManager::UnloadModules()
} }
} }
//reset state of the module manager
//this could be done by calling the destructor and then a placement-new
//to avoid repeating the initial values here but the defaults aren't
//complicated enough to complicate this by using the placement-new
m_mod_init.clear();
m_max_module_id = 0;
m_module_2_count = 0;
initialized = false;
memset(m_modules, 0, 3 * 0xFF * sizeof(Module*));
std::lock_guard<std::mutex> lock(m_funcs_lock); std::lock_guard<std::mutex> lock(m_funcs_lock);
m_modules_funcs_list.clear(); m_modules_funcs_list.clear();
} }

View File

@ -416,8 +416,7 @@ void Emulator::Stop()
GetKeyboardManager().Close(); GetKeyboardManager().Close();
GetMouseManager().Close(); GetMouseManager().Close();
GetCallbackManager().Clear(); GetCallbackManager().Clear();
// TODO: not all modules unload cleanly, so we're not unloading them for now GetModuleManager().UnloadModules();
//GetModuleManager().UnloadModules();
CurGameInfo.Reset(); CurGameInfo.Reset();
Memory.Close(); Memory.Close();