difficulty deleting pointers from std::vector

Started by
10 comments, last by shadow12345 20 years, 2 months ago
OK, to try and find out whether this is a) a multiple deletion problem or b) a not-really-a-VWorldObject deletion problem, can you add a global:
std::vector<int> vWorldObjectValidator1;std::deque<int> vWorldObjectValidator2; 

and in the VWorldObject constructor add:
vWorldObjectValidator1.push_back((int)this);vWorldObjectValidator2.push_back((int)this); 

and at the start of the VWorldObject destructor add:
if (std::find(vWorldObjectValidator1.begin(), vWorldObjectValidator1.end(), (int)this) == vWorldObjectValidator1.end()){	// some error reporting, i.e. message box or std::cerr << .. reporting invalid object	std::exit(-1);}else if (std::find(vWorldObjectValidator2.begin(), vWorldObjectValidator2.end(), (int)this) == vWorldObjectValidator2.end()){	// some error reporting, i.e. message box or std::cerr << .. reporting already deleted object	std::exit(-1);}vWorldObjectValidator2.erase(std::find(vWorldObjectValidator2.begin(), vWorldObjectValidator2.end(), (int)this)); 


Enigma
Advertisement
To be perfectly honest I am still totally befuddled as to what the problem is. I have tried all of your suggestions but I was still generating the exact same error somehow. I have finally got it so that it works, however I do not know what was wrong to be honest. I'm deleting them using std::for_each in my GameExport structure before I delete my BSP, then when I delete the BSP I just clear the raw pointers in the leaf std::vector by calling clear() on them. The funny thing is I had been doing this for a long time and it was not working, but I must've changed something somewhere to get it working.

You can obviously tell I still really have no clue what is going on...subsequently I think I am going to look into boost::shared_ptr, although boost.org seem to be down right now.

However, you guys have been really really great. I wish everybody was as patient and thoughtful as you guys. You certainly kept pointing me in the right direction and I think I have a better idea of what might be wrong than when I started.

[edited by - Shadow12345 on February 7, 2004 2:50:43 PM]

[edited by - Shadow12345 on February 7, 2004 2:51:53 PM]
Why don't alcoholics make good calculus teachers?Because they don't know their limits!Oh come on, Newton wasn't THAT smart...

This topic is closed to new replies.

Advertisement