# VFLib & plugin issue

**URL:** <https://forum.juce.com/t/vflib-plugin-issue/10006>\
**Category:** Useful Tools and Components\
**Created:** [February 21, 2013, 12:49pm UTC](https://forum.juce.com/t/vflib-plugin-issue/10006 "2013-02-21T12:49:48Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![lalala](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/lalala/32/8577_2.png) [@lalala](https://forum.juce.com/u/lalala)\
**Post date:** [February 21, 2013, 12:49pm UTC](https://forum.juce.com/t/vflib-plugin-issue/10006/1 "2013-02-21T12:49:48Z")

</div>

hi,

Here below is the crash I got, which tells me that “calls are being made after the queue is closed, and probably there is no one around to process it.”  
But I really don’t get what’s going on…

The plugin is simpleDJ, embedded in an introjucer generated plugin.  
So what I just added in the introjucer generated code is :

in PluginProcessor.h :

`public:
    ScopedPointer <Mixer> m_mixer;`

in PluginProcessor.cpp :

```auto
NewProjectAudioProcessor::NewProjectAudioProcessor()
{
    m_mixer = Mixer::New ();
}
```

in PluginEditor.cpp :

```auto
NewProjectAudioProcessorEditor::NewProjectAudioProcessorEditor (NewProjectAudioProcessor* ownerFilter)
    : AudioProcessorEditor (ownerFilter)
{
    CMain* contentComponent = new CMain (*ownerFilter->m_mixer);
    addAndMakeVisible(contentComponent);
    setSize (800, 500);
}

NewProjectAudioProcessorEditor::~NewProjectAudioProcessorEditor()
{
    deleteAllChildren();
}

```

Everything seems to be ok when I use jule’s pluginHost.  
But it crashes when I use my VST in reaper.  
everything seems fine at first, I can instantiate many plugins, etc.  
The issue appears if I remove all the instantiated plugins and create a new one.  
(i.e, to reproduce, I create one instance, remove it, then create a new one).

Any idea what’s going on?

> [@](#):
>
> Thread 0 Crashed:: Dispatch queue: com.apple.main-thread  
> 0 com.yourcompany.NewProject 0x1081f3a2 vf::CallQueue::queuep(vf::CallQueue::Work\*) + 290 (vf\_CallQueue.cpp:62)  
> 1 com.yourcompany.NewProject 0x108205e7 vf::ListenersBase::Group::queue1(vf::ListenersBase::Call\*, unsigned long, void\*) + 183 (vf\_Listeners.cpp:268)  
> 2 com.yourcompany.NewProject 0x10822f3f vf::ListenersBase::queue1p\_void(void\*, vf::ListenersBase::Call\*) + 287 (vf\_Listeners.cpp:698)  
> 3 com.yourcompany.NewProject 0x1083d56f vf::ListenersParam::Listener::queue1p(Param::Listener\*, juce::ReferenceCountedObjectPtrvf::ListenersBase::Call) + 63 (vf\_Listeners.h:396)  
> 4 com.yourcompany.NewProject 0x1083d4c8 void vf::ListenersParam::Listener::queue1f\<std::tr1::_Bind\<std::tr1::Mem\_fn\<void (Param::Listener::)(Param, double)\> (std::tr1::Placeholder\<1\>, Param\*, double)\> \>(Param::Listener\*, std::tr1::Bind\<std::tr1::Mem\_fn\<void (Param::Listener::)(Param, double)\> (std::tr1::Placeholder\<1\>, Param\*, double)\> const&) + 184 (vf\_Listeners.h:407)  
> 5 com.yourcompany.NewProject 0x1083c35f void vf::ListenersParam::Listener::queue1\<void (Param::Listener::)(Param, double), Param\*, double\>(Param::Listener\*, void (Param::Listener::)(Param, double), Param\*, double) + 143 (vf\_Listeners.h:761)  
> 6 com.yourcompany.NewProject 0x1083bed1 Param::addListener(Param::Listener\*, vf::CallQueue&) + 337 (Param.cpp:57)  
> 7 com.yourcompany.NewProject 0x10847d99 CSpeedControl::CSpeedControl(Param&) + 169 (CSpeedControl.cpp:35)  
> 8 com.yourcompany.NewProject 0x10847ce4 CSpeedControl::CSpeedControl(Param&) + 36 (CSpeedControl.cpp:41)  
> 9 com.yourcompany.NewProject 0x1084026a CDeck::CDeck(int, juce::ReferenceCountedObjectPtr) + 2826 (CDeck.cpp:89)  
> 10 com.yourcompany.NewProject 0x1083f75b CDeck::CDeck(int, juce::ReferenceCountedObjectPtr) + 43 (CDeck.cpp:119)  
> 11 com.yourcompany.NewProject 0x10844e1f CMain::CMain(Mixer&) + 639 (CMain.cpp:49)  
> 12 com.yourcompany.NewProject 0x10844b94 CMain::CMain(Mixer&) + 36 (CMain.cpp:109)  
> 13 com.yourcompany.NewProject 0x10849597 NewProjectAudioProcessorEditor::NewProjectAudioProcessorEditor(NewProjectAudioProcessor\*) + 119 (PluginEditor.cpp:21)  
> 14 com.yourcompany.NewProject 0x10849514 NewProjectAudioProcessorEditor::NewProjectAudioProcessorEditor(NewProjectAudioProcessor\*) + 36 (PluginEditor.cpp:24)  
> 15 com.yourcompany.NewProject 0x10848ce7 NewProjectAudioProcessor::createEditor() + 55 (PluginProcessor.cpp:163)  
> 16 com.yourcompany.NewProject 0x10949fdc juce::AudioProcessor::createEditorIfNeeded() + 108 (juce\_AudioProcessor.cpp:204)  
> 17 com.yourcompany.NewProject 0x10d155c6 JuceVSTWrapper::createEditorComp() + 102 (juce\_VST\_Wrapper.cpp:1046)  
> 18 com.yourcompany.NewProject 0x10d10c48 JuceVSTWrapper::dispatcher(int, int, int, void\*, float) + 904 (juce\_VST\_Wrapper.cpp:1162)  
> 19 com.yourcompany.NewProject 0x10d0e0ab AudioEffect::dispatchEffectClass(AEffect\*, int, int, int, void\*, float) + 219 (audioeffect.cpp:32)  
> 20 com.cockos.reaper 0x0023e8be VST\_HostedPlugin::ShowConfig(HWND, RECT) + 558  
> 21 com.cockos.reaper 0x00259858 FxDsp::showConfig(HWND, RECT, int) (.) + 519  
> 22 com.cockos.reaper 0x0027f609 FxChain::displayDspConfig(HWND__, int) (.) + 312  
> 23 com.cockos.reaper 0x0027da2a FxChain::onDspAdded(HWND\_\__, int, char const\*) (.) + 185  
> 24 com.cockos.reaper 0x00297873 addDialogProc(HWND\_\__, unsigned int, unsigned long, long) + 12067  
> 25 com.cockos.reaper 0x0037f40a SwellDialogDefaultWindowProc(HWND\_\__, unsigned int, unsigned long, long) + 74  
> 26 com.cockos.reaper 0x0039b983 SendMessage(HWND\_\__, unsigned int, unsigned long, long) + 435  
> 27 com.cockos.reaper 0x00296515 addDialogProc(HWND\_\__, unsigned int, unsigned long, long) + 7109  
> 28 com.cockos.reaper 0x0037f40a SwellDialogDefaultWindowProc(HWND\_\_\*, unsigned int, unsigned long, long) + 74  
> 29 com.cockos.reaper 0x0037fb6a -[REAPERSwell\_hwnd swellOnControlDoubleClick:] + 474  
> 30 libobjc.A.dylib 0x97c6c5d3 -[NSObject performSelector:withObject:] + 70  
> 31 com.apple.AppKit 0x94f30bd2 -[NSApplication sendAction:to:from:] + 436  
> 32 com.apple.AppKit 0x94f309e0 -[NSControl sendAction:to:] + 102  
> 33 com.apple.AppKit 0x9539c0cc -[NSTableView \_sendAction:to:row:column:] + 158  
> 34 com.apple.AppKit 0x953a00ba -[NSTableView mouseDown:] + 5976  
> 35 com.cockos.reaper 0x003a1e07 -[REAPERSwell\_listview mouseUp:] + 615  
> 36 com.apple.AppKit 0x94f25ae0 -[NSWindow sendEvent:] + 7159  
> 37 com.apple.AppKit 0x94f20a0f -[NSApplication sendEvent:] + 4278  
> 38 com.cockos.reaper 0x00213799 -[REAPERapp sendEvent:] + 297  
> 39 com.apple.AppKit 0x94e3a72c -[NSApplication run] + 951  
> 40 com.apple.AppKit 0x94ddd6f6 NSApplicationMain + 1053  
> 41 com.cockos.reaper 0x000022e2 \_start + 216  
> 42 com.cockos.reaper 0x00002209 start + 41

---

<div class="post-metadata">

**Author:** ![TheVinn](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/thevinn/32/806_2.png) [@TheVinn](https://forum.juce.com/u/TheVinn)\
**Post date:** [February 21, 2013, 7:47pm UTC](https://forum.juce.com/t/vflib-plugin-issue/10006/2 "2013-02-21T19:47:45Z")

</div>

The question, is which queue is getting calls? There are two queues of interest. One is the ManualCallQueue in Mixer. The other is from the vf::MessageThread::getInstance.

Set a breakpoint where the assert goes off and inspect the name field of the call queue in question to figure out which one it is.

Once you find out which queue it is, then you need to set a breakpoint in CallQueue::close and find out why it is getting closed. Most likely you have a threading issue where you are destroying an object containing the call queue, but another thread is trying to put messages on it. You need to have an orderly set of shutdown steps. There are often bugs in destruction of objects in multithreaded systems, this is all perfectly normal. Debugging it will be difficult.

---

<div class="post-metadata">

**Author:** ![lalala](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/lalala/32/8577_2.png) [@lalala](https://forum.juce.com/u/lalala)\
**Post date:** [February 22, 2013, 2:31pm UTC](https://forum.juce.com/t/vflib-plugin-issue/10006/3 "2013-02-22T14:31:28Z")

</div>

thanks vinnie for your answer.

the name field doesn’t seem to be anything valid when the assert goes off…  
I have seen it ‘\x0’, ‘\x17’, or ‘\x06’ (so when I print it, either nothing or ‘¿’)

as well it seems that most of the time I haven’t got that assert, but got an “EXC\_BAD\_ACCESS” in getPageBytes() in vf\_PagedFreeStore.h (l.56).

Any other clue you could give me to debug that?

```auto
void CallQueue::queuep (Work* c)
{
  DBG("queue name = "+ m_name);
  jassert (!m_closed.isSignaled ());
...
}
```

give as last print :

> [@](#):
>
> queue name = GuiCallQueue  
> queue name = GuiCallQueue  
> queue name = GuiCallQueue  
> queue name = GuiCallQueue  
> queue name = GuiCallQueue  
> queue name = GuiCallQueue  
> queue name = GuiCallQueue  
> queue name = GuiCallQueue  
> queue name = GuiCallQueue  
> queue name = AsyncDeleter  
> queue name = AsyncDeleter  
> queue name = AsyncDeleter  
> queue name = AsyncDeleter  
> queue name = AsyncDeleter  
> queue name = AsyncDeleter  
> queue name = AsyncDeleter  
> queue name = AsyncDeleter  
> queue name = GuiCallQueue  
> queue name = Mixer  
> queue name = ¿  
> JUCE Assertion failure in ~/SDKs/VFLib/modules/vf\_concurrent/threads/vf\_CallQueue.cpp, line 60

---

<div class="post-metadata">

**Author:** ![TheVinn](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/thevinn/32/806_2.png) [@TheVinn](https://forum.juce.com/u/TheVinn)\
**Post date:** [February 22, 2013, 2:34pm UTC](https://forum.juce.com/t/vflib-plugin-issue/10006/4 "2013-02-22T14:34:45Z")

</div>

Sounds to me like a thread is accessing a queue after it is deleted.

---

<div class="post-metadata">

**Author:** ![lalala](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/lalala/32/8577_2.png) [@lalala](https://forum.juce.com/u/lalala)\
**Post date:** [February 22, 2013, 2:39pm UTC](https://forum.juce.com/t/vflib-plugin-issue/10006/5 "2013-02-22T14:39:50Z")

</div>

What I don’t understand is that the first instance of the plugin is ALWAYS running nicely. It’s only when I remove it and create another one that this goes off.  
Do you mean that it’s probably due to the host doing something strange, and that I can’t do anything about it?

---

<div class="post-metadata">

**Author:** ![lalala](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/lalala/32/8577_2.png) [@lalala](https://forum.juce.com/u/lalala)\
**Post date:** [February 22, 2013, 2:42pm UTC](https://forum.juce.com/t/vflib-plugin-issue/10006/6 "2013-02-22T14:42:21Z")

</div>

Do you think it could be related to something like that :

[http://www.rawmaterialsoftware.com/viewtopic.php?f=8&t=6879&hilit=Leaked+objects+Thread](http://www.rawmaterialsoftware.com/viewtopic.php?f=8&t=6879&hilit=Leaked+objects+Thread)

where jules says [quote]Because the host is in charge of the event queue, it’s quite possible that the plugin posts one of these messages, and then gets deleted before the event is delivered - so inevitably the event is lost[/quote]

---

<div class="post-metadata">

**Author:** ![TheVinn](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/thevinn/32/806_2.png) [@TheVinn](https://forum.juce.com/u/TheVinn)\
**Post date:** [February 22, 2013, 2:49pm UTC](https://forum.juce.com/t/vflib-plugin-issue/10006/7 "2013-02-22T14:49:35Z")

</div>

> [@lalala](#):
>
> Do you think it could be related to something like that…

If that was true then AsyncUpdaters would sometimes cause crashes independent of VFLib so no.

---

<div class="post-metadata">

**Author:** ![lalala](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/lalala/32/8577_2.png) [@lalala](https://forum.juce.com/u/lalala)\
**Post date:** [February 22, 2013, 5:48pm UTC](https://forum.juce.com/t/vflib-plugin-issue/10006/8 "2013-02-22T17:48:14Z")

</div>

Ok. But you think it’s a host-related issue ?  
I’m a bit lost here. I don’t really get why I’ve got such a threading issue during the creation of the plugin, but only if I already created and destructed it once. Isn’t it strange I don’t have the issue during the first creation of the plugin ?  
sorry for such a naive question, but I’m really new to threading stuff :  
Do you think I can do something about that issue then, or is it something I can’t change ?  
I would really like to use vflib for my plugs…

---

<div class="post-metadata">

**Author:** ![TheVinn](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/thevinn/32/806_2.png) [@TheVinn](https://forum.juce.com/u/TheVinn)\
**Post date:** [February 22, 2013, 7:00pm UTC](https://forum.juce.com/t/vflib-plugin-issue/10006/9 "2013-02-22T19:00:43Z")

</div>

If you want to use VFLib you need to write the code yourself, one step at a time, and make sure that each piece works. Trying to take SimpleDJ objects and instantiate them inside your plugin without understanding fully how they work, is probably going to create problems for you. The worst part about it is that you are going from a plugin containing nothing, to a plugin containing a lot of code. You need to build your plugin up incrementally - one step at a time. This way when it breaks, you can narrow your search to the most recent change instead of having to suspect the entire code base.

---

<div class="post-metadata">

**Author:** ![lalala](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/lalala/32/8577_2.png) [@lalala](https://forum.juce.com/u/lalala)\
**Post date:** [February 23, 2013, 3:37pm UTC](https://forum.juce.com/t/vflib-plugin-issue/10006/10 "2013-02-23T15:37:15Z")

</div>

Ok, I think identified where the issue comes from.

I did a really simple plug, with just the following change from the introjucer created one :

in PluginEditor.h, an inner class :

```auto
public:
class Listener
    {
        public:
            virtual void fct () { }
    };

public:
    Listener listener;
    vf::Listeners <Listener> listeners;
```

in the PluginEditor constructor :

```auto
listeners.add (&listener, vf::MessageThread::getInstance ());
listeners.queue1 (&listener, &Listener::fct);
```

and in the destructor :

```auto

```

It seems there’s a singleton problem with DeletedAtShutdown & the message queue.  
When I first instantiate the plugin and then delete it ~MessageThread () is called and the queue is closed.  
Then, when I create a new instance of the plugin, MessageThread::getInstance () return me the same queue, which is closed.

---

<div class="post-metadata">

**Author:** ![TheVinn](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/thevinn/32/806_2.png) [@TheVinn](https://forum.juce.com/u/TheVinn)\
**Post date:** [February 23, 2013, 4:38pm UTC](https://forum.juce.com/t/vflib-plugin-issue/10006/11 "2013-02-23T16:38:39Z")

</div>

[quote=“lalala”]It seems there’s a singleton problem with DeletedAtShutdown & the message queue.  
When I first instantiate the plugin and then delete it ~MessageThread () is called and the queue is closed.  
Then, when I create a new instance of the plugin, MessageThread::getInstance () return me the same queue, which is closed.[/quote]

Okay, good job narrowing this down.

What does DeletedAtShutdown have to do with any of this? Why is the destructor for MessageThread getting called? That should only be called if your DLL is unloaded (I think).

---

<div class="post-metadata">

**Author:** ![lalala](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/lalala/32/8577_2.png) [@lalala](https://forum.juce.com/u/lalala)\
**Post date:** [February 23, 2013, 5:07pm UTC](https://forum.juce.com/t/vflib-plugin-issue/10006/12 "2013-02-23T17:07:00Z")

</div>

Hum. don’t forget i’m a newb 🙂

the MessageThread destructor is getting called because MessageThread inherits DeletedAtShutdown, and it seems the normal behaviour that DeletedAtShutdown is getting called when all the plugins instances are deleted :

Singletons and DeletedAtShutdown : [http://www.rawmaterialsoftware.com/viewtopic.php?f=2&t=7491](http://www.rawmaterialsoftware.com/viewtopic.php?f=2&t=7491)  
Singleton && DeletedAtShutdown Class in Plug-In : [http://www.rawmaterialsoftware.com/viewtopic.php?f=8&t=4733](http://www.rawmaterialsoftware.com/viewtopic.php?f=8&t=4733)

---

<div class="post-metadata">

**Author:** ![TheVinn](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/thevinn/32/806_2.png) [@TheVinn](https://forum.juce.com/u/TheVinn)\
**Post date:** [February 24, 2013, 12:54am UTC](https://forum.juce.com/t/vflib-plugin-issue/10006/13 "2013-02-24T00:54:46Z")

</div>

Jules can you point me towards a clearer picture of this problem? I have not worked with DLLs at all…

---

<div class="post-metadata">

**Author:** ![P4tr3ck](https://avatars.discourse-cdn.com/v4/letter/p/e79b87/32.png) [@P4tr3ck](https://forum.juce.com/u/P4tr3ck)\
**Post date:** [March 4, 2013, 10:40pm UTC](https://forum.juce.com/t/vflib-plugin-issue/10006/14 "2013-03-04T22:40:27Z")

</div>

First, I didn’t reproduce the problem. Seems I am too stupid to debug a vst plugin using Visual Studio 😉

But I gathered so much that using static objects are not a good idea when using dlls. So maybe you can side step the problem: Try using a vf::GuiCallQueue instead of the vf::MessageThread.

---

<div class="post-metadata">

**Author:** ![chkn](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/chkn/32/3862_2.png) [@chkn](https://forum.juce.com/u/chkn)\
**Post date:** [March 5, 2013, 8:03am UTC](https://forum.juce.com/t/vflib-plugin-issue/10006/15 "2013-03-05T08:03:33Z")

</div>

I wouldn’t use DeletedAtShutdown in a Plugin, because there isn’t is a classic “shutdown” in plugin environments, it depends all on the host.

Better use ref-counted objects or just open an instance of what you need for any of your plugin.

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [March 5, 2013, 8:55am UTC](https://forum.juce.com/t/vflib-plugin-issue/10006/16 "2013-03-05T08:55:29Z")

</div>

I’d agree with chkn - best to avoid DeletedAtShutdown in a plugin. It should work, being called when shutdownJuce\_GUI() is called, which should happen when all your plugin instances are deleted, or before the DLL is unloaded, but hosts can be unpredictable.

Something I keep meaning to create but never quite get around to is a ref-counted singleton… That’d be handy in this kind of circumstance.

---

<div class="post-metadata">

**Author:** ![P4tr3ck](https://avatars.discourse-cdn.com/v4/letter/p/e79b87/32.png) [@P4tr3ck](https://forum.juce.com/u/P4tr3ck)\
**Post date:** [March 5, 2013, 9:21am UTC](https://forum.juce.com/t/vflib-plugin-issue/10006/17 "2013-03-05T09:21:13Z")

</div>

> [@jules](#):
>
> I’d agree with chkn - best to avoid DeletedAtShutdown in a plugin. It should work, being called when shutdownJuce\_GUI() is called, which should happen when all your plugin instances are deleted, or before the DLL is unloaded, but hosts can be unpredictable.

For lalala’s specific problem this means using a vf::GuiCallQueue instead of the vf::MessageThread.

---

<div class="post-metadata">

**Author:** ![TheVinn](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/thevinn/32/806_2.png) [@TheVinn](https://forum.juce.com/u/TheVinn)\
**Post date:** [March 5, 2013, 1:11pm UTC](https://forum.juce.com/t/vflib-plugin-issue/10006/18 "2013-03-05T13:11:26Z")

</div>

> [@jules](#):
>
> Something I keep meaning to create but never quite get around to is a ref-counted singleton…

You mean like [vf::RefCountedSingleton\<\>](http://vinniefalco.com/VFLib/class_ref_counted_singleton.html)?

:lol: :lol: 😃

---

<div class="post-metadata">

**Author:** ![lalala](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/lalala/32/8577_2.png) [@lalala](https://forum.juce.com/u/lalala)\
**Post date:** [March 5, 2013, 1:36pm UTC](https://forum.juce.com/t/vflib-plugin-issue/10006/19 "2013-03-05T13:36:05Z")

</div>

thanks all for your comments!  
So to conclude I should use a RefCountedSingleton instead of MessageThread, is that right ?

---

<div class="post-metadata">

**Author:** ![TheVinn](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/thevinn/32/806_2.png) [@TheVinn](https://forum.juce.com/u/TheVinn)\
**Post date:** [March 5, 2013, 2:28pm UTC](https://forum.juce.com/t/vflib-plugin-issue/10006/20 "2013-03-05T14:28:08Z")

</div>

[quote=“lalala”]thanks all for your comments!  
So to conclude I should use a RefCountedSingleton instead of MessageThread, is that right ?[/quote]

Try it and see ^^

Actually, I don’t think it even needs to be that complicated. Just make GuiCallQueue a member of one of your long lived classes (like the plugin instance for example). You can have more than one GuiCallQueue in your plugin, it doesn’t need to be any sort of singleton.
