]> git.mxchange.org Git - flightgear.git/blobdiff - src/Main/bootstrap.cxx
Update image-server logic.
[flightgear.git] / src / Main / bootstrap.cxx
index 990018d36b4d341c8731842ca6fc7465478f70c1..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,12 +60,24 @@ using std::endl;
 
 #include <Viewer/fgviewer.hxx>
 #include "main.hxx"
-#include "globals.hxx"
-#include "fg_props.hxx"
-
+#include <Include/version.h>
+#include <Main/globals.hxx>
+#include <Main/fg_props.hxx>
+#include <GUI/MessageBox.hxx>
 
 #include "fg_os.hxx"
 
+#if defined(SG_MAC)
+    #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;
 
@@ -120,7 +135,7 @@ static void initFPE()
 }
 #endif
 
-#if defined(_MSC_VER) || defined(_WIN32)
+#if defined(SG_WINDOWS)
 int main ( int argc, char **argv );
 int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
                              LPSTR lpCmdLine, int nCmdShow) {
@@ -131,10 +146,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
 
 static void fg_terminate() {
     cerr << endl <<
-            "Uncaught Exception: you should see a meaningful error message\n"
-            "here, but your GLUT (or SDL) library was apparently compiled\n"
-            "and/or linked without exception support. Please complain to\n"
-            "its provider!"
+            "Uncaught Exception: missing exception handler on some thread"
             << endl << endl;
     abort();
 }
@@ -144,7 +156,7 @@ int _bootstrap_OSInit;
 // Main entry point; catch any exceptions that have made it this far.
 int main ( int argc, char **argv )
 {
-#if defined(_MSC_VER) || defined(_WIN32) 
+#if defined(SG_WINDOWS)
   // Don't show blocking "no disk in drive" error messages on Windows 7,
   // silently return errors to application instead.
   // See Microsoft MSDN #ms680621: "GUI apps should specify SEM_NOOPENFILEERRORBOX"
@@ -160,12 +172,62 @@ int main ( int argc, char **argv )
   signal(SIGPIPE, SIG_IGN);
 #endif
 
+#if defined(SG_MAC)
+    // required so native messages boxes work prior to osgViewer init
+    // (only needed when not running as a bundled app)
+    transformToForegroundApp();
+#endif
+    
 #ifdef PTW32_STATIC_LIB
     // Initialise static pthread win32 lib
     pthread_win32_process_attach_np ();
 #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); 
@@ -202,28 +264,29 @@ 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) {
-                            // We must use cerr rather than
-                            // logging, since logging may be
-                            // disabled.
-        cerr << "Fatal error: " << t.getFormattedMessage() << endl;
+        std::string info;
         if (std::strlen(t.getOrigin()) != 0)
-            cerr << " (received from " << t.getOrigin() << ')' << endl;
+            info = std::string("received from ") + t.getOrigin();
+        flightgear::fatalMessageBox("Fatal exception", t.getFormattedMessage(), info);
 
     } catch (const std::exception &e ) {
-        cerr << "Fatal error (std::exception): " << e.what() << endl;
-
+        flightgear::fatalMessageBox("Fatal exception", e.what());
     } catch (const std::string &s) {
-        cerr << "Fatal error (std::string): " << s << endl;
-
+        flightgear::fatalMessageBox("Fatal exception", s);
     } catch (const char *s) {
         cerr << "Fatal error (const char*): " << s << endl;
 
@@ -233,6 +296,10 @@ int main ( int argc, char **argv )
             perror("Possible cause");
     }
 
+#if defined(HAVE_CRASHRPT)
+       crUninstall();
+#endif
+
     return 0;
 }
 
@@ -240,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;