Skip to content

Commit

Permalink
Fix hang when updateInOutCount called from processReplacing
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
DomClark authored and PhysSong committed Sep 11, 2018
1 parent de427bb commit cc2ae66
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions plugins/vst_base/RemoteVstPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ class RemoteVstPlugin;
RemoteVstPlugin * __plugin = NULL;

HWND __MessageHwnd = NULL;
DWORD __processingThreadId = 0;



Expand Down Expand Up @@ -251,7 +252,7 @@ class RemoteVstPlugin : public RemotePluginClient
}

// has to be called as soon as input- or output-count changes
void updateInOutCount();
int updateInOutCount();

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



void RemoteVstPlugin::updateInOutCount()
int RemoteVstPlugin::updateInOutCount()
{
if( inputCount() == RemotePluginClient::inputCount() &&
outputCount() == RemotePluginClient::outputCount() )
{
return 1;
}

if( GetCurrentThreadId() == __processingThreadId )
{
debugMessage( "Plugin requested I/O change from processing "
"thread. Request denied; stability may suffer.\n" );
return 0;
}

lockShm();

setShmIsValid( false );
Expand Down Expand Up @@ -1467,6 +1481,8 @@ void RemoteVstPlugin::updateInOutCount()
{
m_outputs = new float * [outputCount()];
}

return 1;
}


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

case audioMasterIOChanged:
__plugin->updateInOutCount();
SHOW_CALLBACK( "amc: audioMasterIOChanged\n" );
// numInputs and/or numOutputs has changed
return 0;
// numInputs, numOutputs, and/or latency has changed
return __plugin->updateInOutCount();

#ifdef OLD_VST_SDK
case audioMasterWantMidi:
Expand Down Expand Up @@ -1897,6 +1912,8 @@ void RemoteVstPlugin::processUIThreadMessages()

DWORD WINAPI RemoteVstPlugin::processingThread( LPVOID _param )
{
__processingThreadId = GetCurrentThreadId();

RemoteVstPlugin * _this = static_cast<RemoteVstPlugin *>( _param );

RemotePluginClient::message m;
Expand Down

0 comments on commit cc2ae66

Please sign in to comment.