PDA

View Full Version : RunTime Error



Rajesh
05-23-2002, 01:53 AM
Dear All,

Please tell me exact error in this code.It is showing the runtime error.It is compiling correctly.I am using Windows NT platform.

The window(black) is displaying and after that it is showing run time error.Please tell me where exactly is the error.

#include <glut.h>
#define XSIZE 100
#define YSIZE 100

GLUquadricObj *qobj;


void init()
{
glShadeModel(GL_FLAT);
}

void reshape(int w, int h)
{
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60.0, (GLfloat)w/(GLfloat)h, 1.0, 20.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
/*glTranslatef(0.0,6.2,-10.0);
glRotatef(290.0f,1.0,0.0, 0.0);*/
}

void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glTranslatef(-5,0,0);
glRotatef(45,1,0,0);
glPushMatrix();
qobj=gluNewQuadric();
gluCylinder(qobj,20,100,10,10,20,10);
glPopMatrix();
glFlush();
}

void main(int argc,char** argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA);
glutInitWindowSize(XSIZE, YSIZE);
glutInitWindowPosition(100, 100);
glutCreateWindow("FATAL FX' Pendulum [www.fatalfx.com]");
init();
glutReshapeFunc(reshape);
glutDisplayFunc(display);
glutMainLoop();

return 0;
}

Robbo
05-23-2002, 02:06 AM
For starters, you are not deleting the quadric object after use. My guess is you have a giant memory leak http://www.opengl.org/discussion_boards/ubb/wink.gif

coredump
05-23-2002, 04:32 AM
yep...every time a frame is drawn a new quadric object is allocated. you'd run out of memory kinda quick doing that. try allocating it once, say, in your init() function.

b

AsylumX
05-23-2002, 07:13 PM
or perhaps just delete it at the end of your display function?

Looking at your code again, I don't see any reason that qobj needs to be global. Perhaps just create qobj at the beginning of your display function and delete it at the end.

-AsylumX

[This message has been edited by AsylumX (edited 05-23-2002).]