Skip to main content
GameDev.net gamedev.net
🔒 Locked

GL_STACK_OVERFLOW

Started by General_Lee Dec 19, 2010 at 12:58 PM 6 replies 4.2k views
Original Post
General_Lee
General_Lee
I guess my problem is very stupid, but anyway I can't figure it out.
My program is using this code to sync my physics actor(PhysX) and my display list.

tmp=glGenLists(1); //tmp is temp display listglNewList(tmp,GL_COMPILE);glPushMatrix();glLoadIdentity();glTranslatef(m_actor->getGlobalPosition().x,m_actor->getGlobalPosition().y,m_actor->getGlobalPosition().z);	glRotated(m_actor->getGlobalOrientationQuat().getAngle(),m_actor->getGlobalOrientationQuat().x,m_actor->getGlobalOrientationQuat().y,m_actor->getGlobalOrientationQuat().z);glCallList(list);glPopMatrix();glEndList();list=tmp;


While I was using glslDevel, it detected that GL_STACK_OVERFLOW error appears.
I would be grateful for any help.
szecs
szecs
Well, I have no idea what you are trying to do...

Is list assigned anywhere? If you want to compile a display list, you don't have to call glCallList. Or it is your intention to nest display lists?

The whole thing seems very fishy, are you trying to spare a variable?

Show all the code between [source] and [/source] tags.
General_Lee
General_Lee
Im calling the display list because FXACE suggested it to me in this thread - http://www.gamedev.net/community/forums/topic.asp?topic_id=590770

#include <classes.h>#include <freeglut.h>#include <boost\timer.hpp>#include <iostream>boost::timer t; // start timingEngine *engine = new Engine();DrawableObject * obj;void		DisplayFunc(void){    /* Clear the buffer, clear the matrix */  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);  glMatrixMode( GL_PROJECTION );  //glLoadIdentity();  engine->simulate(1.0f/60.0f);  obj->sync();  /*  std::cout<<obj->getPosition().x;  std::cout<<"   ";  std::cout<<obj->getPosition().y;  std::cout<<"   ";  std::cout<<obj->getPosition().z<<std::endl;  std::cout<<obj-	  */  glCallList(obj->getDisplayList());  //glPushMatrix();  //glFlush();  glutSwapBuffers();   /* Update again and again */  glutPostRedisplay();    #ifdef DEBUG  cout<<alpha<<endl;#endif}/*** Function called when the window is created or resized*/void ReshapeFunc(int width, int height){	glMatrixMode(GL_PROJECTION);	glLoadIdentity();	// Near clipping plane needs to be closer and far further like this	gluPerspective(20, width / (float) height, 0.000001f, 1000000.0f);	glViewport(0, 0, width, height);	glMatrixMode(GL_MODELVIEW);	glutPostRedisplay();}/*** Function called when a key is hit*/void		KeyboardFunc(unsigned char key, int x, int y){  int foo;  foo = x + y; /* Has no effect: just to avoid a warning */      }int		main(int argc, char **argv){    /* Creation of the window */  glutInit(&argc, argv);  glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);  glutInitWindowSize(1000, 1000);  glutCreateWindow("Spinning cube");  engine->Init(-9.81);  obj = new DrawableObject("models\\cube.3ds",engine->getScene());  //obj->setPosition(NxVec3(0.5,0.5,-1));  glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);  glEnable(GL_NORMALIZE);  /* Declaration of the callbacks */  glutDisplayFunc(&DisplayFunc);  glutReshapeFunc(&ReshapeFunc);  glutKeyboardFunc(&KeyboardFunc);    /* Loop */  glutMainLoop();  /* Never reached */  return 0;}

