Depsgraph: Use C++ style of guarded allocation of objects
This commit is contained in:
@@ -158,14 +158,14 @@ DepsgraphBuilderCache::~DepsgraphBuilderCache()
|
||||
{
|
||||
for (AnimatedPropertyStorage *animated_property_storage :
|
||||
animated_property_storage_map_.values()) {
|
||||
OBJECT_GUARDED_DELETE(animated_property_storage, AnimatedPropertyStorage);
|
||||
delete animated_property_storage;
|
||||
}
|
||||
}
|
||||
|
||||
AnimatedPropertyStorage *DepsgraphBuilderCache::ensureAnimatedPropertyStorage(ID *id)
|
||||
{
|
||||
return animated_property_storage_map_.lookup_or_add_cb(
|
||||
id, []() { return OBJECT_GUARDED_NEW(AnimatedPropertyStorage); });
|
||||
id, []() { return new AnimatedPropertyStorage(); });
|
||||
}
|
||||
|
||||
AnimatedPropertyStorage *DepsgraphBuilderCache::ensureInitializedAnimatedPropertyStorage(ID *id)
|
||||
|
||||
@@ -23,6 +23,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "MEM_guardedalloc.h"
|
||||
|
||||
#include "intern/depsgraph_type.h"
|
||||
|
||||
#include "RNA_access.h"
|
||||
@@ -51,6 +53,8 @@ class AnimatedPropertyID {
|
||||
/* Corresponds to PointerRNA.data. */
|
||||
void *data;
|
||||
const PropertyRNA *property_rna;
|
||||
|
||||
MEM_CXX_CLASS_ALLOC_FUNCS("AnimatedPropertyID");
|
||||
};
|
||||
|
||||
class AnimatedPropertyStorage {
|
||||
@@ -70,6 +74,8 @@ class AnimatedPropertyStorage {
|
||||
|
||||
/* indexed by PointerRNA.data. */
|
||||
Set<AnimatedPropertyID> animated_properties_set;
|
||||
|
||||
MEM_CXX_CLASS_ALLOC_FUNCS("AnimatedPropertyStorage");
|
||||
};
|
||||
|
||||
/* Cached data which can be re-used by multiple builders. */
|
||||
@@ -98,6 +104,8 @@ class DepsgraphBuilderCache {
|
||||
}
|
||||
|
||||
Map<ID *, AnimatedPropertyStorage *> animated_property_storage_map_;
|
||||
|
||||
MEM_CXX_CLASS_ALLOC_FUNCS("DepsgraphBuilderCache");
|
||||
};
|
||||
|
||||
} // namespace deg
|
||||
|
||||
@@ -68,7 +68,7 @@ void deg_graph_remove_unused_noops(Depsgraph *graph)
|
||||
|
||||
/* Remove the relation. */
|
||||
rel_in->unlink();
|
||||
OBJECT_GUARDED_DELETE(rel_in, Relation);
|
||||
delete rel_in;
|
||||
num_removed_relations++;
|
||||
|
||||
/* Queue parent no-op node that has now become unused. */
|
||||
|
||||
@@ -102,7 +102,7 @@ void deg_graph_transitive_reduction(Depsgraph *graph)
|
||||
}
|
||||
for (Relation *rel : relations_to_remove) {
|
||||
rel->unlink();
|
||||
OBJECT_GUARDED_DELETE(rel, Relation);
|
||||
delete rel;
|
||||
}
|
||||
num_removed_relations += relations_to_remove.size();
|
||||
relations_to_remove.clear();
|
||||
|
||||
@@ -83,9 +83,7 @@ Depsgraph::Depsgraph(Main *bmain, Scene *scene, ViewLayer *view_layer, eEvaluati
|
||||
Depsgraph::~Depsgraph()
|
||||
{
|
||||
clear_id_nodes();
|
||||
if (time_source != nullptr) {
|
||||
OBJECT_GUARDED_DELETE(time_source, TimeSourceNode);
|
||||
}
|
||||
delete time_source;
|
||||
BLI_spin_end(&lock);
|
||||
}
|
||||
|
||||
@@ -157,7 +155,7 @@ void Depsgraph::clear_id_nodes()
|
||||
clear_id_nodes_conditional([](ID_Type id_type) { return id_type != ID_PA; });
|
||||
|
||||
for (IDNode *id_node : id_nodes) {
|
||||
OBJECT_GUARDED_DELETE(id_node, IDNode);
|
||||
delete id_node;
|
||||
}
|
||||
/* Clear containers. */
|
||||
id_hash.clear();
|
||||
@@ -188,7 +186,7 @@ Relation *Depsgraph::add_new_relation(Node *from, Node *to, const char *descript
|
||||
#endif
|
||||
|
||||
/* Create new relation, and add it to the graph. */
|
||||
rel = OBJECT_GUARDED_NEW(Relation, from, to, description);
|
||||
rel = new Relation(from, to, description);
|
||||
rel->flag |= flags;
|
||||
return rel;
|
||||
}
|
||||
@@ -229,10 +227,8 @@ void Depsgraph::add_entry_tag(OperationNode *node)
|
||||
void Depsgraph::clear_all_nodes()
|
||||
{
|
||||
clear_id_nodes();
|
||||
if (time_source != nullptr) {
|
||||
OBJECT_GUARDED_DELETE(time_source, TimeSourceNode);
|
||||
time_source = nullptr;
|
||||
}
|
||||
delete time_source;
|
||||
time_source = nullptr;
|
||||
}
|
||||
|
||||
ID *Depsgraph::get_cow_id(const ID *id_orig) const
|
||||
@@ -270,8 +266,7 @@ ID *Depsgraph::get_cow_id(const ID *id_orig) const
|
||||
/* Initialize a new Depsgraph */
|
||||
Depsgraph *DEG_graph_new(Main *bmain, Scene *scene, ViewLayer *view_layer, eEvaluationMode mode)
|
||||
{
|
||||
deg::Depsgraph *deg_depsgraph = OBJECT_GUARDED_NEW(
|
||||
deg::Depsgraph, bmain, scene, view_layer, mode);
|
||||
deg::Depsgraph *deg_depsgraph = new deg::Depsgraph(bmain, scene, view_layer, mode);
|
||||
deg::register_graph(deg_depsgraph);
|
||||
return reinterpret_cast<Depsgraph *>(deg_depsgraph);
|
||||
}
|
||||
@@ -308,7 +303,7 @@ void DEG_graph_free(Depsgraph *graph)
|
||||
using deg::Depsgraph;
|
||||
deg::Depsgraph *deg_depsgraph = reinterpret_cast<deg::Depsgraph *>(graph);
|
||||
deg::unregister_graph(deg_depsgraph);
|
||||
OBJECT_GUARDED_DELETE(deg_depsgraph, Depsgraph);
|
||||
delete deg_depsgraph;
|
||||
}
|
||||
|
||||
bool DEG_is_evaluating(const struct Depsgraph *depsgraph)
|
||||
|
||||
@@ -31,6 +31,8 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "MEM_guardedalloc.h"
|
||||
|
||||
#include "DNA_ID.h" /* for ID_Type */
|
||||
|
||||
#include "BKE_main.h" /* for MAX_LIBARRAY */
|
||||
@@ -168,6 +170,8 @@ struct Depsgraph {
|
||||
/* Cached list of colliders/effectors for collections and the scene
|
||||
* created along with relations, for fast lookup during evaluation. */
|
||||
Map<const ID *, ListBase *> *physics_relations[DEG_PHYSICS_RELATIONS_NUM];
|
||||
|
||||
MEM_CXX_CLASS_ALLOC_FUNCS("Depsgraph");
|
||||
};
|
||||
|
||||
} // namespace deg
|
||||
|
||||
@@ -23,6 +23,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "MEM_guardedalloc.h"
|
||||
|
||||
namespace blender {
|
||||
namespace deg {
|
||||
|
||||
@@ -59,6 +61,8 @@ struct Relation {
|
||||
/* relationship attributes */
|
||||
const char *name; /* label for debugging */
|
||||
int flag; /* Bitmask of RelationFlag) */
|
||||
|
||||
MEM_CXX_CLASS_ALLOC_FUNCS("Relation");
|
||||
};
|
||||
|
||||
} // namespace deg
|
||||
|
||||
@@ -302,7 +302,7 @@ Node::~Node()
|
||||
* when we're trying to free same link from both it's sides. We don't have
|
||||
* dangling links so this is not a problem from memory leaks point of view. */
|
||||
for (Relation *rel : inlinks) {
|
||||
OBJECT_GUARDED_DELETE(rel, Relation);
|
||||
delete rel;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -23,6 +23,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "MEM_guardedalloc.h"
|
||||
|
||||
#include "intern/depsgraph_type.h"
|
||||
|
||||
#include "BLI_utildefines.h"
|
||||
@@ -204,6 +206,8 @@ struct Node {
|
||||
}
|
||||
|
||||
virtual NodeClass get_class() const;
|
||||
|
||||
MEM_CXX_CLASS_ALLOC_FUNCS("Node");
|
||||
};
|
||||
|
||||
/* Macros for common static typeinfo. */
|
||||
|
||||
@@ -221,12 +221,12 @@ void ComponentNode::clear_operations()
|
||||
{
|
||||
if (operations_map != nullptr) {
|
||||
for (OperationNode *op_node : operations_map->values()) {
|
||||
OBJECT_GUARDED_DELETE(op_node, OperationNode);
|
||||
delete op_node;
|
||||
}
|
||||
operations_map->clear();
|
||||
}
|
||||
for (OperationNode *op_node : operations) {
|
||||
OBJECT_GUARDED_DELETE(op_node, OperationNode);
|
||||
delete op_node;
|
||||
}
|
||||
operations.clear();
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ Node *DepsNodeFactoryImpl<ModeObjectType>::create_node(const ID *id,
|
||||
const char *subdata,
|
||||
const char *name) const
|
||||
{
|
||||
Node *node = OBJECT_GUARDED_NEW(ModeObjectType);
|
||||
Node *node = new ModeObjectType();
|
||||
/* Populate base node settings. */
|
||||
node->type = type();
|
||||
/* Set name if provided, or use default type name. */
|
||||
|
||||
@@ -133,7 +133,7 @@ void IDNode::destroy()
|
||||
}
|
||||
|
||||
for (ComponentNode *comp_node : components.values()) {
|
||||
OBJECT_GUARDED_DELETE(comp_node, ComponentNode);
|
||||
delete comp_node;
|
||||
}
|
||||
|
||||
/* Free memory used by this CoW ID. */
|
||||
|
||||
Reference in New Issue
Block a user