Re: delete, hash_map
"SimpleCode" <DragonXLong@gmail.com> wrote in message
news:1178355836.551586.220550@q75g2000hsh.googlegroups.com...
:> Well, either the object has already been deleted,
: > or its destructor does an illegal operation (e.g.
: > maybe a recursion problem?).
: > It is impossible to tell from the code you've posted.
:
: My code:
: #include <hash_map>
: stdext::hash_map<moving_vehicle*, COsgCar*> g_hash; //global
: variable
: typedef pair<moving_vehicle*, COsgCar*> Ptr_Pair;
:
: void COsgView::setRootChild(float x, float y, float z, float angle,
: int type, moving_vehicle* pMovingVehicle)
: {
: /**** new, only hear ****/
: COsgCar * osgcar = new COsgCar(x, y, z, angle, type);
: g_hash.insert(Ptr_Pair(pMovingVehicle, osgcar));
: }
:
: vehicle_node* car_list::delete_car(vehicle_node *k)
: {
: stdext::hash_map<moving_vehicle*, COsgCar*>::iterator hash_Iter;
: hash_Iter = g_hash.find(k->vehicle_p);
: if (hash_Iter != g_hash.end())
: {
: COsgCar *p = g_hash[k->vehicle_p];
: g_hash.erase(hash_Iter);
: delete p; /**** If I comment, there is no problem ***/
: p = NULL;
: }
: }
:
: A puzzle.
Well, it's one of two things:
- the pointer that you are deleting is invalid
You could try to log object addresses in the constructor
and destructor to find out.
- the destructor of COsgCar does something wrong...
Again, the code you've posted seems ok.
--
http://ivan.vecerina.com/contact/?subject=NG_POST <- email contact form