From b9fb2f67786e6b99b18de0e66b4294aab3ec5406 Mon Sep 17 00:00:00 2001 From: HJfod <60038575+HJfod@users.noreply.github.com> Date: Sat, 16 Nov 2024 18:36:34 +0200 Subject: [PATCH] fix CCCallFuncExt --- loader/include/Geode/utils/cocos.hpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/loader/include/Geode/utils/cocos.hpp b/loader/include/Geode/utils/cocos.hpp index 6a7093ab..0e77a412 100644 --- a/loader/include/Geode/utils/cocos.hpp +++ b/loader/include/Geode/utils/cocos.hpp @@ -1331,15 +1331,13 @@ namespace geode::cocos { class CallFuncExtImpl : public cocos2d::CCActionInstant { public: static CallFuncExtImpl* create(const F& func) { - auto ret = new CallFuncExtImpl; - ret->m_func = func; + auto ret = new CallFuncExtImpl(func); ret->autorelease(); return ret; } static CallFuncExtImpl* create(F&& func) { - auto ret = new CallFuncExtImpl; - ret->m_func = std::move(func); + auto ret = new CallFuncExtImpl(std::move(func)); ret->autorelease(); return ret; } @@ -1347,8 +1345,17 @@ namespace geode::cocos { private: F m_func; + // F may not be default-constructible + CallFuncExtImpl(F&& func) : m_func(std::move(func)) {} + CallFuncExtImpl(F const& func) : m_func(func) {} + void update(float) override { - if (m_func) this->m_func(); + // Make sure any `std::function`s are valid + if constexpr (requires { static_cast(m_func); }) { + if (m_func) m_func(); + } else { + m_func(); + } } };