Page MenuHome

Add nullptr checks in the depsgraph physics relation builder
ClosedPublic

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

Details

Summary

Without these check ASAN complains about null pointer member access.

Diff Detail

Repository
rB Blender

Event Timeline

Sebastian Parborg (zeddb) requested review of this revision.Wed, Sep 9, 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.

source/blender/depsgraph/intern/depsgraph_physics.cc
82–83

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.Wed, Sep 9, 4:15 PM