Menu Item custom callback not called if MenuBarModel::setMacMainMenu

I suspect a bug when using a custom callback with an item of a SubMenu, on Mac. The item is well displayed but when clicked, the callback is not called. However, it ONLY happens when the MenuBarModel::setMacMainMenu is used with the menu as a parameter. When it is NOT applied, the menu item works fine. Is it a bug? On Windows and Linux, everything is fine.

My menu item is created like this:

PopupMenu::Item item;
item.text = "my text";
item.itemID = 1234;		// Why not?
ReferenceCountedObjectPtr<MyItemCallback> myItemCallback(new MyItemCallback());
item.customCallback = myItemCallback;


With MyItemCallback being a child of the PopupMenu::CustomCallback:

class MyItemCallback : public PopupMenu::CustomCallback
	bool menuItemTriggered() override
		// Item clicked! Do something.


Please check the develop trunk. There used to be a bug which has been fixed a month ago.
Not sure if this really your issue as it was the main menu but just in case.

1 Like

Yes this should be fixed in JUCE 5.1.2.

Thanks for your answer. However, I tested on the latest version of JUCE on both master and develop, and it does not work: the callback is not called. if setMacMainMenu is used.

1 Like

Thanks for reporting. This is fixed on develop with commit e0b0920.

It turns out that by fixing this bug we discovered a memory-leak (as PopupMenu::CustomCallback has a leak detector) for any native macOS menu item that JUCE creates. It took ages to figure out what the problem was but it’s finally fixed - also on develop -
with commit 6ae99f4.

Glad I could help :). This is working now, thanks a lot.