JUCE API classes that use globals / static variables


Hi everybody,

while testing my plugin with multiple instances within a host, I noticed that the tooltips are shown in all plugin windows (as if they would share one TooltipWindow object).

Are there more classes which use a singleton object internally and thus creating some cross-instance behaviour? I read somewhere that calling setDefaultLookAndFeel() does something similar, so maybe a list of all stuff that can interfere with multiple instances would be a great resource for debugging.


Hi chrisboy2000,

This really depends on how you instantiate TooltipWindow. If you have TooltipWindow as a member variable of your plug-in Editor then multiple tooltip windows will appear (because you have multiple instances of them for each editor instance). The correct way to do this in a plug-in is to use a SharedResourcePointer of a TooltipWindow. I've now added a comment to the TooltipWindow code to clarify this.

I think we use very little statically typed objects and - if we do - we try to make it clear in the documentation. For example, the default look and feel is part of the Desktop class. The documentation of this class (see for example Desktop::getInstance) states that this is a singleton class. If you find any places where this is missing then please report this and we will fix the documentation.

There are singleton macros within JUCE and I don't think we always use them consistently. It might be a good idea for us to replace all static member variables being used in a singleton-type manner with the juce_DeclareSingleton and juce_ImplementSingleton macros - or some other method to annotate them. This would make it far easier for JUCE devs to search the code base for singletons. I'll add it to our backlog.