I got a crash that almost drove me nuts: the crash happened exclusively in release-builds and then only on instances not started immediately with a debugger. After several month a finally boiled the problem down to the line:
const CMFCToolBarMenuButton& otherMenuBtn = (const CMFCToolBarMenuButton&) other;
One could argument that this is not a problem as just before compared the buttons are ensured to have the same ID, so "other" should be a CMFCToolBarMenuButton too.
But wait, this routine is also called during CMFCToolBar::SmartUpdate and I changed a toolbar-button from a former version to a toolbar-menu-button (while keeping the ID). Thus there is an illegal cast !!!
(In debug mode the line
if (m_listCommands.GetCount() != otherMenuBtn.m_listCommands.GetCount())
usually return TRUE, so the crash does not occur in debug builds.)
So, please insert a DYNAMIC_DOWNCAST to check if "other" has the correct runtime type.