1
0
Fork 0

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:
Richard Harrison 2017-01-30 23:24:39 +01:00
parent e39eac8a6d
commit 0bf80f9b2a

View file

@ -319,35 +319,53 @@ void FGAIMultiplayer::update(double dt)
int ival; int ival;
float val; float val;
switch ((*prevPropIt)->type) { /*
case props::INT: * RJH - 2017-01-25
case props::BOOL: * During multiplayer operations a series of crashes were encountered that affected all players
case props::LONG: * within range of each other and resulting in an exception being thrown at exactly the same moment in time
ival = (int) (0.5+(1-tau)*((double) (*prevPropIt)->int_value) + * (within case props::STRING: ref http://i.imgur.com/y6MBoXq.png)
tau*((double) (*nextPropIt)->int_value)); * Investigation showed that the nextPropIt and prevPropIt were pointing to different properties
pIt->second->setIntValue(ival); * which may be caused due to certain models that have overloaded mp property transmission and
//cout << "Int: " << ival << "\n"; * these craft have their properties truncated due to packet size. However the result of this
break; * will be different contents in the previous and current packets, so here we protect against
case props::FLOAT: * this by only considering properties where the previous and next id are the same.
case props::DOUBLE: * It might be a better solution to search the previous and next lists to locate the matching id's
val = (1-tau)*(*prevPropIt)->float_value + */
tau*(*nextPropIt)->float_value; if (*nextPropIt && (*nextPropIt)->id == (*prevPropIt)->id ) {
//cout << "Flo: " << val << "\n"; switch ((*prevPropIt)->type) {
pIt->second->setFloatValue(val); case props::INT:
break; case props::BOOL:
case props::STRING: case props::LONG:
case props::UNSPECIFIED: ival = (int)(0.5 + (1 - tau)*((double)(*prevPropIt)->int_value) +
//cout << "Str: " << (*nextPropIt)->string_value << "\n"; tau*((double)(*nextPropIt)->int_value));
pIt->second->setStringValue((*nextPropIt)->string_value); pIt->second->setIntValue(ival);
break; //cout << "Int: " << ival << "\n";
default: break;
// FIXME - currently defaults to float values case props::FLOAT:
val = (1-tau)*(*prevPropIt)->float_value + case props::DOUBLE:
tau*(*nextPropIt)->float_value; val = (1 - tau)*(*prevPropIt)->float_value +
//cout << "Unk: " << val << "\n"; tau*(*nextPropIt)->float_value;
pIt->second->setFloatValue(val); //cout << "Flo: " << val << "\n";
break; pIt->second->setFloatValue(val);
} break;
case props::STRING:
case props::UNSPECIFIED:
//cout << "Str: " << (*nextPropIt)->string_value << "\n";
pIt->second->setStringValue((*nextPropIt)->string_value);
break;
default:
// FIXME - currently defaults to float values
val = (1 - tau)*(*prevPropIt)->float_value +
tau*(*nextPropIt)->float_value;
//cout << "Unk: " << val << "\n";
pIt->second->setFloatValue(val);
break;
}
}
else
{
SG_LOG(SG_AI, SG_WARN, "MP packet mismatch during lag interpolation: " << (*prevPropIt)->id << " != " << (*nextPropIt)->id << "\n");
}
} }
else else
{ {