Jump to content
  • Advertisement
Sign in to follow this  
sd_dracula

stack overflow error from printing text?

This topic is 4136 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

whenever i use this function to draw text on the screen i get a lot of stack overflow errors in the console window. it doesnt crash but i think if i leave it running long enough it does. char pixelstring[30]; void printText(const char* text, int s, float x, float y, float z) { sprintf(pixelstring, text, s); //Print a string to the screen glPushMatrix(); glDisable(GL_LIGHTING); glColor4f(1.0,1.0,0.0,1.0); glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); gluOrtho2D(0, 200, 0, 200); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); // render the string renderBitmapString(x,y,z,GLUT_BITMAP_TIMES_ROMAN_24,pixelstring); glPopMatrix(); glMatrixMode(GL_PROJECTION); glPopMatrix(); glMatrixMode(GL_MODELVIEW); } void renderBitmapString(float x, float y, float z, void *font, char *string) { char *c; glRasterPos3f(x, y,z); for (c=string; *c != '\0'; c++) { glutBitmapCharacter(font, *c); } } and then i call this inside the display funciton of glut printText("SCORE: %d",score,0,0,0); can anyone see a problem there?

Share this post


Link to post
Share on other sites
Advertisement
The answer is very simple: You got 3 glPushMatrix but only 2 glPopMatrix so this causes a stack overflow

Share this post


Link to post
Share on other sites
Sign in to follow this  

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