From: <sag...@us...> - 2014-02-14 20:06:24
|
Revision: 3713 http://sourceforge.net/p/modplug/code/3713 Author: saga-games Date: 2014-02-14 20:06:12 +0000 (Fri, 14 Feb 2014) Log Message: ----------- [Ref] Add SNDMIXPLUGIN::Destroy to unify plugin destroy code (shouldn't leak anymore when throwing away the last plugin due to moving around other slots) Modified Paths: -------------- trunk/OpenMPT/mptrack/SelectPluginDialog.cpp trunk/OpenMPT/mptrack/View_gen.cpp trunk/OpenMPT/soundlib/Sndfile.cpp trunk/OpenMPT/soundlib/plugins/PlugInterface.h Modified: trunk/OpenMPT/mptrack/SelectPluginDialog.cpp =================================================================== --- trunk/OpenMPT/mptrack/SelectPluginDialog.cpp 2014-02-14 00:16:27 UTC (rev 3712) +++ trunk/OpenMPT/mptrack/SelectPluginDialog.cpp 2014-02-14 20:06:12 UTC (rev 3713) @@ -123,20 +123,9 @@ { CriticalSection cs; - if (pCurrentPlugin != nullptr) - { - pCurrentPlugin->Release(); - } + // Destroy old plugin, if there was one. + m_pPlugin->Destroy(); - // Just in case... - m_pPlugin->pMixPlugin = nullptr; - m_pPlugin->pMixState = nullptr; - - // Remove old state - m_pPlugin->nPluginDataSize = 0; - if (m_pPlugin->pPluginData) delete[] m_pPlugin->pPluginData; - m_pPlugin->pPluginData = nullptr; - // Initialize plugin info MemsetZero(m_pPlugin->Info); m_pPlugin->Info.dwPluginId1 = pFactory->pluginId1; Modified: trunk/OpenMPT/mptrack/View_gen.cpp =================================================================== --- trunk/OpenMPT/mptrack/View_gen.cpp 2014-02-14 00:16:27 UTC (rev 3712) +++ trunk/OpenMPT/mptrack/View_gen.cpp 2014-02-14 20:06:12 UTC (rev 3713) @@ -1342,9 +1342,7 @@ MovePlug(MAX_MIXPLUGINS - 1, MAX_MIXPLUGINS - 2, true); } else { - pSndFile->m_MixPlugins[MAX_MIXPLUGINS - 1].pMixPlugin->Release(); - memset(&(pSndFile->m_MixPlugins[MAX_MIXPLUGINS - 1]), 0, sizeof(SNDMIXPLUGIN)); - //possible mem leak here... + pSndFile->m_MixPlugins[MAX_MIXPLUGINS - 1].Destroy(); } } Modified: trunk/OpenMPT/soundlib/Sndfile.cpp =================================================================== --- trunk/OpenMPT/soundlib/Sndfile.cpp 2014-02-14 00:16:27 UTC (rev 3712) +++ trunk/OpenMPT/soundlib/Sndfile.cpp 2014-02-14 20:06:12 UTC (rev 3713) @@ -1016,18 +1016,7 @@ } for(PLUGINDEX i = 0; i < MAX_MIXPLUGINS; i++) { - if ((m_MixPlugins[i].nPluginDataSize) && (m_MixPlugins[i].pPluginData)) - { - m_MixPlugins[i].nPluginDataSize = 0; - delete[] m_MixPlugins[i].pPluginData; - m_MixPlugins[i].pPluginData = NULL; - } - m_MixPlugins[i].pMixState = NULL; - if (m_MixPlugins[i].pMixPlugin) - { - m_MixPlugins[i].pMixPlugin->Release(); - m_MixPlugins[i].pMixPlugin = NULL; - } + m_MixPlugins[i].Destroy(); } m_nType = MOD_TYPE_NONE; @@ -2150,7 +2139,7 @@ { UpgradePatternData(CSoundFile &sf) : sndFile(sf), chn(0) { } - void operator()(ModCommand& m) + void operator() (ModCommand &m) { if(m.IsPcNote()) { @@ -2165,7 +2154,7 @@ // Out-of-range global volume commands should be ignored. // OpenMPT 1.17.03.02 fixed this in compatible mode, OpenMPT 1.20 fixes it in normal mode as well. // So for tracks made with older versions than OpenMPT 1.17.03.02 or tracks made with 1.17.03.02 <= version < 1.20, we limit invalid global volume commands. - LimitMax(m.param, (sndFile.GetType() & (MOD_TYPE_IT | MOD_TYPE_MPT)) ? BYTE(128): BYTE(64)); + LimitMax(m.param, ModCommand::PARAM((sndFile.GetType() & (MOD_TYPE_IT | MOD_TYPE_MPT)) ? 128: 64)); } else if(m.command == CMD_S3MCMDEX && (sndFile.GetType() & (MOD_TYPE_IT | MOD_TYPE_MPT))) { // SC0 and SD0 should be interpreted as SC1 and SD1 in IT files. @@ -2231,8 +2220,7 @@ // OpenMPT 1.20 fixes multiple fine pattern delays on the same row. Previously, only the last command was considered, // but all commands should be added up. Since Scream Tracker 3 itself doesn't support S6x, we also use Impulse Tracker's behaviour here, // since we can assume that most S3Ms that make use of S6x were composed with Impulse Tracker. - ModCommand *fixCmd = (&m) - chn; - for(CHANNELINDEX i = 0; i < chn; i++, fixCmd++) + for(ModCommand *fixCmd = (&m) - chn; fixCmd < &m; fixCmd++) { if((fixCmd->command == CMD_S3MCMDEX || fixCmd->command == CMD_XFINEPORTAUPDOWN) && (fixCmd->param & 0xF0) == 0x60) { @@ -2245,8 +2233,7 @@ { // OpenMPT 1.20 fixes multiple pattern delays on the same row. Previously, only the *last* command was considered, // but Scream Tracker 3 and Impulse Tracker only consider the *first* command. - ModCommand *fixCmd = (&m) - chn; - for(CHANNELINDEX i = 0; i < chn; i++, fixCmd++) + for(ModCommand *fixCmd = (&m) - chn; fixCmd < &m; fixCmd++) { if(fixCmd->command == CMD_S3MCMDEX && (fixCmd->param & 0xF0) == 0xE0) { Modified: trunk/OpenMPT/soundlib/plugins/PlugInterface.h =================================================================== --- trunk/OpenMPT/soundlib/plugins/PlugInterface.h 2014-02-14 00:16:27 UTC (rev 3712) +++ trunk/OpenMPT/soundlib/plugins/PlugInterface.h 2014-02-14 20:06:12 UTC (rev 3713) @@ -208,7 +208,20 @@ void SetOutputPlugin(PLUGINDEX plugin) { if(plugin < MAX_MIXPLUGINS) Info.dwOutputRouting = plugin + 0x80; else Info.dwOutputRouting = 0; } -}; // rewbs.dryRatio: Hopefully this doesn't need to be a fixed size. + void Destroy() + { + delete[] pPluginData; + pPluginData = nullptr; + nPluginDataSize = 0; + pMixState = nullptr; + if(pMixPlugin) + { + pMixPlugin->Release(); + pMixPlugin = nullptr; + } + } +}; + class CSoundFile; typedef bool (*PMIXPLUGINCREATEPROC)(SNDMIXPLUGIN &, CSoundFile &); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |