]> git.mxchange.org Git - simgear.git/commitdiff
Mac OS X fixes from Jonathan Polley.
authordavid <david>
Fri, 10 May 2002 21:33:12 +0000 (21:33 +0000)
committerdavid <david>
Fri, 10 May 2002 21:33:12 +0000 (21:33 +0000)
simgear/debug/logstream.cxx
simgear/debug/logstream.hxx
simgear/debug/logtest.cxx

index deca69939aa6c0bbcce7e22b3dc4be06cd298d96..c47d4c8b35a2d050d50ebdf94f1c972deb81b26c 100644 (file)
@@ -23,6 +23,8 @@
 
 #include "logstream.hxx"
 
+logstream *global_logstream = NULL;
+
 bool            logbuf::logging_enabled = true;
 sgDebugClass    logbuf::logClass        = SG_NONE;
 sgDebugPriority logbuf::logPriority     = SG_INFO;
index 5b57d50f0f8f977cb162cd90ed2a72a364291b1f..ea35ee956c66d935ba575a23c8feab1feb35f060 100644 (file)
@@ -256,6 +256,7 @@ logstream::operator<< ( const loglevel& l )
     return *this;
 }
 
+extern logstream *global_logstream;
 
 /**
  * \relates logstream
@@ -267,8 +268,22 @@ logstream::operator<< ( const loglevel& l )
 inline logstream&
 sglog()
 {
-    static logstream logstrm( cerr );
-    return logstrm;
+  if (global_logstream == NULL) {
+
+#ifdef __APPLE__
+    /**
+     * There appears to be a bug in the C++ runtime in Mac OS X that
+     * will crash if certain funtions are called (in this case
+     * cerr.rdbuf()) during static initialization of a class. This
+     * print statement is hack to kick the library in the pants so it
+     * won't crash when cerr.rdbuf() is first called -DW 
+     **/
+    cout << "Using Mac OS X hack for initializing C++ stdio..." << endl;
+#endif    
+    global_logstream = new logstream (cerr);
+  }
+    
+  return *global_logstream;
 }
 
 
index bf923e7a657f87d1c6ecca650e7c8f5d42ba4daa..afa5ddcc2a816c124196278334ecc0f6f3a4facf 100644 (file)
@@ -1,16 +1,32 @@
 #include <string>
 #include "Debug/logstream.hxx"
 
+class Test {
+
+       public:
+       Test() {
+         //cout << "Cout seems to work" << endl;
+         //cerr << "Cerr seems to work" << endl;
+         
+         sglog().setLogLevels( SG_ALL, SG_INFO );
+         
+         SG_LOG(SG_EVENT, SG_INFO, "Test::Test" << "foo");
+       }
+
+};
+
+Test test;
+
 int
 main( int argc, char* argv[] )
 {
-    fglog().setLogLevels( SG_ALL, SG_INFO );
+    sglog().setLogLevels( SG_ALL, SG_INFO );
 
-    SG_LOG( FG_TERRAIN, FG_BULK,  "terrain::bulk" ); // shouldnt appear
-    SG_LOG( FG_TERRAIN, SG_DEBUG, "terrain::debug" ); // shouldnt appear
-    SG_LOG( FG_TERRAIN, SG_INFO,  "terrain::info" );
-    SG_LOG( FG_TERRAIN, FG_WARN,  "terrain::warn" );
-    SG_LOG( FG_TERRAIN, SG_ALERT, "terrain::alert" );
+    //SG_LOG( FG_TERRAIN, FG_BULK,  "terrain::bulk" ); // shouldnt appear
+    //SG_LOG( FG_TERRAIN, SG_DEBUG, "terrain::debug" ); // shouldnt appear
+    //SG_LOG( FG_TERRAIN, SG_INFO,  "terrain::info" );
+    //SG_LOG( FG_TERRAIN, FG_WARN,  "terrain::warn" );
+    //SG_LOG( FG_TERRAIN, SG_ALERT, "terrain::alert" );
 
     int i = 12345;
     long l = 54321L;