if the menubar is not yet attached.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@25256 
c3d73ce0-8a6f-49c7-b76d-
6d57e0e08775
 {
     // Find out which MSW item before which we'll be inserting before
     // wxMenuBarBase::Insert is called and GetMenu(pos) is the new menu.
-    int mswpos = (pos == m_menus.GetCount())
+    // If IsAttached() is false this won't be used anyway
+    int mswpos = (!IsAttached() || (pos == m_menus.GetCount()))
         ?   -1 // append the menu
         :   MSWPositionForWxMenu(GetMenu(pos),pos);