]> git.mxchange.org Git - flightgear.git/blobdiff - src/Main/bootstrap.cxx
Update image-server logic.
[flightgear.git] / src / Main / bootstrap.cxx
index be6c595b584038734310cfd1829d2827e0f563cc..326401a7573b3e556d4f93d43de53af31d470afa 100644 (file)
@@ -50,6 +50,9 @@
 #include <simgear/compiler.h>
 #include <simgear/structure/exception.hxx>
 
+#include <osg/Texture>
+#include <osg/BufferObject>
+
 #include <cstring>
 #include <iostream>
 using std::cerr;
@@ -57,6 +60,7 @@ using std::endl;
 
 #include <Viewer/fgviewer.hxx>
 #include "main.hxx"
+#include <Include/version.h>
 #include <Main/globals.hxx>
 #include <Main/fg_props.hxx>
 #include <GUI/MessageBox.hxx>
@@ -67,6 +71,13 @@ using std::endl;
     #include <GUI/CocoaHelpers.h> // for transformToForegroundApp
 #endif
 
+#if defined(HAVE_CRASHRPT)
+       #include <CrashRpt.h>
+
+bool global_crashRptEnabled = false;
+
+#endif
+
 std::string homedir;
 std::string hostname;
 
@@ -173,6 +184,50 @@ int main ( int argc, char **argv )
 #endif
     _bootstrap_OSInit = 0;
 
+#if defined(HAVE_CRASHRPT)
+       // Define CrashRpt configuration parameters
+       CR_INSTALL_INFO info;  
+       memset(&info, 0, sizeof(CR_INSTALL_INFO));  
+       info.cb = sizeof(CR_INSTALL_INFO);    
+       info.pszAppName = "FlightGear";
+       info.pszAppVersion = FLIGHTGEAR_VERSION;
+       info.pszEmailSubject = "FlightGear " FLIGHTGEAR_VERSION " crash report";
+       info.pszEmailTo = "fgcrash@goneabitbursar.com";
+       info.pszUrl = "http://fgfs.goneabitbursar.com/crashreporter/crashrpt.php";
+       info.uPriorities[CR_HTTP] = 3; 
+       info.uPriorities[CR_SMTP] = 2;  
+       info.uPriorities[CR_SMAPI] = 1;
+
+       // Install all available exception handlers
+       info.dwFlags |= CR_INST_ALL_POSSIBLE_HANDLERS;
+  
+       // Restart the app on crash 
+       info.dwFlags |= CR_INST_SEND_QUEUED_REPORTS; 
+
+       // automatically install handlers for all threads
+       info.dwFlags |= CR_INST_AUTO_THREAD_HANDLERS;
+
+       // Define the Privacy Policy URL 
+       info.pszPrivacyPolicyURL = "http://flightgear.org/crash-privacypolicy.html"; 
+  
+       // Install crash reporting
+       int nResult = crInstall(&info);    
+       if(nResult!=0) {
+               char buf[1024];
+               crGetLastErrorMsg(buf, 1024);
+               flightgear::modalMessageBox("CrashRpt setup failed", 
+                       "Failed to setup crash-reporting engine, check the installation is not damaged.",
+                       buf);
+       } else {
+               global_crashRptEnabled = true;
+
+               crAddProperty("hudson-build-id", HUDSON_BUILD_ID);
+               char buf[16];
+               ::snprintf(buf, 16, "%d", HUDSON_BUILD_NUMBER);
+               crAddProperty("hudson-build-number", buf);
+       }
+#endif
+
 #if defined(__FreeBSD__)
     // Ignore floating-point exceptions on FreeBSD
     signal(SIGFPE, SIG_IGN); 
@@ -209,14 +264,19 @@ int main ( int argc, char **argv )
         // is possible inside fgExitCleanup
         sglog();
         
+        // similar to above, ensure some static maps inside OSG exist before
+        // we register our at-exit handler, otherwise the statics are gone
+        // when fg_terminate runs, which causes crashes.
+        osg::Texture::getTextureObjectManager(0);
+        osg::GLBufferObjectManager::getGLBufferObjectManager(0);
+        
         std::set_terminate(fg_terminate);
         atexit(fgExitCleanup);
         if (fgviewer)
             fgviewerMain(argc, argv);
         else
             fgMainInit(argc, argv);
-            
-        
+           
     } catch (const sg_throwable &t) {
         std::string info;
         if (std::strlen(t.getOrigin()) != 0)
@@ -236,6 +296,10 @@ int main ( int argc, char **argv )
             perror("Possible cause");
     }
 
+#if defined(HAVE_CRASHRPT)
+       crUninstall();
+#endif
+
     return 0;
 }
 
@@ -243,9 +307,12 @@ int main ( int argc, char **argv )
 // so OpenAL device and context are released cleanly
 void fgExitCleanup() {
 
-    if (_bootstrap_OSInit != 0)
+    if (_bootstrap_OSInit != 0) {
         fgSetMouseCursor(MOUSE_CURSOR_POINTER);
 
+        fgOSCloseWindow();
+    }
+    
     // on the common exit path globals is already deleted, and NULL,
     // so this only happens on error paths.
     delete globals;