|
View:
New views
1 Messages
—
Rating Filter:
Alert me
|
|
|
SDL not responding to eventsHi, I suggest a 'break' statement after the 'active=false'. It may not explain why the app never quits but as soon as you've caught a quit event of any kind, you may not want to continue reading the event queue. Moreover, supposing something is producing SDL events continuously, then your program would never leave the "while" loop. Also, you may replace the if(..) if(..) by a switch() ... case because in your code, you're testing for 'SDL_KEYDOWN' even if you detected a 'SDL_QUIT' previously, which is a useless test to perform. A 'break' avoids this, and a switch...case is even cleaner. This is not significant for catching 2 event types but if your application is growing, think about
it. Look at the examples in the SDL doc, it's a very good place to start writing efficient code. Also, try putting a printf/cout inside the event loop to be sure it's the location where the program is looping (and not in a previous function like in 'window.initialize'). Once you find where it is looping, fix the problem. Regards, Julien CLEMENTI'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; _______________________________________________ SDL mailing list SDL@... http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org |
| Free embeddable forum powered by Nabble | Forum Help |