diff --git a/loader/include/Geode/cocos/base_nodes/Layout.hpp b/loader/include/Geode/cocos/base_nodes/Layout.hpp index d47ab470..fbc5272b 100644 --- a/loader/include/Geode/cocos/base_nodes/Layout.hpp +++ b/loader/include/Geode/cocos/base_nodes/Layout.hpp @@ -48,7 +48,7 @@ public: virtual ~Layout() = default; }; -class GEODE_DLL LayoutOptions { +class GEODE_DLL LayoutOptions : public CCObject { public: virtual ~LayoutOptions() = default; }; @@ -344,9 +344,7 @@ protected: public: /** - * Create a new RowLayout. Note that this class is not automatically - * managed by default, so you must assign it to a CCNode or manually - * manage the memory yourself. See the chainable setters on RowLayout for + * Create a new RowLayout. See the chainable setters on RowLayout for * what options you can customize for the layout * @returns Created RowLayout */ @@ -362,9 +360,7 @@ protected: public: /** - * Create a new ColumnLayout. Note that this class is not automatically - * managed by default, so you must assign it to a CCNode or manually - * manage the memory yourself. See the chainable setters on RowLayout for + * Create a new ColumnLayout. See the chainable setters on RowLayout for * what options you can customize for the layout * @returns Created ColumnLayout */ diff --git a/loader/src/cocos2d-ext/AnchorLayout.cpp b/loader/src/cocos2d-ext/AnchorLayout.cpp index ddb953e7..e1e7f4ab 100644 --- a/loader/src/cocos2d-ext/AnchorLayout.cpp +++ b/loader/src/cocos2d-ext/AnchorLayout.cpp @@ -8,7 +8,9 @@ using namespace geode::prelude; AnchorLayoutOptions* AnchorLayoutOptions::create() { - return new AnchorLayoutOptions(); + auto ret = new AnchorLayoutOptions(); + ret->autorelease(); + return ret; } Anchor AnchorLayoutOptions::getAnchor() const { diff --git a/loader/src/cocos2d-ext/AxisLayout.cpp b/loader/src/cocos2d-ext/AxisLayout.cpp index 6c0cb22c..36ff6821 100644 --- a/loader/src/cocos2d-ext/AxisLayout.cpp +++ b/loader/src/cocos2d-ext/AxisLayout.cpp @@ -908,7 +908,9 @@ ColumnLayout* ColumnLayout::create() { // AxisLayoutOptions AxisLayoutOptions* AxisLayoutOptions::create() { - return new AxisLayoutOptions(); + auto ret = new AxisLayoutOptions(); + ret->autorelease(); + return ret; } std::optional<bool> AxisLayoutOptions::getAutoScale() const { diff --git a/loader/src/hooks/GeodeNodeMetadata.cpp b/loader/src/hooks/GeodeNodeMetadata.cpp index 9ff19e5b..13acbf69 100644 --- a/loader/src/hooks/GeodeNodeMetadata.cpp +++ b/loader/src/hooks/GeodeNodeMetadata.cpp @@ -20,7 +20,7 @@ private: Ref<cocos2d::CCObject> m_userObject; std::string m_id = ""; Ref<Layout> m_layout = nullptr; - std::unique_ptr<LayoutOptions> m_layoutOptions = nullptr; + Ref<LayoutOptions> m_layoutOptions = nullptr; std::unordered_map<std::string, matjson::Value> m_attributes; std::unordered_set<std::unique_ptr<EventListenerProtocol>> m_eventListeners; std::unordered_map<std::string, std::unique_ptr<EventListenerProtocol>> m_idEventListeners; @@ -147,14 +147,14 @@ Layout* CCNode::getLayout() { } void CCNode::setLayoutOptions(LayoutOptions* options, bool apply) { - GeodeNodeMetadata::set(this)->m_layoutOptions.reset(options); + GeodeNodeMetadata::set(this)->m_layoutOptions = options; if (apply && m_pParent) { m_pParent->updateLayout(); } } LayoutOptions* CCNode::getLayoutOptions() { - return GeodeNodeMetadata::set(this)->m_layoutOptions.get(); + return GeodeNodeMetadata::set(this)->m_layoutOptions.data(); } void CCNode::updateLayout(bool updateChildOrder) {