Fix memory leaks in CollectionObject by making ob a weak pointer and removing prev pointer.

Something was cyclic in CollectionObject and we don't traverse backwards anyways
pull/4193/head
Pencil Amazing 2021-11-26 15:41:50 -04:00
parent e831ecf3c2
commit 095bd67e10
3 changed files with 23 additions and 13 deletions

View File

@ -325,7 +325,7 @@ void BlenderImporter::ParseSubCollection(const Blender::Scene &in, aiNode *root,
// Count number of objects
for (std::shared_ptr<CollectionObject> cur = std::static_pointer_cast<CollectionObject>(collection->gobject.first); cur; cur = cur->next) {
if (cur->ob) {
root_objects.push_back(cur->ob.get());
root_objects.push_back(cur->ob);
}
}
std::deque<Collection *> root_children;

View File

@ -100,9 +100,18 @@ void Structure::Convert<CollectionObject>(
CollectionObject &dest,
const FileDatabase &db) const {
ReadFieldPtr<ErrorPolicy_Fail>(dest.prev, "*prev", db);
ReadFieldPtr<ErrorPolicy_Fail>(dest.next, "*next", db);
ReadFieldPtr<ErrorPolicy_Igno>(dest.ob, "*ob", db);
{
//std::shared_ptr<CollectionObject> prev;
//ReadFieldPtr<ErrorPolicy_Fail>(prev, "*prev", db);
//dest.prev = prev.get();
std::shared_ptr<Object> ob;
ReadFieldPtr<ErrorPolicy_Igno>(ob, "*ob", db);
dest.ob = ob.get();
}
db.reader->IncPtr(size);
}
//--------------------------------------------------------------------------------

View File

@ -107,6 +107,7 @@ namespace Blender {
struct Object;
struct MTex;
struct Image;
struct Collection;
#include <memory>
@ -147,18 +148,11 @@ struct Group : ElemBase {
std::shared_ptr<GroupObject> gobject;
};
// -------------------------------------------------------------------------------
struct Collection : ElemBase {
ID id FAIL;
ListBase gobject; // CollectionObject
ListBase children; // CollectionChild
//ListBase objects; // Objects
};
// -------------------------------------------------------------------------------
struct CollectionObject : ElemBase {
std::shared_ptr<CollectionObject> next, prev;
std::shared_ptr<Object> ob;
//CollectionObject* prev;
std::shared_ptr<CollectionObject> next;
Object *ob;
};
// -------------------------------------------------------------------------------
@ -167,6 +161,13 @@ struct CollectionChild : ElemBase {
std::shared_ptr<Collection> collection;
};
// -------------------------------------------------------------------------------
struct Collection : ElemBase {
ID id FAIL;
ListBase gobject; // CollectionObject
ListBase children; // CollectionChild
};
// -------------------------------------------------------------------------------
struct World : ElemBase {
ID id FAIL;