Sign in to follow this  

Deleting inactive things from my list... I think I'm missing something

Recommended Posts

Hi all, this is part of my game, but I think it's a general programming oversight on my part. I'm using VC++ 2008 express edition on Windows XP Pro SP3. Anyway, the situation is this: I have a list with the various objects that get updated in the game. Basically, I have these lines when I do anything with it:
//In the main game class, it's declared like this:
std::list< smartptr<GameObject> > GameObjs;

//This declares it...
std::list< smartptr< GameObject > >::iterator it1;

//During the run, this is called...
it1 = GameObjs.begin();
while(it1 != GameObjs.end())
{//	(*it1)->Update();  THIS LINE is updating without deletion...  Obviously the wrong way to go when many objects are in play.
	  it1 = GameObjs.erase(it1);

//Later, while drawing:
for (int blah = 1; blah < 7; blah++)
{	for(it1 = GameObjs.begin(); it1 != GameObjs.end(); ++it1)
	{	if ((*it1)->drawPriority == blah)
} - This is the smartPtr source. Basically, what SHOULD be happening is, during the Update call, if true is returned, the object should just be deleted from the list. This does not seem to be the case though as I can have player bullets off-screen "hit" enemies. Another thing that's happening is the App crashes when closing. This tends to only happen if I shoot a fair amount of bullets, but obviously it should not be happening period. I've commented out the removal code and the App runs okay until a LOT of bullets/enemies are in there and never being removed (obviously). But the thing never crashes upon closing, so I'm positive this is the culprit. Anyone have any thoughts? Thanks. [Edited by - Sivak on March 29, 2010 2:18:52 PM]

Share this post

Link to post
Share on other sites
Original post by Gage64
Why are you calling Update() twice?

Er, sorry. The part below the initial call is supposed to be commented out. I've fixed this.

Share this post

Link to post
Share on other sites
Hey all. Sorry for the double post, but I seem to have figured it out. I needed a virtual dtor in the master class. That seems to have fixed it!

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this