[Bf-blender-cvs] [1a8a69d3187] master: Cleanup: Fix harmless runtime error about null pointer in Outliner tree code.

Bastien Montagne noreply at git.blender.org
Fri Apr 29 17:57:52 CEST 2022


Commit: 1a8a69d3187fe513b34c8e31749fa1219750cff4
Author: Bastien Montagne
Date:   Fri Apr 29 17:56:08 2022 +0200
Branches: master
https://developer.blender.org/rB1a8a69d3187fe513b34c8e31749fa1219750cff4

Cleanup: Fix harmless runtime error about null pointer in Outliner tree code.

While the reference would never be used in case of NULL pointer, this
bit of code was not really clear and nice, so make it less ambiguous
now. Also add early return in case a NULL idv pointeris actually passed.

===================================================================

M	source/blender/editors/space_outliner/tree/tree_element.cc

===================================================================

diff --git a/source/blender/editors/space_outliner/tree/tree_element.cc b/source/blender/editors/space_outliner/tree/tree_element.cc
index 7fe3f08b3be..1e3fd2df7c2 100644
--- a/source/blender/editors/space_outliner/tree/tree_element.cc
+++ b/source/blender/editors/space_outliner/tree/tree_element.cc
@@ -33,7 +33,9 @@ std::unique_ptr<AbstractTreeElement> AbstractTreeElement::createFromType(const i
                                                                          TreeElement &legacy_te,
                                                                          void *idv)
 {
-  ID &id = *static_cast<ID *>(idv);
+  if (idv == nullptr) {
+    return nullptr;
+  }
 
   /*
    * The following calls make an implicit assumption about what data was passed to the `idv`
@@ -49,10 +51,10 @@ std::unique_ptr<AbstractTreeElement> AbstractTreeElement::createFromType(const i
 
   switch (type) {
     case TSE_SOME_ID:
-      return TreeElementID::createFromID(legacy_te, id);
+      return TreeElementID::createFromID(legacy_te, *static_cast<ID *>(idv));
     case TSE_ANIM_DATA:
       return std::make_unique<TreeElementAnimData>(legacy_te,
-                                                   *reinterpret_cast<IdAdtTemplate &>(id).adt);
+                                                   *reinterpret_cast<IdAdtTemplate *>(idv)->adt);
     case TSE_DRIVER_BASE:
       return std::make_unique<TreeElementDriverBase>(legacy_te, *static_cast<AnimData *>(idv));
     case TSE_NLA:
@@ -70,7 +72,7 @@ std::unique_ptr<AbstractTreeElement> AbstractTreeElement::createFromType(const i
     case TSE_SCENE_OBJECTS_BASE:
       return std::make_unique<TreeElementSceneObjectsBase>(legacy_te, *static_cast<Scene *>(idv));
     case TSE_LIBRARY_OVERRIDE_BASE:
-      return std::make_unique<TreeElementOverridesBase>(legacy_te, id);
+      return std::make_unique<TreeElementOverridesBase>(legacy_te, *static_cast<ID *>(idv));
     case TSE_LIBRARY_OVERRIDE:
       return std::make_unique<TreeElementOverridesProperty>(
           legacy_te, *static_cast<TreeElementOverridesData *>(idv));



More information about the Bf-blender-cvs mailing list