Seg Fault with event handling

I call my event handling adn I get a Segmentation fault.
Here’s the code

int key_events()
{
Uint8 *keys;
SDL_Event event;
while ( SDL_PollEvent(&event) )
{
keys = SDL_GetKeyState(NULL);

       if ( event.type == SDLK_ESCAPE )
            {
              exit(1);
            }

}
}

int main()
{
srand(time(NULL));
key_events();
initialize();
load_images();
setcolormap();
blit_background();
blit_toolbar();
trans_image();
which_scen();
exit(1);
}
Not sure whats causing this but if I leave key_events out of main, it will
launch app. If I leabve it in I get a seg fault.

I notice that you’re calling key_events() before you call initialize().
If you call SDL_Init in initialize() (like I expect you do), then you’re
trying to use event handling before SDL is ready to be used. Try
switching the order.

Hope this helps,
–Ryan

“Tony M.” wrote:>

I call my event handling adn I get a Segmentation fault.
Here’s the code

int key_events()
{
Uint8 *keys;
SDL_Event event;
while ( SDL_PollEvent(&event) )
{
keys = SDL_GetKeyState(NULL);

       if ( event.type == SDLK_ESCAPE )
            {
              exit(1);
            }

}
}

int main()
{
srand(time(NULL));
key_events();
initialize();
load_images();
setcolormap();
blit_background();
blit_toolbar();
trans_image();
which_scen();
exit(1);
}
Not sure whats causing this but if I leave key_events out of main, it will
launch app. If I leabve it in I get a seg fault.

Uint8 *keys;
SDL_Event event;
while ( SDL_PollEvent(&event) )
{
keys = SDL_GetKeyState(NULL);

       if ( event.type == SDLK_ESCAPE )
            {
              exit(1);
            }

Also:
if ( event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_ESCAPE )

-Sam Lantinga, Lead Programmer, Loki Entertainment Software