How to exit an App on KeyPressed

Hello everyone!

I try to make a key (‘q’) when pressed, quit the application.

I tried with exit, std::exit(1), with OF_EXIT_APP(0) but nothing happened
Maybe it’s very more simple but I can’t get through it…
Thanks and have a nice day!

void testApp::keyPressed(int key){

    if (key == 's'){
        usecamera = !usecamera; //Stop the drawing to see the draw
    if (key == 'q'){
1 Like

Works for me on OS X (OF_v_0.8.0)…!
Are you using mac or windows ?

I’m using OS X, same config as you…

I think ofExit() is the newest one

There is also the nuclear option _Exit

So my app is hanging on exit, and only calling _Exit (0) has worked so far to quit out of the program. Is there anything bad / dangerous about that? I realize that it doesn’t call any deconstructors or otherwise let the app do its thing and clean up, but is that necessarily bad?

I would love to know more about this… How can I properly handle app setup exit if some weird conditions happens ?

What is the right way ? Calling ofExit() ? Will App::exit will be called ?

Thanks !!

yes ofExit is the correct way to exit an application, it’ll call ofApp::exit and also release any other resources that OF uses