# Blender: fix memory leaking due to cycle refs. Thanks to Vitalii Trubchaninov for pointing this out.

git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@1230 67173fc5-114c-0410-ac8e-9d2fd5bffc1f
pull/5/head
aramis_acg 2012-03-27 22:09:09 +00:00
parent 6caf98d945
commit 07841c3e13
5 changed files with 49 additions and 21 deletions

View File

@ -881,7 +881,7 @@ aiNode* BlenderImporter::ConvertNode(const Scene& in, const Object* obj, Convers
std::deque<const Object*> children;
for(std::set<const Object*>::iterator it = conv_data.objects.begin(); it != conv_data.objects.end() ;) {
const Object* object = *it;
if (object->parent.get() == obj) {
if (object->parent == obj) {
children.push_back(object);
conv_data.objects.erase(it++);

View File

@ -1,8 +1,8 @@
/*
Open Asset Import Library (assimp)
Open Asset Import Library (ASSIMP)
----------------------------------------------------------------------
Copyright (c) 2006-2012, assimp team
Copyright (c) 2006-2010, ASSIMP Development Team
All rights reserved.
Redistribution and use of this software in source and binary forms,
@ -18,10 +18,10 @@ following conditions are met:
following disclaimer in the documentation and/or other
materials provided with the distribution.
* Neither the name of the assimp team, nor the names of its
* Neither the name of the ASSIMP team, nor the names of its
contributors may be used to endorse or promote products
derived from this software without specific prior
written permission of the assimp team.
written permission of the ASSIMP Development Team.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
@ -63,7 +63,11 @@ template <> void Structure :: Convert<Object> (
ReadFieldArray2<ErrorPolicy_Warn>(dest.obmat,"obmat",db);
ReadFieldArray2<ErrorPolicy_Warn>(dest.parentinv,"parentinv",db);
ReadFieldArray<ErrorPolicy_Warn>(dest.parsubstr,"parsubstr",db);
ReadFieldPtr<ErrorPolicy_Warn>(dest.parent,"*parent",db);
{
boost::shared_ptr<Object> parent;
ReadFieldPtr<ErrorPolicy_Warn>(parent,"*parent",db);
dest.parent = parent.get();
}
ReadFieldPtr<ErrorPolicy_Warn>(dest.track,"*track",db);
ReadFieldPtr<ErrorPolicy_Warn>(dest.proxy,"*proxy",db);
ReadFieldPtr<ErrorPolicy_Warn>(dest.proxy_from,"*proxy_from",db);
@ -238,7 +242,11 @@ template <> void Structure :: Convert<Base> (
) const
{
ReadFieldPtr<ErrorPolicy_Warn>(dest.prev,"*prev",db);
{
boost::shared_ptr<Base> prev;
ReadFieldPtr<ErrorPolicy_Warn>(prev,"*prev",db);
dest.prev = prev.get();
}
ReadFieldPtr<ErrorPolicy_Warn>(dest.next,"*next",db);
ReadFieldPtr<ErrorPolicy_Warn>(dest.object,"*object",db);

View File

@ -71,9 +71,10 @@ namespace Assimp {
//
// * Pointers to other structures or primitive types are allowed.
// No references or double pointers or arrays of pointers.
// A pointer to a T is written as boost::shared_ptr, while a
// A pointer to a T is normally written as boost::shared_ptr, while a
// pointer to an array of elements is written as boost::
// shared_array.
// shared_array. To avoid cyclic pointers, use raw pointers in
// one direction.
//
// * Arrays can have maximally two-dimensions. Any non-pointer
// type can form them.
@ -477,7 +478,7 @@ struct Object : ElemBase {
float parentinv[4][4] WARN;
char parsubstr[32] WARN;
boost::shared_ptr<Object> parent WARN;
Object* parent WARN;
boost::shared_ptr<Object> track WARN;
boost::shared_ptr<Object> proxy,proxy_from,proxy_group WARN;
@ -490,7 +491,7 @@ struct Object : ElemBase {
// -------------------------------------------------------------------------------
struct Base : ElemBase {
boost::shared_ptr<Base> prev WARN;
Base* prev WARN;
boost::shared_ptr<Base> next WARN;
boost::shared_ptr<Object> object WARN;
};

View File

@ -1,8 +1,8 @@
/*
Open Asset Import Library (assimp)
Open Asset Import Library (ASSIMP)
----------------------------------------------------------------------
Copyright (c) 2006-2012, assimp team
Copyright (c) 2006-2010, ASSIMP Development Team
All rights reserved.
Redistribution and use of this software in source and binary forms,
@ -18,10 +18,10 @@ following conditions are met:
following disclaimer in the documentation and/or other
materials provided with the distribution.
* Neither the name of the assimp team, nor the names of its
* Neither the name of the ASSIMP team, nor the names of its
contributors may be used to endorse or promote products
derived from this software without specific prior
written permission of the assimp team.
written permission of the ASSIMP Development Team.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT

View File

@ -67,6 +67,13 @@ template <> void Structure :: Convert<{a}> (
Structure_Convert_ptrdecl = """
ReadFieldPtr<{policy}>({destcast}dest.{name_canonical},"{name_dna}",db);"""
Structure_Convert_rawptrdecl = """
{{
boost::shared_ptr<{type}> {name_canonical};
ReadFieldPtr<{policy}>({destcast}{name_canonical},"{name_dna}",db);
dest.{name_canonical} = {name_canonical}.get();
}}"""
Structure_Convert_arraydecl = """
ReadFieldArray<{policy}>({destcast}dest.{name_canonical},"{name_dna}",db);"""
@ -103,11 +110,12 @@ def main():
getstruct = re.compile(r"struct\s+(\w+?)\s*(:\s*ElemBase)?\s*\{(.*?)^\}\s*;",flags)
getsmartx = re.compile(r"(std\s*::\s*)?(vector)\s*<\s*(boost\s*::\s*)?shared_(ptr)\s*<\s*(\w+)\s*>\s*>\s*",flags)
getsmartp = re.compile(r"(boost\s*::\s*)?shared_(ptr)\s*<\s*(\w+)\s*>\s*",flags)
getrawp = re.compile(r"(\w+)\s*\*\s*",flags)
getsmarta = re.compile(r"(std\s*::\s*)?(vector)\s*<\s*(\w+)\s*>\s*",flags)
getpolicy = re.compile(r"\s*(WARN|FAIL|IGNO)",flags)
stripenum = re.compile(r"enum\s+(\w+)\s*{.*?\}\s*;",flags)
assert getsmartx and getsmartp and getsmarta and getpolicy and stripenum
assert getsmartx and getsmartp and getsmarta and getrawp and getpolicy and stripenum
enums = set()
#re.sub(stripcoms," ",input)
@ -146,14 +154,20 @@ def main():
policy = py.groups()[0]
line = re.sub(getpolicy,"",line)
ty = re.match(getsmartx,line) or re.match(getsmartp,line) or re.match(getsmarta,line)
ty = re.match(getsmartx,line) or re.match(getsmartp,line) or\
re.match(getsmarta,line) or re.match(getrawp,line)
if ty is None:
ty = line.split(None,1)[0]
else:
if ty.groups()[1] == "ptr":
if len(ty.groups()) == 1:
ty = ty.groups()[-1] + "$"
elif ty.groups()[1] == "ptr":
ty = ty.groups()[2] + "*"
elif ty.groups()[1] == "vector":
ty = ty.groups()[-1] + ("*" if len(ty.groups()) == 3 else "**")
else:
assert False
#print(line)
sp = line.split(',')
@ -190,7 +204,9 @@ def main():
splits = name.split("[",1)
name_canonical = splits[0]
#array_part = "" if len(splits)==1 else "["+splits[1]
ptr_decl = "*"*type.count("*")
is_raw_ptr = not not type.count("$")
ptr_decl = "*"*(type.count("*") + (1 if is_raw_ptr else 0))
name_dna = ptr_decl+name_canonical #+array_part
#required = "false"
@ -198,7 +214,10 @@ def main():
destcast = "(int&)" if type in enums else ""
# POINTER
if ptr_decl:
if is_raw_ptr:
type = type.replace('$','')
s += Structure_Convert_rawptrdecl.format(**locals())
elif ptr_decl:
s += Structure_Convert_ptrdecl.format(**locals())
# ARRAY MEMBER
elif name.count('[')==1: