Tooltips showing up on multiple instances of plugin


#1

I have a plugin with an editor, the editor has:

[code]class MyProcessorEditor : …
{
public:

MyProcessorEditor()
{
    tooltipWindow = new TooltipWindow(this);
}

ScopedPointer<TooltipWindow> tooltipWindow;

}[/code]

Which gets created at construction of the editor. When I open two instances of the plugin (tried in cubase and bidule) and hover over a control in one window a tooltip appears in both windows.

Anyone have any ideas?

  • bram

#2

It does look like this has to do with multiple instances of the TooltipWindow. It would be nice to have a guide on how to use TooltipWindow’s in plugins.
There is one ancient thread about using either reference counting or DeleteAtShutdown + singleton on here, but it’s not very enlightening.

  • bram

#3

This kind of does the trick, let’s see if Jules accepts this…

class ReferenceCountedTooltipWindow
{
public:
    ReferenceCountedTooltipWindow()
    {
        if (m_RefCount.compareAndSetBool(1,0))
            m_TooltipWindow = new TooltipWindow();
        else
            ++m_RefCount;
    }

    ~ReferenceCountedTooltipWindow()
    {
        if (--m_RefCount == 0)
            delete m_TooltipWindow;
    }

    static TooltipWindow* m_TooltipWindow;
    static Atomic<int> m_RefCount;
};

// cpp
TooltipWindow* ReferenceCountedTooltipWindow::m_TooltipWindow = nullptr;
Atomic<int> ReferenceCountedTooltipWindow::m_RefCount = 0;

Jules, I guess it would be nice to have something like this in the code and some kind of comment about multiple instances?


#4

Yes, I should add a note about having multiple instances. Personally, I’d probably have just used a static ref-counted pointer, but your code will work too.


#5

static ref-counted pointer <- isn’t that what my code is?


#6

Sorry, I just meant I’d have used ReferenceCountedObjectPtr to hide the implementation details.