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.
This commit is contained in:
Bastien Montagne 2022-04-29 17:56:08 +02:00
parent 3c7a6718dd
commit 1a8a69d318
1 changed files with 6 additions and 4 deletions

View File

@ -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));