I am going crazy about two issues I am having with my code.
I am trying to delete an element from my vector containing a list of objects.
//Remove Object
if (button2 == true)
{
//go through objects and check collision
for (std::vector<cOBJECT*>::size_type i = 0; i != GameObjects.size(); i++)
{
//Check for collision and delete object
if (MouseRect(GameObjects[i]->getrect(), mx + offX, my + offY) == true)
{
//GameObjects[i]->~cOBJECT();
delete GameObjects[i];
GameObjects.erase(GameObjects.begin() + i);
}
}
} // if (button2 == true)
For some reasons I run into two issues.
1) Access violation reading location 0xFEEEFEEE.
It seems to somehow have an issues with me destroying the texture. If I take out the "delete ...." and replace it with the destructor of the object instead, it works fine.
2) Vector subscript out of range
So if I use the destuctor to pass the first problem. I run into the next one. Now even if I use "GameObjects.erase(GameObjects.begin());" I get the same error.