From de9fedb4b486b1bd0107846f88946d97c81441f5 Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Sat, 24 May 2014 19:00:25 -0400 Subject: [PATCH 1/2] 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. --- .../Plasma/FeatureLib/pfPython/cyAvatar.cpp | 41 +++++-------------- 1 file changed, 10 insertions(+), 31 deletions(-) diff --git a/Sources/Plasma/FeatureLib/pfPython/cyAvatar.cpp b/Sources/Plasma/FeatureLib/pfPython/cyAvatar.cpp index 95aac6c8..72194979 100644 --- a/Sources/Plasma/FeatureLib/pfPython/cyAvatar.cpp +++ b/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; ifPlayerKey = (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 ) From 83b8f6c10ba3608feff03dff58099fe16f8b8190 Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Sat, 24 May 2014 19:16:02 -0400 Subject: [PATCH 2/2] Fix invalid sizeof expressions in HeadSpin.cpp --- Sources/Plasma/CoreLib/HeadSpin.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/Plasma/CoreLib/HeadSpin.cpp b/Sources/Plasma/CoreLib/HeadSpin.cpp index 580b6d6c..0b218d0c 100644 --- a/Sources/Plasma/CoreLib/HeadSpin.cpp +++ b/Sources/Plasma/CoreLib/HeadSpin.cpp @@ -118,7 +118,7 @@ void ErrorAssert(int line, const char* file, const char* fmt, ...) char msg[1024]; va_list args; va_start(args, fmt); - vsnprintf(msg, sizeof(msg), fmt, args); + vsnprintf(msg, arrsize(msg), fmt, args); #ifdef HS_DEBUGGING if (s_GuiAsserts) { @@ -163,7 +163,7 @@ void DebugMsg(const char* fmt, ...) char msg[1024]; va_list args; va_start(args, fmt); - vsnprintf(msg, sizeof(msg), fmt, args); + vsnprintf(msg, arrsize(msg), fmt, args); if (DebugIsDebuggerPresent()) {