]> git.mxchange.org Git - flightgear.git/commitdiff
Fix for SEGFAULT when using multiple loggers.
authorStuart Buchanan <stuart_d_buchanan@yahoo.co.uk>
Sun, 22 Nov 2015 17:11:36 +0000 (17:11 +0000)
committerStuart Buchanan <stuart_d_buchanan@yahoo.co.uk>
Sun, 22 Nov 2015 17:11:36 +0000 (17:11 +0000)
Patch from Julian BREITENEICHER.

src/Main/logger.cxx
src/Main/logger.hxx

index 0e8109e0df7b8b6f8b54393d26bd3a487ce0534d..6c18162c312b22bac7e66c36b15bfc037e6a9497 100644 (file)
@@ -29,6 +29,10 @@ FGLogger::FGLogger ()
 
 FGLogger::~FGLogger ()
 {
+    for (unsigned int i = 0; i < _logs.size(); i++) {
+        delete _logs[i];
+    }
+    _logs.clear();
 }
 
 void
@@ -46,8 +50,8 @@ FGLogger::init ()
     if (!child->getBoolValue("enabled", false))
         continue;
 
-    _logs.push_back(Log());
-    Log &log = _logs[_logs.size()-1];
+    _logs.push_back(new Log());
+    Log &log = *_logs[_logs.size()-1];
     
     string filename = child->getStringValue("filename");
     if (filename.empty()) {
@@ -102,6 +106,9 @@ FGLogger::init ()
 void
 FGLogger::reinit ()
 {
+    for (unsigned int i = 0; i < _logs.size(); i++) {
+        delete _logs[i];
+    }
     _logs.clear();
     init();
 }
@@ -122,14 +129,14 @@ FGLogger::update (double dt)
     double sim_time_sec = globals->get_sim_time_sec();
     double sim_time_ms = sim_time_sec * 1000;
     for (unsigned int i = 0; i < _logs.size(); i++) {
-        while ((sim_time_ms - _logs[i].last_time_ms) >= _logs[i].interval_ms) {
-            _logs[i].last_time_ms += _logs[i].interval_ms;
-            (*_logs[i].output) << sim_time_sec;
-            for (unsigned int j = 0; j < _logs[i].nodes.size(); j++) {
-                (*_logs[i].output) << _logs[i].delimiter
-                          << _logs[i].nodes[j]->getStringValue();
+        while ((sim_time_ms - _logs[i]->last_time_ms) >= _logs[i]->interval_ms) {
+            _logs[i]->last_time_ms += _logs[i]->interval_ms;
+            (*_logs[i]->output) << sim_time_sec;
+            for (unsigned int j = 0; j < _logs[i]->nodes.size(); j++) {
+                (*_logs[i]->output) << _logs[i]->delimiter
+                                    << _logs[i]->nodes[j]->getStringValue();
             }
-            (*_logs[i].output) << endl;
+            (*_logs[i]->output) << endl;
         }
     }
 }
index c1b56b2643c19fed9a0c7b95cd2c858537c5ba99..3d2146a83ec9fa7e00182da6babfcf465255c58b 100644 (file)
@@ -45,7 +45,7 @@ private:
     char delimiter;
   };
 
-  std::vector<Log> _logs;
+  std::vector<Log *> _logs;
 
 };