Singletons in a plugin


Just getting stuck into iPlug2, really excited by it! Started getting my own UI framework running, and noticed that if I open up 2 of the same plugin, it shows me 2 identical plugins, and both receive the same events. Could this be because I’m using statics (singletons) to pass events round? As in do you think the static variables are being shared across plugin instances? I would make a test, but it’s a bit of a rewrite, and thought to ask for some advice before I start shredding up my codebase! (this is vst3 / Ableton Live / Mac btw)

all the best


Hi Marek,

good to have you with us :slight_smile:

It’s quite likely that statics/singletons in your UI framework would cause problems with multiple instances but its a bit difficult to say, without knowing how your stuff works.

got some run-time-compiled CPP stuff on a branch which you might be interested in btw


Ah thanks for your input, I thought as much, but struggling to find the exact thing to type into google to work out a way round this. Basically I can see that the 2 instances of the plugin open do indeed have the same memory address for the singleton. Was wondering if there was a compiler switch to stop this happening, will probably just try to restructure the code.

The singleton in question is my event dispatcher, so anyone can call it and it funnels the events to the UI root view. It’s a lazy way to program that’s what happens when you work by yourself I guess.

Would love to try out the runtime c++ stuff in iPlug2, is it in the main repo?

Also, just want to say thanks, this is an amazing project, hopefully I can make some cool stuff with it!

rccpp branch is here, not sure if it will compile