1
0
Fork 0

Fix for SEGFAULT when using multiple loggers.

Patch from Julian BREITENEICHER.
This commit is contained in:
Stuart Buchanan 2015-11-22 17:11:36 +00:00
parent 3e462f3056
commit 660c38ce72
2 changed files with 17 additions and 10 deletions

View file

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

View file

@ -45,7 +45,7 @@ private:
char delimiter; char delimiter;
}; };
std::vector<Log> _logs; std::vector<Log *> _logs;
}; };