Skip to content

Instantly share code, notes, and snippets.

@mmansion
Last active November 3, 2018 23:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mmansion/b04296db22d27ca0fa5029d3fadc7953 to your computer and use it in GitHub Desktop.
Save mmansion/b04296db22d27ca0fa5029d3fadc7953 to your computer and use it in GitHub Desktop.
Restart OF App on Crash
#include "ofMain.h"
#include "ofApp.h"
#include <signal.h>
extern "C" void onAbort(int signum) {
ofApp::restart();
}
//========================================================================
int main( ){
SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX);
_set_abort_behavior(0, _WRITE_ABORT_MSG);
signal(SIGABRT, &onAbort);
ofSetupOpenGL(1024,768,OF_WINDOW); // <-------- setup the GL context
// this kicks off the running of my app
// can be OF_WINDOW or OF_FULLSCREEN
// pass in width and height too:
ofRunApp(new ofApp());
}
#include "ofApp.h"
//------------------------------------------------------------- -
void ofApp::restart() {
ofLogToFile("crash_reports.txt", true);
ofLog() << "The app restarted : " << ofGetTimestampString() << endl;
string path = "";
ofDirectory dir(path);
cout << dir.getAbsolutePath() << endl;
// set this path to a BAT file that restarts the app
ofSystem("start C:/Users/../RESTART_APP.BAT");
}
//--------------------------------------------------------------
void ofApp::setup(){
}
//--------------------------------------------------------------
void ofApp::update(){
}
//--------------------------------------------------------------
void ofApp::draw(){
}
//--------------------------------------------------------------
void ofApp::keyPressed(int key){
}
//--------------------------------------------------------------
void ofApp::keyReleased(int key){
}
//--------------------------------------------------------------
void ofApp::mouseMoved(int x, int y ){
}
//--------------------------------------------------------------
void ofApp::mouseDragged(int x, int y, int button){
}
//--------------------------------------------------------------
void ofApp::mousePressed(int x, int y, int button){
}
//--------------------------------------------------------------
void ofApp::mouseReleased(int x, int y, int button){
}
//--------------------------------------------------------------
void ofApp::mouseEntered(int x, int y){
}
//--------------------------------------------------------------
void ofApp::mouseExited(int x, int y){
}
//--------------------------------------------------------------
void ofApp::windowResized(int w, int h){
}
//--------------------------------------------------------------
void ofApp::gotMessage(ofMessage msg){
}
//--------------------------------------------------------------
void ofApp::dragEvent(ofDragInfo dragInfo){
}
#pragma once
#include "ofMain.h"
class ofApp : public ofBaseApp{
public:
void static restart();
void setup();
void update();
void draw();
void keyPressed(int key);
void keyReleased(int key);
void mouseMoved(int x, int y );
void mouseDragged(int x, int y, int button);
void mousePressed(int x, int y, int button);
void mouseReleased(int x, int y, int button);
void mouseEntered(int x, int y);
void mouseExited(int x, int y);
void windowResized(int w, int h);
void dragEvent(ofDragInfo dragInfo);
void gotMessage(ofMessage msg);
ofDirectory dir;
};
:: place in bin/data dir
taskkill /f /IM /myAppName.exe
timeout /t 3
start %~dp0\..\myAppName.exe
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment