diff options
author | Bastien Montagne <bastien@blender.org> | 2022-04-29 18:56:08 +0300 |
---|---|---|
committer | Bastien Montagne <bastien@blender.org> | 2022-04-29 18:57:46 +0300 |
commit | 1a8a69d3187fe513b34c8e31749fa1219750cff4 (patch) | |
tree | 02e0117948029416d5366f402e8c9981e57d03dd /source/blender | |
parent | 3c7a6718ddc52fbf2a6a8d57822007738699fe96 (diff) |
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.
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/editors/space_outliner/tree/tree_element.cc | 10 |
1 files changed, 6 insertions, 4 deletions
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)); |