Results 1 to 9 of 9
  1. #1
    Join Date
    May 2009
    Posts
    8

    GL VTM 40, errors with ListBox

    This is actually the first of two problems I have with the VTM, but probably the easiest to fix.

    I'm ignoring the obj loading problems at this time. Instead the problem lies with the cleanup being done with ListBox (I think).

    The program loads correctly, and displays the listbox, but when ti closes I get a pop-up message box with the error:

    "Debug Assertion failed!'

    ... blah, blah, blah...

    "Expression: list iterator not incrementable"

    Supposedly occurring in line 242 of the <list> header.

    I defined the listbox and related stuff with...

    Code:
    Control *controlled = NULL;
    MouseState state;
    
    ListBox *lstModels = NULL;
    vector<Model *> models;
    Then I initialized it like so withing initGL:

    Code:
    lstModels = (ListBox *)addControl(new ListBox(0, 0, 200, 200));
    lstModels->addItem("Box");
    lstModels->addItem("Sphere");
    The drawScene() function is defined as:

    Code:
    GLvoid drawScene(GLvoid)
    {
    	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    
    	
    	establishProjectionMatrix(windowWidth, windowHeight);
    
    	glMatrixMode(GL_MODELVIEW);
    	glLoadIdentity();
    
    	glTranslatef(0, 0, zoom);
    
    	glRotatef(rotateX, 1, 0, 0);
    	glRotatef(rotateY, 0, 1, 0);
    
    	glEnable(GL_BLEND);
    	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    
    	glDisable(GL_TEXTURE_2D);
    	glEnable(GL_LIGHTING);
    
    	for ( int i = 0; i < (int)Light::lights.size(); i++)
    		Light::lights[i]->updateLight();
    
    	
    	glEnable(GL_BLEND);
    
    	if ( lstModels != NULL )
    		models[ lstModels->getIndex() ]->drawModel();
    
    	glDisable(GL_LIGHTING);
    	setOrtho(windowWidth, windowHeight);
    
    	glMatrixMode(GL_MODELVIEW);
    	glLoadIdentity();
    
    	displayFPS();
    	drawControls();
    	
    	glFlush();
    
    	SDL_GL_SwapBuffers();
    }
    I think the problem lies somewhere in the main() function as the program is exiting. The program doesn't crash until it hits the loop that cleans up the controls:

    Code:
    for(list<Control *>::iterator it = Control::controls.begin(); it != Control::controls.end(); it++)
    {
    	delete (*it);
    
    	it = Control::controls.begin();
    }
    What's odd is that this worked fine in the Particle Demo, but it doesn't work correctly when I try to use it here.

    Any thoughts?

  2. #2
    Join Date
    Aug 2009
    Posts
    3
    I had something like this happen to me before. In order to solve it I had to run the code to that area and carefully watch what was being done with the iterator and the memory it was pointing to.

    I'd watch the iterator to see if you are ever incrementing the iterator when the iterator is no longer pointing to valid memory.


    I'm fairly new to lists. However, my guess is that everything in the list is being deleted on the last delete (*it); before it fails. So even though you are telling it to go back to the beginning of the list, it still points to invalid memory, which means it may not know its the "end" of the list when that conditional statement runs for the last time. So then it tries to increment the list and it can't.

  3. #3
    Join Date
    Aug 2004
    Location
    little rock arkansas
    Posts
    3,482

    Talking

    in the thread of information it goes over how to fix the incrementor error
    but we do not have a definite list of where they are in the code so you just have to look and find out where it is crashing
    ME WANT AGENTS ME WANT AGENTS ME WANT AGENTS

  4. #4
    Join Date
    May 2009
    Posts
    8
    The error described in the thread of information is related to the decrement operator. This one has problems when incrementing, so...

    How does that relate? I know VS doesn't like to decrement, but it seems to me like this is an entirely different error. Am I wrong, and if so, could you please explain why?

  5. #5
    Join Date
    Aug 2004
    Location
    little rock arkansas
    Posts
    3,482
    it is almost the same error....it is just incremented instead of decremented.
    http://www.gidforums.com/t-17428.html
    there is a page with something on the error
    and i am sure there are more on google
    ME WANT AGENTS ME WANT AGENTS ME WANT AGENTS

  6. #6
    Join Date
    Jun 2003
    Location
    Trier, Germany
    Posts
    1,350
    well, the interesting thing here is, there is nothing erased from that list. in fact, that loop shouldn't move forward all, being the iterator is basically stuck at Control::controls.begin(). chekr, you sure this is what you intended?

  7. #7
    Join Date
    May 2009
    Posts
    8
    Ah. Thanks for the link to that other forum. It explained it a bit better for me.

    I changed it to this:

    Code:
    for(list<Control *>::iterator it = Control::controls.begin(); it != Control::controls.end();)
    {
    	if (*it < 0)
    	{
    		delete (*it++);
            }
            else
    	{
                it++;
            }
    
    }
    And everything seems to work fine now. I guess It was a stupid mistake. At least now I know better.

    Thank you very much for your help everyone.

  8. #8
    Join Date
    Aug 2004
    Location
    little rock arkansas
    Posts
    3,482

    Talking

    Quote Originally Posted by ChekR View Post
    And everything seems to work fine now. I guess It was a stupid mistake. At least now I know better.

    Thank you very much for your help everyone.
    NO!!!!!!!!!!!!!!

    not a stupid mistake, the new compilers are pickier about coding with VS2003 you could get away with it but not in 2005 and 2008.
    a lot of users hat to upgrade there code and anywhere ylu see an iterator in that code form now on you will have to update it as well.
    ME WANT AGENTS ME WANT AGENTS ME WANT AGENTS

  9. #9
    Join Date
    May 2009
    Posts
    8
    Ah. Thanks for the link to that other forum. It explained it a bit better for me.

    I changed it to this:

    Code:
    for(list<Control *>::iterator it = Control::controls.begin(); it != Control::controls.end();)
    {
    	if (*it < 0)
    	{
    		delete (*it++);
            }
            else
    	{
                it++;
            }
    
    }
    And everything seems to work fine now. I guess It was a stupid mistake. At least now I know better.

    Thank you very much for your help everyone.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •