Add protection to the multiplayer (AI) interpolation to protect against segfaults when the previous and next packets contain different properties.
This commit is contained in:
parent
e39eac8a6d
commit
0bf80f9b2a
1 changed files with 47 additions and 29 deletions
|
@ -319,18 +319,31 @@ void FGAIMultiplayer::update(double dt)
|
|||
|
||||
int ival;
|
||||
float val;
|
||||
/*
|
||||
* RJH - 2017-01-25
|
||||
* During multiplayer operations a series of crashes were encountered that affected all players
|
||||
* within range of each other and resulting in an exception being thrown at exactly the same moment in time
|
||||
* (within case props::STRING: ref http://i.imgur.com/y6MBoXq.png)
|
||||
* Investigation showed that the nextPropIt and prevPropIt were pointing to different properties
|
||||
* which may be caused due to certain models that have overloaded mp property transmission and
|
||||
* these craft have their properties truncated due to packet size. However the result of this
|
||||
* will be different contents in the previous and current packets, so here we protect against
|
||||
* this by only considering properties where the previous and next id are the same.
|
||||
* It might be a better solution to search the previous and next lists to locate the matching id's
|
||||
*/
|
||||
if (*nextPropIt && (*nextPropIt)->id == (*prevPropIt)->id ) {
|
||||
switch ((*prevPropIt)->type) {
|
||||
case props::INT:
|
||||
case props::BOOL:
|
||||
case props::LONG:
|
||||
ival = (int) (0.5+(1-tau)*((double) (*prevPropIt)->int_value) +
|
||||
tau*((double) (*nextPropIt)->int_value));
|
||||
ival = (int)(0.5 + (1 - tau)*((double)(*prevPropIt)->int_value) +
|
||||
tau*((double)(*nextPropIt)->int_value));
|
||||
pIt->second->setIntValue(ival);
|
||||
//cout << "Int: " << ival << "\n";
|
||||
break;
|
||||
case props::FLOAT:
|
||||
case props::DOUBLE:
|
||||
val = (1-tau)*(*prevPropIt)->float_value +
|
||||
val = (1 - tau)*(*prevPropIt)->float_value +
|
||||
tau*(*nextPropIt)->float_value;
|
||||
//cout << "Flo: " << val << "\n";
|
||||
pIt->second->setFloatValue(val);
|
||||
|
@ -342,7 +355,7 @@ void FGAIMultiplayer::update(double dt)
|
|||
break;
|
||||
default:
|
||||
// FIXME - currently defaults to float values
|
||||
val = (1-tau)*(*prevPropIt)->float_value +
|
||||
val = (1 - tau)*(*prevPropIt)->float_value +
|
||||
tau*(*nextPropIt)->float_value;
|
||||
//cout << "Unk: " << val << "\n";
|
||||
pIt->second->setFloatValue(val);
|
||||
|
@ -350,6 +363,11 @@ void FGAIMultiplayer::update(double dt)
|
|||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
SG_LOG(SG_AI, SG_WARN, "MP packet mismatch during lag interpolation: " << (*prevPropIt)->id << " != " << (*nextPropIt)->id << "\n");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
SG_LOG(SG_AI, SG_DEBUG, "Unable to find property: " << (*prevPropIt)->id << "\n");
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue