SDL_PollEvent() problem

Started by
2 comments, last by Kylotan 15 years ago
Has anyone experienced SDL_PollEvent(&event) in a function quits its while loop at the beginning it's executed? while(SDL_PollEvent(&event)) ...in this code: int title_screen() { bool quit = false; Title theTitle; while( quit == false ) { //While there's events to handle while( SDL_PollEvent( &event ) ) { theTitle.handle_input(); if( event.type == SDL_QUIT ) { //Quit the program quit = true; } } //Apply surfaces apply_surface ( 0, 0, title, screen ); //Update the screen if( SDL_Flip( screen ) == -1 ) { return 1; } } return 0; } I'm using Multithreaded DLL code generation. The first time title_screen()executed it's normal. That function title_screen() is called within main(). But second time it's executed (the flow is after title_screen() -> main_menu() -> title_screen(), so this function is called again) the SDL_PollEvent() returns false, avoiding the handle_input() function. The main_menu() uses SDL_PollEvent() too and experiencing same problem: First time called it's normal, second call PollEvent() quits irresponsibly. What possibly happening? [Edited by - andrern2000 on March 28, 2009 4:56:12 AM]
Advertisement
Sorry! No intend to spam. The double post is unintentional. I clicked the Submit button twice.
Nobody want to help? I need the solution immediately.

Wait, let me rewind a bit detail:
There are no errors, just the missing condition somewhere in...

while( SDL_PollEvent(&event) )

...which makes it returns false when executed inside a function that's called twice within the main(), so that it won't enter the body. My question is: What causes it to return false?

====
Btw, my main() function:

main(...)
{
while (quit=false)
{
if mode=1
{ title_screen(); }
else
{ mainmenu(); }

//While there's events to handle
while( SDL_PollEvent( &event ) ) <-- Could it be collides with &event here?
{
if( event.type == SDL_QUIT )
{ //Quit the program
quit = true;
}
}
}

SDL_PollEvent only returns true when there is actually an event to handle. Most of the time it will return false, and that's expected.

This topic is closed to new replies.

Advertisement