From 5abed8a7f6b30f39937b5cb2316279cd81d76970 Mon Sep 17 00:00:00 2001 From: Mario Zechner Date: Tue, 21 May 2024 13:15:46 +0200 Subject: [PATCH] [godot] Closes #2489, fix reference count of SpineAttachments The SpineAttachment destructor would dereference the spine::Attachment. However, the set_spine_object() call doesn't increase the reference count. This can lead to the attachment being deallocated too early. --- spine-godot/spine_godot/SpineAttachment.h | 7 +++++++ spine-godot/spine_godot/SpineCommon.h | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/spine-godot/spine_godot/SpineAttachment.h b/spine-godot/spine_godot/SpineAttachment.h index e547319d1..9d711656c 100644 --- a/spine-godot/spine_godot/SpineAttachment.h +++ b/spine-godot/spine_godot/SpineAttachment.h @@ -30,6 +30,7 @@ #pragma once #include "SpineCommon.h" +#include "spine/Attachment.h" #include class SpineSkeletonDataResource; @@ -46,4 +47,10 @@ public: String get_attachment_name(); Ref copy(); + + void set_spine_object(const SpineSkeletonDataResource *_owner, spine::Attachment *_object) { + if (get_spine_object()) get_spine_object()->dereference(); + _set_spine_object_internal(_owner, _object); + if (_object) _object->reference(); + } }; diff --git a/spine-godot/spine_godot/SpineCommon.h b/spine-godot/spine_godot/SpineCommon.h index e09384e86..d7e2fe002 100644 --- a/spine-godot/spine_godot/SpineCommon.h +++ b/spine-godot/spine_godot/SpineCommon.h @@ -145,7 +145,7 @@ class SpineSkeletonDataResource; template class SpineSkeletonDataResourceOwnedObject : public SpineObjectWrapper { public: - void set_spine_object(const SpineSkeletonDataResource *_owner, OBJECT *_object) { + virtual void set_spine_object(const SpineSkeletonDataResource *_owner, OBJECT *_object) { _set_spine_object_internal(_owner, _object); }