A little bugger

posted in Rhaal's Journal
Published April 02, 2005
Advertisement
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?
Previous Entry Oh no Gamedev banned me!
Next Entry Newest Song
0 likes 4 comments

Comments

choffstein
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).
April 02, 2005 08:43 PM
Rhaal
Hey, good idea! And... you win this picture: [totally]
April 02, 2005 08:56 PM
Rhaal
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!)
April 02, 2005 11:12 PM
choffstein
At what unholy hour of the night did you code this?
April 03, 2005 09:04 AM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement

Latest Entries

Elitism

992 views

WooHoo

951 views

:)

686 views

Newest Song

1093 views

A little bugger

951 views

Entry

932 views

Entry

867 views

Entry

783 views

Entry

790 views
Advertisement