Page MenuHome
Paste P1529

Snippet for D8230
ActivePublic

Authored by Sergey Sharybin (sergey) on Jul 13 2020, 4:41 PM.
BL::Depsgraph::object_instances_iterator b_instance_iter;
for (b_depsgraph.object_instances.begin(b_instance_iter);
b_instance_iter != b_depsgraph.object_instances.end() && !cancel;
++b_instance_iter) {
BL::DepsgraphObjectInstance b_instance = *b_instance_iter;
// NOTE: This is potentially an object which is constructed in-place, in the
// iterator memory. It must be treated in a way that it becomes invalid after
// `++b_instance_iter`.
//
// Use this object to access all instance-specific settings, such as:
//
// - World transform
// - Persistent ID
// - All the rest what Cycles need from the instance.
//
// Do NOT use this object outside of this loop iteration.
BL::Object b_temp_object = b_instance.object();
// The b_accessible_object points to an actual ID from the dependency graph.
// It can be passed to the underlying calls, so that it is possible to get
// access to the following fields:
//
// - Object type
// - Object name
// - Modifiers and constraints
// - Object data (BL::Object::data, aka BL::Mesh and others)
//
// NOTE: This object will be valid after ++b_instance_iter, and hence can be
// used from callbacks used by threaded synchronization.
//
// NOTE: b_accessible_object.data() and b_temp_object.data() are the same
// pointers
BL::Object b_accessible_object(PointerRNA_NULL);
if (b_instance.is_instance()) {
// NOTE: instance_object is a real object from the dependency graph, but it
// does not have instance transform (hence transform is to be acquired
// differently).
b_accessible_object.b_object = b_instance.instance_object();
} else {
// NOTE: Non-instanced objects points to real object in the dependency,
// (as opposite to the instance case when object is a temporary copy with
// some fields overwritten).
b_accessible_object.b_object = b_instance.object();
}
}

Event Timeline

Sergey Sharybin (sergey) created this object with edit policy "Administrators".
Sergey Sharybin (sergey) updated the paste's language from autodetect to cpp.

What does it mean if b_accessible_object.data() return NULL? I get a crash when there's a check to see if it's a mesh when I'm running this multi-threaded.

Hi Sergey, I think something's wrong with the definition of b_accessible_object. Accessing the data() function in my sync function keeps crashing, which makes me think the data underneath's been invalidated. This makes sense given your comment about how b_accessible_object.data() and b_temp_object.data() both point to the same thing, but then how can I make sure it's not being invalidated?