summaryrefslogtreecommitdiff
path: root/Source/Core
diff options
context:
space:
mode:
authorayuanx <ayuanx@gmail.com>2009-12-30 14:37:12 +0000
committerayuanx <ayuanx@gmail.com>2009-12-30 14:37:12 +0000
commit151ff28ab7dd1fd0343587f194bf8620d5fc3620 (patch)
treea47f43544c2c44fc52b529f3eacf2c78c3b8c490 /Source/Core
parent97779ea295b025d013ed07fc3b0f6bf99def6c5a (diff)
Fixed mem leak caused by not releasing pad & wiimote plugin when shutdown
Fixed main frame crash after shutdown git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@4755 8ced0084-cf51-0410-be5f-012b33b47a6e
Diffstat (limited to 'Source/Core')
-rw-r--r--Source/Core/Core/Src/Core.cpp50
-rw-r--r--Source/Core/Core/Src/CoreParameter.h2
-rw-r--r--Source/Core/Core/Src/HW/SI_DeviceAMBaseboard.cpp4
-rw-r--r--Source/Core/Core/Src/HW/SI_DeviceGCController.cpp4
-rw-r--r--Source/Core/Core/Src/PluginManager.cpp59
-rw-r--r--Source/Core/Core/Src/PluginManager.h1
-rw-r--r--Source/Core/VideoCommon/Src/CommandProcessor.cpp40
-rw-r--r--Source/Core/VideoCommon/Src/CommandProcessor.h4
8 files changed, 70 insertions, 94 deletions
diff --git a/Source/Core/Core/Src/Core.cpp b/Source/Core/Core/Src/Core.cpp
index 7d36529f77..4e48bde02e 100644
--- a/Source/Core/Core/Src/Core.cpp
+++ b/Source/Core/Core/Src/Core.cpp
@@ -213,19 +213,15 @@ void Stop() // - Hammertime!
PowerPC::Stop();
CCPU::StepOpcode(); // Kick it if it's waiting (code stepping wait loop)
- // Wait until the CPU finishes exiting the main run loop
- cpuRunloopQuit.Wait();
- cpuRunloopQuit.Shutdown();
- // At this point, we must be out of the CPU:s runloop.
-
- // Stop audio thread.
- CPluginManager::GetInstance().GetDSP()->DSP_StopSoundStream();
-
// If dual core mode, the CPU thread should immediately exit here.
if (_CoreParameter.bCPUThread) {
NOTICE_LOG(CONSOLE, "%s", StopMessage(true, "Wait for Video Loop to exit ...").c_str());
CPluginManager::GetInstance().GetVideo()->Video_ExitLoop();
}
+ // Wait until the CPU finishes exiting the main run loop
+ cpuRunloopQuit.Wait();
+ cpuRunloopQuit.Shutdown();
+ // At this point, we must be out of the CPU:s runloop.
// Video_EnterLoop() should now exit so that EmuThread() will continue concurrently with the rest
// of the commands in this function. We no longer rely on Postmessage.
@@ -296,7 +292,6 @@ THREAD_RETURN CpuThread(void *pArg)
// Enter CPU run loop. When we leave it - we are done.
CCPU::Run();
- cpuRunloopQuit.Set();
return 0;
}
@@ -369,30 +364,13 @@ THREAD_RETURN EmuThread(void *pArg)
dspInit.bOnThread = _CoreParameter.bDSPThread;
Plugins.GetDSP()->Initialize((void *)&dspInit);
-
- // Load and Init PadPlugin
- for (int i = 0; i < MAXPADS; i++)
- {
- SPADInitialize PADInitialize;
- PADInitialize.hWnd = g_pWindowHandle;
- PADInitialize.pLog = Callback_PADLog;
- PADInitialize.padNumber = i;
- // This is may be needed to avoid a SDL problem
- //Plugins.FreeWiimote();
- // Check if we should init the plugin
- if (Plugins.OkayToInitPlugin(i))
- {
- Plugins.GetPad(i)->Initialize(&PADInitialize);
-
- // Check if joypad open failed, in that case try again
- if (PADInitialize.padNumber == -1)
- {
- Plugins.GetPad(i)->Shutdown();
- Plugins.FreePad(i);
- Plugins.GetPad(i)->Initialize(&PADInitialize);
- }
- }
- }
+
+ SPADInitialize PADInitialize;
+ PADInitialize.hWnd = g_pWindowHandle;
+ PADInitialize.pLog = Callback_PADLog;
+ // This is may be needed to avoid a SDL problem
+ //Plugins.FreeWiimote();
+ Plugins.GetPad(0)->Initialize(&PADInitialize);
// Load and Init WiimotePlugin - only if we are booting in wii mode
if (_CoreParameter.bWii)
@@ -459,7 +437,6 @@ THREAD_RETURN EmuThread(void *pArg)
// then we lose the powerdown check. ... unless powerdown sends a message :P
while (PowerPC::GetState() != PowerPC::CPU_POWERDOWN)
{
- Host_UpdateMainFrame();
if (Callback_PeekMessages)
Callback_PeekMessages();
Common::SleepCurrentThread(20);
@@ -507,6 +484,8 @@ THREAD_RETURN EmuThread(void *pArg)
// We have now exited the Video Loop and will shut down
g_bHwInit = false;
+ // Stop audio thread.
+ Plugins.GetDSP()->DSP_StopSoundStream();
WARN_LOG(CONSOLE, "%s", StopMessage(false, "Shutting down plugins").c_str());
Plugins.ShutdownVideoPlugin();
@@ -521,8 +500,7 @@ THREAD_RETURN EmuThread(void *pArg)
NOTICE_LOG(CONSOLE, "Stop [Main Thread]\t\t---- Shutdown complete ----");
g_bStopping = false;
-
- Host_UpdateMainFrame();
+ cpuRunloopQuit.Set();
return 0;
}
diff --git a/Source/Core/Core/Src/CoreParameter.h b/Source/Core/Core/Src/CoreParameter.h
index 28ae9bd131..c3079a8835 100644
--- a/Source/Core/Core/Src/CoreParameter.h
+++ b/Source/Core/Core/Src/CoreParameter.h
@@ -25,7 +25,7 @@
#include "IniFile.h"
#include <string>
-#define MAXPADS 4
+#define MAXPADS 1
#define MAXWIIMOTES 1
struct SCoreStartupParameter
diff --git a/Source/Core/Core/Src/HW/SI_DeviceAMBaseboard.cpp b/Source/Core/Core/Src/HW/SI_DeviceAMBaseboard.cpp
index 3af82f4c23..79b40d7bdc 100644
--- a/Source/Core/Core/Src/HW/SI_DeviceAMBaseboard.cpp
+++ b/Source/Core/Core/Src/HW/SI_DeviceAMBaseboard.cpp
@@ -144,7 +144,7 @@ int CSIDevice_AMBaseboard::RunBuffer(u8* _pBuffer, int _iLength)
DEBUG_LOG(AMBASEBOARDDEBUG, "GC-AM: CMD 10, %02x (READ STATUS&SWITCHES)", ptr(1));
SPADStatus PadStatus;
memset(&PadStatus, 0 ,sizeof(PadStatus));
- CPluginManager::GetInstance().GetPad(ISIDevice::m_iDeviceNumber)
+ CPluginManager::GetInstance().GetPad(0)
->PAD_GetStatus(ISIDevice::m_iDeviceNumber, &PadStatus);
res[resp++] = 0x10;
res[resp++] = 0x2;
@@ -312,7 +312,7 @@ int CSIDevice_AMBaseboard::RunBuffer(u8* _pBuffer, int _iLength)
for (i=0; i<nr_players; ++i)
{
SPADStatus PadStatus;
- CPluginManager::GetInstance().GetPad(i)
+ CPluginManager::GetInstance().GetPad(0)
->PAD_GetStatus(i, &PadStatus);
unsigned char player_data[2] = {0,0};
if (PadStatus.button & PAD_BUTTON_START)
diff --git a/Source/Core/Core/Src/HW/SI_DeviceGCController.cpp b/Source/Core/Core/Src/HW/SI_DeviceGCController.cpp
index 50cde1edfe..457139b821 100644
--- a/Source/Core/Core/Src/HW/SI_DeviceGCController.cpp
+++ b/Source/Core/Core/Src/HW/SI_DeviceGCController.cpp
@@ -128,7 +128,7 @@ bool CSIDevice_GCController::GetData(u32& _Hi, u32& _Low)
{
SPADStatus PadStatus;
memset(&PadStatus, 0, sizeof(PadStatus));
- Common::PluginPAD* pad = CPluginManager::GetInstance().GetPad(ISIDevice::m_iDeviceNumber);
+ Common::PluginPAD* pad = CPluginManager::GetInstance().GetPad(0);
pad->PAD_GetStatus(ISIDevice::m_iDeviceNumber, &PadStatus);
#if defined(HAVE_SFML) && HAVE_SFML
@@ -257,7 +257,7 @@ bool CSIDevice_GCController::GetData(u32& _Hi, u32& _Low)
// SendCommand
void CSIDevice_GCController::SendCommand(u32 _Cmd, u8 _Poll)
{
- Common::PluginPAD* pad = CPluginManager::GetInstance().GetPad(ISIDevice::m_iDeviceNumber);
+ Common::PluginPAD* pad = CPluginManager::GetInstance().GetPad(0);
UCommand command(_Cmd);
switch (command.Command)
diff --git a/Source/Core/Core/Src/PluginManager.cpp b/Source/Core/Core/Src/PluginManager.cpp
index 0c5ed2d6f7..8bbc72b226 100644
--- a/Source/Core/Core/Src/PluginManager.cpp
+++ b/Source/Core/Core/Src/PluginManager.cpp
@@ -76,17 +76,21 @@ CPluginManager::~CPluginManager()
for (int i = 0; i < MAXPADS; i++)
{
- if (m_pad[i] && (OkayToInitPlugin(i) == -1))
+ if (m_pad[i])
{
- INFO_LOG(CONSOLE, "Delete: %i\n", i);
delete m_pad[i];
+ m_pad[i] = NULL;
}
- m_pad[i] = NULL;
}
for (int i = 0; i < MAXWIIMOTES; i++)
+ {
if (m_wiimote[i])
+ {
delete m_wiimote[i];
+ m_wiimote[i] = NULL;
+ }
+ }
delete m_video;
}
@@ -139,15 +143,18 @@ bool CPluginManager::InitPlugins()
}
// Init wiimote
- if (m_params->bWii) {
- for (int i = 0; i < MAXWIIMOTES; i++) {
+ if (m_params->bWii)
+ {
+ for (int i = 0; i < MAXWIIMOTES; i++)
+ {
if (!m_params->m_strWiimotePlugin[i].empty())
GetWiimote(i);
if (m_wiimote[i] != NULL)
wiimote = true;
}
- if (!wiimote) {
+ if (!wiimote)
+ {
PanicAlert("Can't init any Wiimote Plugins");
return false;
}
@@ -161,13 +168,13 @@ bool CPluginManager::InitPlugins()
// for an explanation about the current LoadLibrary() and FreeLibrary() behavior.
void CPluginManager::ShutdownPlugins()
{
- for (int i = 0; i < MAXPADS; i++) {
+ for (int i = 0; i < MAXPADS; i++)
+ {
if (m_pad[i])
{
m_pad[i]->Shutdown();
- //delete m_pad[i];
+ FreePad(i);
}
- //m_pad[i] = NULL;
}
for (int i = 0; i < MAXWIIMOTES; i++)
@@ -175,9 +182,8 @@ void CPluginManager::ShutdownPlugins()
if (m_wiimote[i])
{
m_wiimote[i]->Shutdown();
- //delete m_wiimote[i];
+ FreeWiimote(i);
}
- //m_wiimote[i] = NULL;
}
if (m_dsp)
@@ -224,7 +230,9 @@ CPluginInfo::CPluginInfo(const char *_rFilename)
PanicAlert("Could not get info about plugin %s", _rFilename);
// We are now done with this plugin and will call FreeLibrary()
delete plugin;
- } else {
+ }
+ else
+ {
WARN_LOG(CONSOLE, "PluginInfo: %s is not a valid Dolphin plugin. Ignoring.", _rFilename);
}
}
@@ -308,19 +316,6 @@ void *CPluginManager::LoadPlugin(const char *_rFilename, int Number)
return plugin;
}
-/* Check if the plugin has already been initialized. If so, return the Id of
- the duplicate pad so we can point the new m_pad[] to that */
-int CPluginManager::OkayToInitPlugin(int Plugin)
-{
- // Compare it to the earlier plugins
- for (int i = 0; i < Plugin; i++)
- if (m_params->m_strPadPlugin[Plugin] == m_params->m_strPadPlugin[i])
- return i;
-
- // No there is no duplicate plugin
- return -1;
-}
-
PLUGIN_GLOBALS* CPluginManager::GetGlobals()
{
return m_PluginGlobals;
@@ -386,15 +381,8 @@ Common::PluginPAD *CPluginManager::GetPad(int controller)
if (m_pad[controller]->GetFilename() == m_params->m_strPadPlugin[controller])
return m_pad[controller];
- // Else do this
- if (OkayToInitPlugin(controller) == -1) {
- m_pad[controller] = (Common::PluginPAD*)LoadPlugin(m_params->m_strPadPlugin[controller].c_str(), controller);
- INFO_LOG(CONSOLE, "LoadPlugin: %i", controller);
- }
- else {
- INFO_LOG(CONSOLE, "Pointed: %i to %i", controller, OkayToInitPlugin(controller));
- m_pad[controller] = m_pad[OkayToInitPlugin(controller)];
- }
+ // Else load a new plugin
+ m_pad[controller] = (Common::PluginPAD*)LoadPlugin(m_params->m_strPadPlugin[controller].c_str());
return m_pad[controller];
}
@@ -458,7 +446,8 @@ void CPluginManager::FreeDSP()
void CPluginManager::FreePad(u32 Pad)
{
- if (Pad < MAXPADS) {
+ if (Pad < MAXPADS)
+ {
delete m_pad[Pad];
m_pad[Pad] = NULL;
}
diff --git a/Source/Core/Core/Src/PluginManager.h b/Source/Core/Core/Src/PluginManager.h
index 134c389118..1d2fac10c2 100644
--- a/Source/Core/Core/Src/PluginManager.h
+++ b/Source/Core/Core/Src/PluginManager.h
@@ -60,7 +60,6 @@ public:
bool InitPlugins();
void ShutdownPlugins();
void ShutdownVideoPlugin();
- int OkayToInitPlugin(int Plugin);
void ScanForPlugins();
void OpenConfig(void* _Parent, const char *_rFilename, PLUGIN_TYPE Type);
void OpenDebug(void* _Parent, const char *_rFilename, PLUGIN_TYPE Type, bool Show);
diff --git a/Source/Core/VideoCommon/Src/CommandProcessor.cpp b/Source/Core/VideoCommon/Src/CommandProcessor.cpp
index 7c0864d692..a9151af1b0 100644
--- a/Source/Core/VideoCommon/Src/CommandProcessor.cpp
+++ b/Source/Core/VideoCommon/Src/CommandProcessor.cpp
@@ -133,11 +133,6 @@ inline void WriteHigh(volatile u32& _reg, u16 highbits) {Common::AtomicStore(_re
inline u16 ReadLow (u32 _reg) {return (u16)(_reg & 0xFFFF);}
inline u16 ReadHigh (u32 _reg) {return (u16)(_reg >> 16);}
-void UpdateInterrupts_Wrapper(u64 userdata, int cyclesLate)
-{
- UpdateInterrupts();
-}
-
void Init()
{
m_CPStatusReg.Hex = 0;
@@ -161,7 +156,7 @@ void Init()
s_fifoIdleEvent.Init();
- et_UpdateInterrupts = g_VideoInitialize.pRegisterEvent("UpdateInterrupts", UpdateInterrupts_Wrapper);
+// et_UpdateInterrupts = g_VideoInitialize.pRegisterEvent("UpdateInterrupts", UpdateInterrupts_Wrapper);
}
void Shutdown()
@@ -187,7 +182,7 @@ void Read16(u16& _rReturnValue, const u32 _Address)
m_CPStatusReg.ReadIdle = fifo.CPReadIdle; // This seems not necessary though
m_CPStatusReg.Breakpoint = fifo.bFF_Breakpoint;
// Clear on Read
- g_VideoInitialize.pSetInterrupt(INT_CAUSE_CP, false);
+ UpdateInterrupts(false);
_rReturnValue = m_CPStatusReg.Hex;
@@ -358,14 +353,22 @@ void Write16(const u16 _Value, const u32 _Address)
{
// Instant Breakpoint and Interrupt, since we haven't implemented accurate BP on dual core
// Most likely the Read thread has already exceeded BP here, but it seems we are still cool
- Common::AtomicStore(fifo.bFF_Breakpoint, tmpCtrl.BPEnable && tmpCtrl.CPIntEnable && tmpCtrl.GPReadEnable);
- UpdateInterrupts();
+ if (tmpCtrl.BPEnable && tmpCtrl.CPIntEnable && tmpCtrl.GPReadEnable && tmpCtrl.GPLinkEnable)
+ {
+ Common::AtomicStore(fifo.bFF_Breakpoint, 1);
+ UpdateInterrupts(true);
+ }
+ else
+ {
+ Common::AtomicStore(fifo.bFF_Breakpoint, 0);
+ }
+
}
else
{
// fifo.bFF_BPEnable is only used in single core
- Common::AtomicStore(fifo.bFF_BPEnable, tmpCtrl.BPEnable && tmpCtrl.CPIntEnable && tmpCtrl.GPReadEnable);
- if (!tmpCtrl.BPEnable || !tmpCtrl.CPIntEnable || !tmpCtrl.GPReadEnable)
+ Common::AtomicStore(fifo.bFF_BPEnable, tmpCtrl.BPEnable && tmpCtrl.CPIntEnable && tmpCtrl.GPReadEnable && tmpCtrl.GPLinkEnable);
+ if (!tmpCtrl.BPEnable || !tmpCtrl.CPIntEnable || !tmpCtrl.GPReadEnable || !tmpCtrl.GPLinkEnable)
Common::AtomicStore(fifo.bFF_Breakpoint, 0);
}
@@ -608,7 +611,7 @@ void CatchUpGPU()
{
//_assert_msg_(POWERPC,0,"BP: %08x",fifo.CPBreakpoint);
fifo.bFF_Breakpoint = 1;
- UpdateInterrupts();
+ UpdateInterrupts(true);
break;
}
}
@@ -669,17 +672,24 @@ void UpdateFifoRegister()
CatchUpGPU();
}
-void UpdateInterrupts()
+void UpdateInterrupts(bool active)
{
- DEBUG_LOG(COMMANDPROCESSOR, "Fifo Breakpoint Interrupt triggered");
- g_VideoInitialize.pSetInterrupt(INT_CAUSE_CP, true);
+ DEBUG_LOG(COMMANDPROCESSOR, "Fifo Breakpoint Interrupt: %s", (active)? "Asserted" : "Deasserted");
+ g_VideoInitialize.pSetInterrupt(INT_CAUSE_CP, active);
}
+/*
void UpdateInterruptsFromVideoPlugin()
{
g_VideoInitialize.pScheduleEvent_Threadsafe(0, et_UpdateInterrupts, 0);
}
+void UpdateInterrupts_Wrapper(u64 userdata, int cyclesLate)
+{
+ UpdateInterrupts();
+}
+*/
+
void SetFifoIdleFromVideoPlugin()
{
s_fifoIdleEvent.Set();
diff --git a/Source/Core/VideoCommon/Src/CommandProcessor.h b/Source/Core/VideoCommon/Src/CommandProcessor.h
index 1a3a47ace8..668b2c2f34 100644
--- a/Source/Core/VideoCommon/Src/CommandProcessor.h
+++ b/Source/Core/VideoCommon/Src/CommandProcessor.h
@@ -148,8 +148,8 @@ void Write32(const u32 _Data, const u32 _Address);
void CatchUpGPU();
void GatherPipeBursted();
void UpdateFifoRegister();
-void UpdateInterrupts();
-void UpdateInterruptsFromVideoPlugin();
+void UpdateInterrupts(bool active);
+//void UpdateInterruptsFromVideoPlugin();
void SetFifoIdleFromVideoPlugin();
bool AllowIdleSkipping();