diff --git a/lib/base/defer.hpp b/lib/base/defer.hpp index 9290c92b9..2a232619a 100644 --- a/lib/base/defer.hpp +++ b/lib/base/defer.hpp @@ -30,13 +30,21 @@ public: inline ~Defer() { - try { - m_Func(); - } catch (...) { - // https://stackoverflow.com/questions/130117/throwing-exceptions-out-of-a-destructor + if (m_Func) { + try { + m_Func(); + } catch (...) { + // https://stackoverflow.com/questions/130117/throwing-exceptions-out-of-a-destructor + } } } + inline + void Cancel() + { + m_Func = nullptr; + } + private: std::function m_Func; };