From d11d4738d4647bb1cfe04affc8a3864bc1108bc4 Mon Sep 17 00:00:00 2001 From: kervala Date: Sat, 30 Jan 2016 18:01:27 +0100 Subject: [PATCH] Fixed: AIS crash if variable not initialized (a big thanks to depyraken to finding it) --- .../server/src/ai_service/state_instance.h | 34 +++++++++---------- 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/code/ryzom/server/src/ai_service/state_instance.h b/code/ryzom/server/src/ai_service/state_instance.h index 802172825..f8bacd31f 100644 --- a/code/ryzom/server/src/ai_service/state_instance.h +++ b/code/ryzom/server/src/ai_service/state_instance.h @@ -376,17 +376,16 @@ inline float CStateInstance::getNelVar(std::string const& varId) { TNelVarList::iterator it = _NelVar.find(varId); - if (it==_NelVar.end()) + if (it != _NelVar.end()) return it->second->get() + + if (NLMISC::CVariable::exists(varId)) { - if (NLMISC::CVariable::exists(varId)) - { - nlwarning("Nel variable \"%s\" exists outside of this state instance", varId.c_str()); - return 0.f; - } - _NelVar[varId] = new NLMISC::CVariable("StateInstance", varId.c_str(), "", 0.f); - _NelVar[varId]->get(); + nlwarning("Nel variable \"%s\" exists outside of this state instance", varId.c_str()); + return 0.f; } - return it->second->get(); + + _NelVar[varId] = new NLMISC::CVariable("StateInstance", varId.c_str(), "", 0.f); + return _NelVar[varId]->get(); } inline @@ -424,17 +423,16 @@ inline std::string CStateInstance::getStrNelVar(std::string const& varId) { TStrNelVarList::iterator it = _StrNelVar.find(varId); - if (it==_StrNelVar.end()) + if (it!=_StrNelVar.end()) return it->second->get(); + + if (NLMISC::CVariable::exists(varId)) { - if (NLMISC::CVariable::exists(varId)) - { - nlwarning("Nel variable \"%s\" exists outside of this state instance", varId.c_str()); - return ""; - } - _StrNelVar[varId] = new NLMISC::CVariable("StateInstanceVar", varId.c_str(), "", std::string()); - _NelVar[varId]->get(); + nlwarning("Nel variable \"%s\" exists outside of this state instance", varId.c_str()); + return ""; } - return it->second->get(); + + _StrNelVar[varId] = new NLMISC::CVariable("StateInstanceVar", varId.c_str(), "", std::string()); + return _NelVar[varId]->get(); } inline