mirror of
https://github.com/vcmi/vcmi.git
synced 2025-03-31 22:05:10 +02:00
CTypeList: Apply changes from a50a32405de5c76f8876e5f479425f71d8e04c73
Use weak_ptr for TypeDescriptor cross-links. Fixed total TypeDescriptor memory leak.
This commit is contained in:
parent
5b76c3f4eb
commit
8f349b5105
@ -62,8 +62,9 @@ std::vector<CTypeList::TypeInfoPtr> CTypeList::castSequence(TypeInfoPtr from, Ty
|
|||||||
{
|
{
|
||||||
auto typeNode = q.front();
|
auto typeNode = q.front();
|
||||||
q.pop();
|
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))
|
if(!previous.count(nodeBase))
|
||||||
{
|
{
|
||||||
previous[nodeBase] = typeNode;
|
previous[nodeBase] = typeNode;
|
||||||
|
@ -66,11 +66,12 @@ class DLL_LINKAGE CTypeList: public boost::noncopyable
|
|||||||
//public:
|
//public:
|
||||||
struct TypeDescriptor;
|
struct TypeDescriptor;
|
||||||
typedef std::shared_ptr<TypeDescriptor> TypeInfoPtr;
|
typedef std::shared_ptr<TypeDescriptor> TypeInfoPtr;
|
||||||
|
typedef std::weak_ptr<TypeDescriptor> WeakTypeInfoPtr;
|
||||||
struct TypeDescriptor
|
struct TypeDescriptor
|
||||||
{
|
{
|
||||||
ui16 typeID;
|
ui16 typeID;
|
||||||
const char *name;
|
const char *name;
|
||||||
std::vector<TypeInfoPtr> children, parents;
|
std::vector<WeakTypeInfoPtr> children, parents;
|
||||||
};
|
};
|
||||||
typedef boost::shared_mutex TMutex;
|
typedef boost::shared_mutex TMutex;
|
||||||
typedef boost::unique_lock<TMutex> TUniqueLock;
|
typedef boost::unique_lock<TMutex> TUniqueLock;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user