From: Vadim Zeitlin Date: Mon, 29 Apr 2013 23:13:24 +0000 (+0000) Subject: Fix assert when adding items with bitmaps wxBitmapComboBox. X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/9e86876e69b1990673f5b331513d3e322aa1c2e8 Fix assert when adding items with bitmaps wxBitmapComboBox. The change of r73567 resulted in an assert when adding items with bitmaps to wxBitmapComboBox without object client data. Fix the code added by this commit to work for all kinds of client data, including wxClientData_None. See #14892. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@73880 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/src/msw/bmpcbox.cpp b/src/msw/bmpcbox.cpp index ea7c925762..bdd42ed970 100644 --- a/src/msw/bmpcbox.cpp +++ b/src/msw/bmpcbox.cpp @@ -133,13 +133,30 @@ void wxBitmapComboBox::RecreateControl() wxPoint pos = GetPosition(); wxSize size = GetSize(); size.y = GetBestSize().y; - wxArrayString strings = GetStrings(); - - // Save the client data pointers before clearing the control. - wxVector clientData; - clientData.reserve(strings.size()); - for ( size_t n = 0; n < strings.size(); ++n ) - clientData.push_back(GetClientObject(n)); + const wxArrayString strings = GetStrings(); + const unsigned numItems = strings.size(); + + // Save the client data pointers before clearing the control, if any. + const wxClientDataType clientDataType = GetClientDataType(); + wxVector objectClientData; + wxVector voidClientData; + switch ( clientDataType ) + { + case wxClientData_None: + break; + + case wxClientData_Object: + objectClientData.reserve(numItems); + for ( unsigned n = 0; n < numItems; ++n ) + objectClientData.push_back(GetClientObject(n)); + break; + + case wxClientData_Void: + voidClientData.reserve(numItems); + for ( unsigned n = 0; n < numItems; ++n ) + voidClientData.push_back(GetClientData(n)); + break; + } wxComboBox::DoClear(); @@ -151,9 +168,14 @@ void wxBitmapComboBox::RecreateControl() return; // initialize the controls contents - for ( unsigned int i = 0; i < strings.size(); i++ ) + for ( unsigned int i = 0; i < numItems; i++ ) { - wxComboBox::Append(strings[i], clientData[i]); + wxComboBox::Append(strings[i]); + + if ( !objectClientData.empty() ) + SetClientObject(i, objectClientData[i]); + else if ( !voidClientData.empty() ) + SetClientData(i, objectClientData[i]); } // and make sure it has the same attributes as before