[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.
This commit is contained in:
Mario Zechner 2024-05-21 13:15:46 +02:00
parent dc577acc8d
commit 5abed8a7f6
2 changed files with 8 additions and 1 deletions

View File

@ -30,6 +30,7 @@
#pragma once
#include "SpineCommon.h"
#include "spine/Attachment.h"
#include <spine/spine.h>
class SpineSkeletonDataResource;
@ -46,4 +47,10 @@ public:
String get_attachment_name();
Ref<SpineAttachment> 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();
}
};

View File

@ -145,7 +145,7 @@ class SpineSkeletonDataResource;
template<typename OBJECT>
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);
}