Well I check to see if their is a null pointer in the vector if not I extend the vector. Is their a better way of checking and doing this or is my code above alright?
Also when I null one of the item_drops I get a segmentation fault when a new ground item is added. The crash is at line 25 of the code above
Any idea why?
Here is the delete code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
void ItemHandler::process()
{
for (unsignedint i = 0; i < item_drops.size(); i++)
{
auto itemDrop = item_drops[i];
if (itemDrop != NULL)
{
/* Delete the item after it has been registered for 10 seconds */
if ((Misc::getTimeSeconds() - itemDrop->registerTime_Seconds) > 10)
{
cout << "Deleteing item: " << itemDrop->itemId << endl;
item_drops[i] = 0;
}
}
}
}