Releasing an Object from a Vector

Started by
11 comments, last by lord_balron 15 years, 1 month ago
Quote:
It fails in the exact same way. Visual studio pops up and says Unhandled exception at 0x0040173b in MesaApp.exe: 0xC0000005: Access violation reading location 0x00000057.

It is as SiCrane said, you are calling Release() on a null pointer. This is probably in the calling code.

Quote:
So I've implemented your other suggestion, the one of using dead and such, but what is happening is the Objects aren't being removed, they are still being drawn which shouldn't be as they are only drawn if they are in the vector.

Have you checked in the debugger to ensure that they are dead()? That when they are dead() that the call to remove them actually occurs.

We cannot diagnose issues in code we cannot see.
Advertisement
Quote:Original post by lord_balron
The Objects have a variable containing their location in the vector so you can access it with.


As mentioned, this is a very bad idea.

Quote:
This is given to it with this code...
void Particle::AddChild(Object* Child){	Children.push_back(Child);	int i = 0;	//for (int i = 0; i < Children.size(); i++)	while (Children != Child)	{		Child->PositionInVector = i;		i++;	}	Child->Parent = this;}


So every time you add a child, you re-number all the previous children, even though their places haven't changed. Then, because of how your while condition works, you don't actually number the child that was just added (note that the commented-out approach would have worked). You also depend on operator== working properly for Objects. And why is a Particle allowed to have any kind of Object as a child, anyway?

Quote:
What problem I'm having is that when I go to release it with:
Place = Place - 1;Children.erase(Children.begin() + Place);


I get an error (through the visual studio realtime debugger), that my program is "Access violation reading location 0x00000000"


1) Have you tried verifying the value of Place?
2) After erasing an element like this, all the elements that followed it will get shifted down, and need to be renumbered. There's no code anywhere to do that.
I can't get this working, what is a better way to hold dynamic scene objects?

This topic is closed to new replies.

Advertisement