~LookAndFeel() assertion when used with PopupMenu that's still open

I really apologize if this is the same old topic again, but to me it’s not obvious how to handle this case. I’ve searched and read the other threads.

I have a plugin using PopupMenus with a custom LookAndFeel. When I close the plugin window while a PopupMenu is still open, I get the assertion in ~LookAndFeel() that there’s still a reference. When I close the window without PopupMenus open, I don’t get the assertion.

In my plugin editor component’s destructor, I call setLookAndFeel(nullptr), but it seems that the PopupMenu is still using it. I’ve tried calling PopupMenu:: dismissAllActiveMenus() and ModalComponentManager::cancelAllModalComponents() before setLookAndFeel(nullptr), but still get the assertion. Strangely, ModalComponentManager:: getNumModalComponents() returns 0, but I can still see the PopupMenu. So I can’t iterate over the modal components and call setLookAndFeel(nullptr) on each one.

The problem does not occur when using the Standalone Plugin target. Just when running it as a plugin in a host (Reaper in my case).

I think it’s because closing a modal component happens async :frowning: