Jump to content
Sign in to follow this  
  • entries
    11
  • comments
    26
  • views
    5887

A little bugger

Sign in to follow this  
Rhaal

341 views

This one got me for a little while. My renderer has a list of entities that get rendered when a Draw function is called on the renderer.

void lxRender::RenderScene()
{
std::list::iterator elI = mElementList.begin();
while(!(elI == mElementList.end()))
{
(*elI)->Draw(mScreen);
elI++;
}
SDL_Flip(mScreen);
}



In an effort to program better I decided to change the way visibility works. Before, I was having the graphic element handle visibility by just exiting the Draw function right away if the flag wasn't set. Moving it to the renderer, I simply added a condition to see if the element was visible.

void lxRender::RenderScene()
{
std::list::iterator elI = mElementList.begin();
while(!(elI == mElementList.end()))
{
if((*elI)->Visible)
{
(*elI)->Draw(mScreen);
elI++;
}
}
SDL_Flip(mScreen);
}



Everything worked until I made an element invisible. The program froze. This one got me for a bit then I felt so dumb. Can you see the problem?
Sign in to follow this  


4 Comments


Recommended Comments

If it is invisible, the iterator never increments =D

Also, why dont you create a list of visible items that is updated with each item that is visible. That way its not necessarily O(n).

Share this comment


Link to comment
ZOMG I FOUND A HUGE ERROR! Although you were right, I found another major flaw. I wasn't calling clear() on the list! I wondered for weeks why I was getting so much lag! (Because this function is called around 60xSecond!)

Share this comment


Link to comment

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
  • 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!