diff --git a/lib/utils/temp-variable.cpp b/lib/utils/temp-variable.cpp index 2a7f26a4..dedb71fb 100644 --- a/lib/utils/temp-variable.cpp +++ b/lib/utils/temp-variable.cpp @@ -299,9 +299,17 @@ void TempVariableRef::Save(obs_data_t *obj, Macro *macro, obs_data_set_obj(obj, name, data); } -void TempVariableRef::Load(obs_data_t *obj, Macro *macro, const char *name) +void TempVariableRef::Load(obs_data_t *obj, Macro *macroPtr, const char *name) { - if (!macro) { + std::weak_ptr macro; + for (const auto ¯oShared : GetMacros()) { + if (macroShared.get() == macroPtr) { + macro = macroShared; + break; + } + } + + if (macro.expired()) { _segment.reset(); return; } @@ -324,10 +332,17 @@ void TempVariableRef::Load(obs_data_t *obj, Macro *macro, const char *name) }); } -void TempVariableRef::PostLoad(int idx, SegmentType type, Macro *macro) +void TempVariableRef::PostLoad(int idx, SegmentType type, + const std::weak_ptr &weakMacro) { + auto childMacro = weakMacro.lock(); + if (!childMacro) { + return; + } + + Macro *macro = nullptr; for (int i = 0; i < _depth; i++) { - macro = getParentMacro(macro); + macro = getParentMacro(childMacro.get()); } if (!macro) { diff --git a/lib/utils/temp-variable.hpp b/lib/utils/temp-variable.hpp index 5b7a19b1..43b0fccc 100644 --- a/lib/utils/temp-variable.hpp +++ b/lib/utils/temp-variable.hpp @@ -72,7 +72,7 @@ private: enum class SegmentType { NONE, CONDITION, ACTION, ELSEACTION }; SegmentType GetType() const; int GetIdx() const; - void PostLoad(int idx, SegmentType, Macro *); + void PostLoad(int idx, SegmentType, const std::weak_ptr &); std::string _id = ""; std::weak_ptr _segment;