Skip to content

Commit

Permalink
obs-vst3: Fix destruction of plugin
Browse files Browse the repository at this point in the history
The recent deferred destroy for sources creates issues because the tiny tubular thread calling destroy is not juce message manager thread.

Signed-off-by: pkv <pkv@obsproject.com>
  • Loading branch information
pkviet committed Apr 27, 2022
1 parent d3ba37a commit df02d84
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 22 deletions.
2 changes: 1 addition & 1 deletion libobs/obs.c
Original file line number Diff line number Diff line change
Expand Up @@ -916,7 +916,7 @@ static void obs_free_data(void)
FREE_OBS_LINKED_LIST(display);
FREE_OBS_LINKED_LIST(service);

// os_task_queue_wait(obs->destruction_task_thread);
os_task_queue_wait(obs->destruction_task_thread);

pthread_mutex_destroy(&data->sources_mutex);
pthread_mutex_destroy(&data->audio_sources_mutex);
Expand Down
4 changes: 2 additions & 2 deletions plugins/obs-vst3/data/locale/en-US.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
VSTPlugin.VST="VST Plugin"
VSTPlugin.VST3="VST3 Plugin"
VSTPlugin.VST="VST2 Plugin (juce)"
VSTPlugin.VST3="VST3 Plugin (juce)"
VSTPlugin.AudioUnit="AU Plugin"
"Plugin Description"="Plugin Description"
Plugin="Plugin or Plugin Path"
Expand Down
32 changes: 13 additions & 19 deletions plugins/obs-vst3/obs-vst3.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
#include <QDesktopWidget>
#include <QCursor>
#include <JuceHeader.h>
//#include <juce_audio_devices/midi_io/juce_MidiDevices.h>
//#include <juce_audio_processors/juce_audio_processors.h>

// global var to count the number of instances
uint count = 0;

int get_max_obs_channels()
{
Expand Down Expand Up @@ -311,6 +312,7 @@ template<class PluginFormat> class PluginHost : private AudioProcessorListener,
clear_vst();
}
descs.clear(true);
descs.~OwnedArray();
}

if (was_open)
Expand Down Expand Up @@ -388,7 +390,9 @@ template<class PluginFormat> class PluginHost : private AudioProcessorListener,
if (editor)
delete editor;
close_vst(vst_instance);
vst_instance = nullptr;
close_vst(new_vst_instance);
new_vst_instance = nullptr;
}

void host_clicked(AudioPluginInstance *inst = nullptr)
Expand Down Expand Up @@ -505,18 +509,7 @@ template<class PluginFormat> class PluginHost : private AudioProcessorListener,

obs_property_set_enabled(desc_list, has_options);
descs.clear(true);
return true;
}

static bool midi_selected_modified(
void *vptr, obs_properties_t *props, obs_property_t *property, obs_data_t *settings)
{
obs_property_list_clear(property);
juce::StringArray devices = MidiInput::getDevices();
obs_property_list_add_string(property, "", "");
for (int i = 0; i < devices.size(); i++)
obs_property_list_add_string(property, devices[i].toRawUTF8(), devices[i].toRawUTF8());

descs.~OwnedArray();
return true;
}

Expand All @@ -531,7 +524,6 @@ template<class PluginFormat> class PluginHost : private AudioProcessorListener,

obs_property_t *vst_list;
obs_property_t *desc_list;
obs_property_t *midi_list;

obs_property_t *vst_host_button;
obs_property_t *dpi_aware;
Expand All @@ -543,10 +535,6 @@ template<class PluginFormat> class PluginHost : private AudioProcessorListener,
desc_list = obs_properties_add_list(props, "desc", obs_module_text("Plugin Description"),
OBS_COMBO_TYPE_LIST, OBS_COMBO_FORMAT_STRING);

midi_list = obs_properties_add_list(
props, "midi", obs_module_text("Midi"), OBS_COMBO_TYPE_LIST, OBS_COMBO_FORMAT_STRING);
obs_property_set_modified_callback2(midi_list, midi_selected_modified, nullptr);

vst_host_button = obs_properties_add_button2(props, "vst_button", "Show", vst_host_clicked, plugin);

dpi_aware = obs_properties_add_bool(props, "dpi_aware", obs_module_text("DPI Aware"));
Expand Down Expand Up @@ -602,6 +590,8 @@ template<class PluginFormat> class PluginHost : private AudioProcessorListener,
plugin->incReferenceCount();
plugin->update(settings);
}
count++;
MessageManager::getInstance();
return plugin;
}

Expand All @@ -614,9 +604,13 @@ template<class PluginFormat> class PluginHost : private AudioProcessorListener,

static void Destroy(void *vptr)
{
MessageManager::getInstance()->MessageManager::setCurrentThreadAsMessageThread();
PluginHost *plugin = static_cast<PluginHost *>(vptr);
if (plugin)
plugin->decReferenceCount();
count--;
if (count == 0)
MessageManager::deleteInstance();
}

static struct obs_audio_data *Filter_Audio(void *vptr, struct obs_audio_data *audio)
Expand Down

0 comments on commit df02d84

Please sign in to comment.