Page MenuHome

Add nullptr checks in the depsgraph physics relation builder

Authored by Sebastian Parborg (zeddb) on Sep 9 2020, 3:13 PM.



Without these check ASAN complains about null pointer member access.

Diff Detail

rB Blender

Event Timeline

Sebastian Parborg (zeddb) requested review of this revision.Sep 9 2020, 3:13 PM
Sebastian Parborg (zeddb) created this revision.

Generally fine.

One possible improvement to avoid ternary operators in many places is to do something like this:

// Get ID from an ID type object, in a safe manner. This means that object can be nullptr,
// in which case the function returns nullptr.
template<class T>
ID *object_id_safe(T *object) {
  if (object == nullptr) {
    return nullptr;
  return &object->id;

And use this in all places where collection can be nullptr.


I would add a comment here that nullptr is the valid key. Will avoid temptation to use early output.

On an unrelated topic: seems that lookup deg_graph->physics_relations[DEG_PHYSICS_EFFECTOR] happens twice here, which is redundant.

Sebastian Parborg (zeddb) marked an inline comment as done.

From quick glance seems fine.

This revision is now accepted and ready to land.Sep 9 2020, 4:15 PM