Hi everybody…
Here’s the trouble I’m having (I’m including the following code as an
example):
#include <string.h>
#include <stdlib.h>
#include <SDL.h>
int main() {
SDL_Init( SDL_INIT_VIDEO );
SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 5 );
SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 5 );
SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 5 );
SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 16 );
SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
if ( SDL_SetVideoMode( 800, 600, 16, SDL_OPENGL ) == NULL ) {
fprintf(stderr, “Couldn’t set GL mode: %s\n”, SDL_GetError());
exit(1);
}
glViewport( 0, 0, 800, 600 );
glClearColor( 1.0, 1.0, 1.0, 1.0 );
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
gluPerspective( 90, 800/600, 1, 100 );
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
while ( 1 ) {
glLoadIdentity();
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glTranslatef( -1.5, 0.0, -6.0 );
glBegin( GL_POLYGON );
glColor3f( 1.0, 0.0, 0.0 );
glVertex3f( 0.0, 1.0, 0.0 );
glColor3f( 0.0, 1.0, 0.0 );
glVertex3f( 1.0, -1.0, 0.0 );
glColor3f( 0.0, 0.0, 1.0);
glVertex3f( -1.0, -1.0, 0.0 );
glEnd();
SDL_GL_SwapBuffers();
SDL_Event event;
if ( SDL_PollEvent( &event ) > 0 ) {
if ( event.type == SDL_KEYDOWN )
break;
}
}
SDL_Quit();
}
As you can see it’s pretty boiler-plate.
Now, the problem is that running this program and hitting a key will crash X
and dump me uncerimoniously back to XDM. Now, I realize that this isn’t a
"normal" game application because its updating the screen way too fast, and
indeed if I insert a sleep(1) after the rendering code then everything is
fine. However I’m left wondering why this is crashing X and furthermore
what amount of delay is the lowest needed to keep it from crashing…perhaps
if I simply inserted a delay before quitting the application it would be OK,
however I haven’t tested this and I’m still wondering why this would be
neccessary since it isn’t documented anywhere.
Anyway, just thought I’d give you guys something to mull over. My system is
an Intel Pentium II/400, TNT2 (using the older, more stable (?) nvidia glx
driver), glibc 2.1.
Thanks in advance,
-Will Weisser