CComponentsForm: prevent crashs, if no item is available in v_cc_items

insertCCItem() and removeCCItem() occured crashes, if no items was added.
Also added debug messages.
This commit is contained in:
2012-11-25 10:00:59 +01:00
parent 41165d7cb2
commit 2e729ffdb9

View File

@@ -1587,22 +1587,36 @@ CComponentsItem* CComponentsForm::getCCItem(const uint& cc_item_id)
void CComponentsForm::insertCCItem(const uint& cc_item_id, CComponentsItem* cc_Item) void CComponentsForm::insertCCItem(const uint& cc_item_id, CComponentsItem* cc_Item)
{ {
#ifdef DEBUG_CC
if (cc_Item == NULL){ if (cc_Item == NULL){
#ifdef DEBUG_CC
printf("CComponentsForm: %s parameter: cc_Item = %d...\n", __FUNCTION__, (int)cc_Item); printf("CComponentsForm: %s parameter: cc_Item = %d...\n", __FUNCTION__, (int)cc_Item);
#endif
return; return;
} }
if (v_cc_items.empty()){
v_cc_items.push_back(cc_Item);
#ifdef DEBUG_CC
printf("CComponentsForm: %s insert cc_Item not possible, v_cc_items is empty, cc_Item added\n", __FUNCTION__);
#endif #endif
v_cc_items.insert(v_cc_items.begin()+cc_item_id, cc_Item); }else
v_cc_items.insert(v_cc_items.begin()+cc_item_id, cc_Item);
} }
void CComponentsForm::removeCCItem(const uint& cc_item_id) void CComponentsForm::removeCCItem(const uint& cc_item_id)
{ {
if (v_cc_items[cc_item_id]) { if (!v_cc_items.empty()){
delete v_cc_items[cc_item_id]; if (v_cc_items.at(cc_item_id)) {
v_cc_items[cc_item_id] = NULL; delete v_cc_items[cc_item_id];
v_cc_items.erase(v_cc_items.begin()+cc_item_id); v_cc_items[cc_item_id] = NULL;
v_cc_items.erase(v_cc_items.begin()+cc_item_id);
}
} }
#ifdef DEBUG_CC
else
printf("CComponentsForm: %s removing cc_Item not possible, v_cc_items is empty...\n", __FUNCTION__);
#endif
} }
void CComponentsForm::paint(bool do_save_bg) void CComponentsForm::paint(bool do_save_bg)