Resetting ofApp while program is still running



it may be a false memory, but i remember somewhere (maybe from processing?) that it is not good practice to call setup() from within a program. i have multiple interfaces that can be used and i want my program to reset to its original at run-time state if a new interface is chosen. may i do:

if(interfaceIschanged == true) ofApp::setup();


thanks in advance.


If you don’t want to call setup() multiple times you can put all your initialization code in a separate function and call it once from setup() and then anytime you like. Of course you have to be careful avoiding memory leaks if you allocate some memory there.


thanks davide,

that’s a good idea and it will probably work better than calling setup upon an interface change as my program crashes when i do so.