Using two or more apps

I’m trying to run one app, and then after it is finished, launch a new app. (After I get it working, I want them to switch back and forth indefinitely. Each app last about 5-10 minutes.) I can’t figure out how to call the new app. First I tried with main, but the line after calling the first app is never called if I exit by exiting out of the window, calling ofExit() or using std::exit(0).

#include "ofMain.h" #include "ofApp.h" #include "otherApp.h" int main( ) { ofSetupOpenGL(1024,768, OF_WINDOW); ofRunApp( new ofApp() ); std::cout << "this line is never outputted" << std::endl; ofRunApp( new otherApp() ); }

Is the appropriate action to call the second app from within the first app? Then I will probably run into the issue of having many apps recursively running at the same time.

1 Like

I found it’s possible to call ofGetWindowPtr->windowShouldClose() to make the app exit without exiting the program. But still if I try to run another app it crashes.

Is there a way to run two apps consecutively? Or to exit an app in a safe way without deinitializing OF?

1 Like

Solved it, here’s what needs to be done:

  • Call ofSetupOpenGL(...) just once
  • End each app by calling ofGetWindowPtr()->windowShouldClose();
  • Use make_shared<ofApp>() when calling ofRunApp
  • Reset GLFW window should close flag
  • Remove all listeners OF adds to your app after in finishes (see example below). I believe this step should be added to OF, I’ll see to it if any dev agrees.

Check an example at this GitHub gist: Run several ofApps

Note: This is for OF 0.8.4, 0.9.0 introduces ofMainLoop which may work differently. However some of these might still apply.

2 Likes