Skip to content

Commit cc2ae66

Browse files
DomClarkPhysSong
authored andcommitted
Fix hang when updateInOutCount called from processReplacing
Ignore requests to change the I/O count from within processReplacing and print a warning instead; the shared memory is in use so it can't be reallocated. Add a special case to return immediately if the I/O count hasn't changed at all; this will prevent spurious warnings when the plugin is only updating the latency and should reduce unnecessary reallocations in general.
1 parent de427bb commit cc2ae66

1 file changed

Lines changed: 22 additions & 5 deletions

File tree

plugins/vst_base/RemoteVstPlugin.cpp

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ class RemoteVstPlugin;
118118
RemoteVstPlugin * __plugin = NULL;
119119

120120
HWND __MessageHwnd = NULL;
121+
DWORD __processingThreadId = 0;
121122

122123

123124

@@ -251,7 +252,7 @@ class RemoteVstPlugin : public RemotePluginClient
251252
}
252253

253254
// has to be called as soon as input- or output-count changes
254-
void updateInOutCount();
255+
int updateInOutCount();
255256

256257
inline void lockShm()
257258
{
@@ -1438,8 +1439,21 @@ void RemoteVstPlugin::loadChunkFromFile( const std::string & _file, int _len )
14381439

14391440

14401441

1441-
void RemoteVstPlugin::updateInOutCount()
1442+
int RemoteVstPlugin::updateInOutCount()
14421443
{
1444+
if( inputCount() == RemotePluginClient::inputCount() &&
1445+
outputCount() == RemotePluginClient::outputCount() )
1446+
{
1447+
return 1;
1448+
}
1449+
1450+
if( GetCurrentThreadId() == __processingThreadId )
1451+
{
1452+
debugMessage( "Plugin requested I/O change from processing "
1453+
"thread. Request denied; stability may suffer.\n" );
1454+
return 0;
1455+
}
1456+
14431457
lockShm();
14441458

14451459
setShmIsValid( false );
@@ -1467,6 +1481,8 @@ void RemoteVstPlugin::updateInOutCount()
14671481
{
14681482
m_outputs = new float * [outputCount()];
14691483
}
1484+
1485+
return 1;
14701486
}
14711487

14721488

@@ -1611,10 +1627,9 @@ intptr_t RemoteVstPlugin::hostCallback( AEffect * _effect, int32_t _opcode,
16111627
return 0;
16121628

16131629
case audioMasterIOChanged:
1614-
__plugin->updateInOutCount();
16151630
SHOW_CALLBACK( "amc: audioMasterIOChanged\n" );
1616-
// numInputs and/or numOutputs has changed
1617-
return 0;
1631+
// numInputs, numOutputs, and/or latency has changed
1632+
return __plugin->updateInOutCount();
16181633

16191634
#ifdef OLD_VST_SDK
16201635
case audioMasterWantMidi:
@@ -1897,6 +1912,8 @@ void RemoteVstPlugin::processUIThreadMessages()
18971912

18981913
DWORD WINAPI RemoteVstPlugin::processingThread( LPVOID _param )
18991914
{
1915+
__processingThreadId = GetCurrentThreadId();
1916+
19001917
RemoteVstPlugin * _this = static_cast<RemoteVstPlugin *>( _param );
19011918

19021919
RemotePluginClient::message m;

0 commit comments

Comments
 (0)