Browse Source

Fix message ref-counting in cyAvatar::RunBehavior

This was potential memory leak AND crash bug, all in one nasty package. I
included a little bit of code cleanup free-of-charge.
Adam Johnson 10 years ago
parent
commit
de9fedb4b4
  1. 41
      Sources/Plasma/FeatureLib/pfPython/cyAvatar.cpp

41
Sources/Plasma/FeatureLib/pfPython/cyAvatar.cpp

@ -215,47 +215,26 @@ void cyAvatar::OneShot(pyKey &seekKey, float duration, bool usePhysics,
void cyAvatar::RunBehavior(pyKey &behKey, bool netForce, bool netProp)
{
// first there is someone to send to and make sure that we an avatar to send this to
if ( behKey.getKey() != nil && fRecvr.Count() > 0)
if ( behKey.getKey() && fRecvr.Count() > 0)
{
// must determine if the behKey is pointing to Single or Multi Shot behavior
if ( plOneShotMod::ConvertNoRef(behKey.getKey()->GetObjectPtr()) != nil )
if (plOneShotMod::ConvertNoRef(behKey.getKey()->GetObjectPtr()))
{
// create a message OneShotMessage
plOneShotMsg* pMsg = new plOneShotMsg;
// check if this needs to be network forced to all clients
if (netProp)
{
pMsg->SetBCastFlag(plMessage::kNetPropagate);
}
else
{
pMsg->SetBCastFlag(plMessage::kNetPropagate, false);
}
if (netForce)
{
// set the network propagate flag to make sure it gets to the other clients
pMsg->SetBCastFlag(plMessage::kNetPropagate);
pMsg->SetBCastFlag(plMessage::kNetForce);
}
else
{
pMsg->SetBCastFlag(plMessage::kNetForce, false);
}
pMsg->SetBCastFlag(plMessage::kNetPropagate, netProp || netForce);
pMsg->SetBCastFlag(plMessage::kNetForce, netForce);
pMsg->SetSender(fSender);
pMsg->AddReceiver(behKey.getKey());
int i;
for ( i=0; i<fRecvr.Count(); i++ )
{
for (int i = 0; i < fRecvr.Count(); i++) {
// make sure there is an avatar to set
if ( fRecvr[i] != nil )
{
pMsg->fPlayerKey = (plKey)fRecvr[i];
plgDispatch::MsgSend( pMsg ); // send off command for each valid avatar we find
// ... really, should only be one... though
if (fRecvr[i]) {
pMsg->fPlayerKey = fRecvr[i];
pMsg->SendAndKeep(); // gotta keep the message so we can keep sending it
// there should really only be one avatar, though...
}
}
pMsg->UnRef(); // done with our reference
}
// else if it is a Multistage guy
else if ( plMultistageBehMod::ConvertNoRef(behKey.getKey()->GetObjectPtr()) != nil )

Loading…
Cancel
Save