Jump to content
  • Advertisement
Sign in to follow this  
Sivak

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

This topic is 3036 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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.
	if((*it1)->Update())
	  it1 = GameObjs.erase(it1);
	else
	  ++it1;
}

//Later, while drawing:
for (int blah = 1; blah < 7; blah++)
{	for(it1 = GameObjs.begin(); it1 != GameObjs.end(); ++it1)
	{	if ((*it1)->drawPriority == blah)
			(*it1)->Draw();
	}
}
http://pastebin.com/rGswatvz - 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
Advertisement
Quote:
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!