SDL not responding to events

View: New views
2 Messages — Rating Filter:   Alert me  

SDL not responding to events

by Sigvatr :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.
I'm trying to setup a basic SDL program but it won't respond to quit, keyboard events or anything. I have to open the task manager to close it. I'm not sure what's wrong.

Here's the code:








Code:
int main( int argc, char *argv[] )
{
   // setup system shutdown handler
   atexit( SDL_Quit );

   // create window
   Window window( 640, 400, false );
   window.initialize();

   // create event manager
   SDL_Event event;

   // create clock
   Clock clock;

   // main loop
   while( active )
   {
      // begin loop iteration
      clock.start();

      // handle events
      while( SDL_PollEvent( &event ) )
      {
         if( event.type == SDL_QUIT )
         {
            active = false;
         }
         if( event.type == SDL_KEYDOWN )
         {
            if( event.key.keysym.sym == SDLK_ESCAPE )
            {
               active = false;
            }
         }
      }
      // end loop iteration
      clock.pause();
   }
   
   // shut down
   SDL_Quit();
   return 0;


And the window class:








Code:
Window::Window( int widthIN, int heightIN, bool fullscreenIN )
{
   width = widthIN;
   height = heightIN;
   fullscreen = fullscreenIN;
}
/// window destructor
Window::~Window()
{
}
/// window initialization function
void Window::initialize()
{   
   // initialize SDL video subsystem
   if( SDL_Init( SDL_INIT_VIDEO ) != 0 )
   {
      // if initialization fails, shut down
      SDL_Quit();
   }
   // set video subsystem parameters
   SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
   SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 8 );
   SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 8 );
   SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 8 );
   SDL_GL_SetAttribute( SDL_GL_ALPHA_SIZE, 8 );

   // create OpenGL window
   Uint32 video_flags = SDL_OPENGL;
   display = SDL_SetVideoMode( 640, 400, 16, video_flags );
   if( display == NULL )
   {
      // if window creation fails, shut down
      SDL_Quit();
   }

   // initialize OpenGL
   glEnable( GL_TEXTURE_2D );
 
   // set OpenGL window parameters
   glViewport( 0, 0, 640, 400 );
   glOrtho( 0.0f, 640, 400, 0.0f, -1.0f, 1.0f) ;

   // set OpenGL general parameters
   glClear( GL_COLOR_BUFFER_BIT );
   glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );
   
   // set OpenGL matrix modes
   glMatrixMode( GL_PROJECTION );
   glLoadIdentity();
   glMatrixMode( GL_MODELVIEW );
   glLoadIdentity();
}

_______________________________________________
SDL mailing list
SDL@...
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Re: SDL not responding to events

by Brian Barrett :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi.

Where is "active" defined? Might it start out as false?

I'm just wondering about your error handling code in your Window class. SDL_Quit() just shuts SDL down, it doesn't terminate the process or anything. It is part of, but not a complete solution to, error handling.

Try using the SDL_GetError() function to retrieve a human readable string of what the error was. You can print this to a log file or display it in a message box. Then you would need to call exit(1) if the error is non-recoverable, or throw an exception / give "initialise" a return value so you can propagate the error back to main().

Finally, you might consider placing a debug breakpoint inside the loops (or print statements) that can verify if they are running.

-- Brian

On Sat, Oct 31, 2009 at 7:11 AM, Sigvatr <me@...> wrote:
I'm trying to setup a basic SDL program but it won't respond to quit, keyboard events or anything. I have to open the task manager to close it. I'm not sure what's wrong.

_______________________________________________
SDL mailing list
SDL@...
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org