#include "../include/DrawableObject.h"bool DrawableObject::isDynamic(void){	return Dynamic;}void DrawableObject::setPosition(NxVec3 vector){	position = vector;	tmp=glGenLists(1);	glNewList(tmp,GL_COMPILE);	glPushMatrix();	glLoadIdentity();	glTranslatef(vector.x,vector.y,vector.z);		glCallList(list);	glPopMatrix();	glEndList();	list=tmp;	}void DrawableObject::setOrientation(NxQuat  orientation){	tmp=glGenLists(1);	glNewList(tmp,GL_COMPILE);	glPushMatrix();	glRotated(orientation.w,orientation.x,orientation.y,orientation.z);	glCallList(list);	glPopMatrix();	glEndList();	list=tmp;}void DrawableObject::sync(){    tmp=glGenLists(1);	glNewList(tmp,GL_COMPILE);	glPushMatrix();	glLoadIdentity();	position = m_actor->getGlobalPosition();	glTranslatef(m_actor->getGlobalPosition().x,m_actor->getGlobalPosition().y,m_actor->getGlobalPosition().z);		glRotated(m_actor->getGlobalOrientationQuat().getAngle(),m_actor->getGlobalOrientationQuat().x,m_actor->getGlobalOrientationQuat().y,m_actor->getGlobalOrientationQuat().z);	glCallList(list);	glPopMatrix();	glEndList();	list=tmp;}void DrawableObject::createRenderList(){	list=glGenLists(1);    glNewList(list,GL_COMPILE);	m_model= new Model();	m_model->LoadModel(path_to_model);	glEndList();}DrawableObject::DrawableObject(const char* path,NxScene * gScene){	NxBodyDesc bodyDesc;	bodyDesc.angularDamping	= 0.5f;	NxBoxShapeDesc boxDesc;	boxDesc.dimensions = NxVec3(2.0f, 2.0f, 2.0f);	NxActorDesc actorDesc;		actorDesc.shapes.pushBack(&boxDesc);	actorDesc.body			= &bodyDesc	actorDesc.density		= 10.0f;	actorDesc.globalPose.t  = NxVec3(0,0,0);	m_actor=gScene->createActor(actorDesc);	path_to_model=path;	createRenderList();}GLuint DrawableObject::getDisplayList(){	return list;}NxVec3 DrawableObject::getPosition(){	return position;}NxActor * DrawableObject::getNxActor(){	return m_actor;}
sprite_hound
sprite_hound
You appear to be further nesting your display list every single frame. There is a limit to how many you can nest (it must be at least 64, but that's still not many...)

A better way would be to keep track of an inner list for your model, and an outer list for your transform, and just change the outer list when you need to.

i.e. currently:
frame 1:transform_list    model_listframe 2:transform_list    transform_list        model_list...


change this to:
frame 1:transform_list    model_listframe 2:transform_list_2    model_listframe 3:transform_list_3    model_list...



You should also be calling glDeleteLists when you're done with them, instead of leaking the memory.
silvermace
silvermace
most implementations of GL will only allow a stack depth of around 32. (you can check by calling glGetInteger with GL_MAX_MODELVIEW_STACK_DEPTH)

Your problem is that you appear to be implicitly making a "recursive" call to glPush/glPop matrix. You are calling glCallList while making a new list which is already using the stack, you then replace the last 'list' value with the newly generated list, once you do this several times, you will easily creep past the max stack depth.

You should refactor your code to not require display lists, as they will (or already are?) deprecated functionality.

If you are adamant you want to keep the display lists, then you should only build and maintain 1 list, and each time you build it, you mustn't call any previous lists, I would suggest using a dirty flag for all your setters, and only build the list in the draw code if the dirty flag is set.

void setPosition(NxVec3 pos) { this->pos = pos; dirty = true }void draw() {  if(dirty) {    createDisplayListFromScratch();    dirty = false;  }   glCallList(this->list)}
Something along those lines..
karwosts
karwosts
I seriously suggest you just drop all the display list stuff (it's old and deprecated) and try to learn how to do things the proper way. (vertex buffers and manual matrix management)

I cannot figure out what you're trying to do with your lists, but it looks very bizarre, and I think you're calling your display list in an infinite recursive loop which is why you're getting the stack overflow.
[size=2]My Projects:
[size=2]Portfolio Map for Android - Free Visual Portfolio Tracker
[size=2]Electron Flux for Android - Free Puzzle/Logic Game
blubberbert
blubberbert
are you trying to compile DLs in runtime?? baaaad idea.
anyway your DL setup code looks wrong... i have no idea what your trying to do exactly
glGenList(create a list handle)
glNewList()

glEndList()

by the way, the gl error means that there were to many glPushMatrix without corresponding glPopMatrix calls (=>matrix stack overflow)
------------------------------
Join the revolution and get a free donut!
General_Lee
General_Lee
Thanks for such a quick and helpful responses. I'll try to fix it as sprite_hound suggested and then learn vertex buffers.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.