1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

CTypeList: Apply changes from a50a32405d

Use weak_ptr for TypeDescriptor cross-links. Fixed total TypeDescriptor memory leak.
This commit is contained in:
AlexVinS 2016-09-10 04:23:13 +03:00 committed by Arseniy Shestakov
parent 5b76c3f4eb
commit 8f349b5105
2 changed files with 4 additions and 2 deletions

View File

@ -62,8 +62,9 @@ std::vector<CTypeList::TypeInfoPtr> CTypeList::castSequence(TypeInfoPtr from, Ty
{
auto typeNode = q.front();
q.pop();
for(auto &nodeBase : upcast ? typeNode->parents : typeNode->children)
for(auto & weakNode : (upcast ? typeNode->parents : typeNode->children) )
{
auto nodeBase = weakNode.lock();
if(!previous.count(nodeBase))
{
previous[nodeBase] = typeNode;

View File

@ -66,11 +66,12 @@ class DLL_LINKAGE CTypeList: public boost::noncopyable
//public:
struct TypeDescriptor;
typedef std::shared_ptr<TypeDescriptor> TypeInfoPtr;
typedef std::weak_ptr<TypeDescriptor> WeakTypeInfoPtr;
struct TypeDescriptor
{
ui16 typeID;
const char *name;
std::vector<TypeInfoPtr> children, parents;
std::vector<WeakTypeInfoPtr> children, parents;
};
typedef boost::shared_mutex TMutex;
typedef boost::unique_lock<TMutex> TUniqueLock;