From 529bf35d6a87db16e0e2fb0bf775719755e98299 Mon Sep 17 00:00:00 2001 From: nakeee Date: Sat, 31 Jan 2009 23:47:45 +0000 Subject: [PATCH] trying to clean all plugins on shutdown git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@2047 8ced0084-cf51-0410-be5f-012b33b47a6e --- Source/Core/Common/Src/DynamicLibrary.cpp | 16 ++++----- Source/Core/Common/Src/Plugin.cpp | 17 ++++------ Source/Core/Common/Src/PluginVideo.cpp | 11 ++++-- Source/Core/Core/Src/Core.cpp | 1 - Source/Core/Core/Src/PluginManager.cpp | 41 ++++++++++++++--------- 5 files changed, 49 insertions(+), 37 deletions(-) diff --git a/Source/Core/Common/Src/DynamicLibrary.cpp b/Source/Core/Common/Src/DynamicLibrary.cpp index bb97fe8a27..dcec5fc9d3 100644 --- a/Source/Core/Common/Src/DynamicLibrary.cpp +++ b/Source/Core/Common/Src/DynamicLibrary.cpp @@ -92,13 +92,13 @@ int DynamicLibrary::Load(const char* filename) return 2; } + Console::Print("LoadLibrary: %s", filename); #ifdef _WIN32 - Console::Print("LoadLibrary: %s\n", filename); library = LoadLibrary(filename); #else library = dlopen(filename, RTLD_NOW | RTLD_LOCAL); #endif - + Console::Print(" %p\n", library); if (!library) { LOG(MASTER_LOG, "Error loading DLL %s: %s", filename, GetLastErrorAsString().c_str()); PanicAlert("Error loading DLL %s: %s\n", filename, GetLastErrorAsString().c_str()); @@ -116,15 +116,15 @@ int DynamicLibrary::Unload() PanicAlert("Error unloading DLL %s: not loaded", library_file.c_str()); return 0; } - + + Console::Print("FreeLibrary: %s %p\n", library_file.c_str(), library); #ifdef _WIN32 - Console::Print("FreeLibrary: %i\n", library_file.c_str()); - retval = FreeLibrary(library); + retval = FreeLibrary(library); #else - Console::Print("FreeLibrary: %i\n", library_file.c_str()); - retval = dlclose(library)?0:1; + retval = dlclose(library)?0:1; #endif - if (!retval) { + + if (! retval) { PanicAlert("Error unloading DLL %s: %s", library_file.c_str(), GetLastErrorAsString().c_str()); } diff --git a/Source/Core/Common/Src/Plugin.cpp b/Source/Core/Common/Src/Plugin.cpp index c029fd1251..dd6f530b10 100644 --- a/Source/Core/Common/Src/Plugin.cpp +++ b/Source/Core/Common/Src/Plugin.cpp @@ -17,14 +17,9 @@ -// ======================================================= -// File description -// ------------- -/* This file is a simpler version of Plugin_...cpp found in Core. This file only loads - the config and debugging windows and works with all plugins. */ -// ============= +/* This file is a simpler version of Plugin_...cpp found in Core. This file + only loads the config and debugging windows and works with all plugins. */ - #include "Plugin.h" namespace Common @@ -35,7 +30,7 @@ CPlugin::~CPlugin() m_hInstLib.Unload(); } -CPlugin::CPlugin(const char* _szName) : valid(false) +CPlugin::CPlugin(const char* _szName) : valid(false) { m_GetDllInfo = NULL; @@ -82,7 +77,7 @@ void *CPlugin::LoadSymbol(const char *sym) { } -// ______________________________________________________________________________________ + // GetInfo: Get DLL info bool CPlugin::GetInfo(PLUGIN_INFO& _pluginInfo) { if (m_GetDllInfo != NULL) { @@ -93,7 +88,7 @@ bool CPlugin::GetInfo(PLUGIN_INFO& _pluginInfo) { return(false); } -// ______________________________________________________________________________________ + // Config: Open the Config window void CPlugin::Config(HWND _hwnd) { @@ -102,7 +97,7 @@ void CPlugin::Config(HWND _hwnd) } -// ______________________________________________________________________________________ + // Debug: Open the Debugging window void CPlugin::Debug(HWND _hwnd, bool Show) { diff --git a/Source/Core/Common/Src/PluginVideo.cpp b/Source/Core/Common/Src/PluginVideo.cpp index b3330a42ed..d4176ee938 100644 --- a/Source/Core/Common/Src/PluginVideo.cpp +++ b/Source/Core/Common/Src/PluginVideo.cpp @@ -3,6 +3,14 @@ namespace Common { PluginVideo::PluginVideo(const char *_Filename) : CPlugin(_Filename), validVideo(false) { + Video_Prepare = 0; + Video_SendFifoData = 0; + Video_UpdateXFB = 0; + Video_EnterLoop = 0; + Video_Screenshot = 0; + Video_AddMessage = 0; + Video_Stop = 0; + Video_Prepare = reinterpret_cast (LoadSymbol("Video_Prepare")); Video_SendFifoData = reinterpret_cast @@ -28,6 +36,5 @@ namespace Common { validVideo = true; } - PluginVideo::~PluginVideo() { - } + PluginVideo::~PluginVideo() {} } diff --git a/Source/Core/Core/Src/Core.cpp b/Source/Core/Core/Src/Core.cpp index 2543993aa4..63d9acba3e 100644 --- a/Source/Core/Core/Src/Core.cpp +++ b/Source/Core/Core/Src/Core.cpp @@ -316,7 +316,6 @@ THREAD_RETURN EmuThread(void *pArg) VideoInitialize.pKeyPress = Callback_KeyPress; VideoInitialize.bWii = _CoreParameter.bWii; VideoInitialize.bUseDualCore = _CoreParameter.bUseDualCore; - Plugins.FreeVideo(); // This is needed for Stop and Start Plugins.GetVideo()->Initialize(&VideoInitialize); // Call the dll // Under linux, this is an X11 Display, not an HWND! diff --git a/Source/Core/Core/Src/PluginManager.cpp b/Source/Core/Core/Src/PluginManager.cpp index 3dd64a116b..f4dc7c44bf 100644 --- a/Source/Core/Core/Src/PluginManager.cpp +++ b/Source/Core/Core/Src/PluginManager.cpp @@ -133,24 +133,32 @@ bool CPluginManager::InitPlugins() void CPluginManager::ShutdownPlugins() { - // Check if we can shutdown the plugin for (int i = 0; i < MAXPADS; i++) { if (m_pad[i] && OkayToInitPlugin(i)) { - //Console::Print("Shutdown: %i\n", i); - m_pad[i]->Shutdown(); - //delete m_pad[i]; - } - //m_pad[i] = NULL; + Console::Print("Delete: %i\n", i); + delete m_pad[i]; + } + m_pad[i] = NULL; } - for (int i = 0; i < MAXWIIMOTES; i++) + for (int i = 0; i < MAXWIIMOTES; i++) { if (m_wiimote[i]) m_wiimote[i]->Shutdown(); - + } + + for (int i = 0; i < MAXWIIMOTES; i++) { + delete m_wiimote[i]; + m_wiimote[i] = NULL; + } + if (m_video) m_video->Shutdown(); - + delete m_video; + m_video = NULL; + if (m_dsp) m_dsp->Shutdown(); + delete m_dsp; + m_dsp = NULL; } // Supporting functions @@ -266,9 +274,9 @@ Common::PluginPAD *CPluginManager::GetPad(int controller) Console::Print("LoadPlugin: %i\n", controller); } else { - Console::Print("Pointed: %i to %i\n", controller, OkayToInitPlugin(controller)); - m_pad[controller] = m_pad[OkayToInitPlugin(controller)]; - } + Console::Print("Pointed: %i to %i\n", controller, OkayToInitPlugin(controller)); + m_pad[controller] = m_pad[OkayToInitPlugin(controller)]; + } return m_pad[controller]; } @@ -295,10 +303,13 @@ Common::PluginDSP *CPluginManager::GetDSP() Common::PluginVideo *CPluginManager::GetVideo() { - if (m_video != NULL) - if (m_video->GetFilename() == m_params.m_strVideoPlugin) + if (m_video != NULL && m_video->IsValid()) { + if (m_video->GetFilename() == m_params.m_strVideoPlugin) { return m_video; - + } else + FreeVideo(); + } + // Else load a new plugin m_video = (Common::PluginVideo*)LoadPlugin(m_params.m_strVideoPlugin.c_str()); return m_video;