From d62ef5606618999a6b11eb04605f2c7a47148e0d Mon Sep 17 00:00:00 2001 From: badlogic Date: Tue, 12 Apr 2022 12:04:49 +0200 Subject: [PATCH] [godot] Clean-up SpineAttachment, perform checks on native object. --- spine-godot/spine_godot/SpineAttachment.cpp | 24 +++++++++++---------- spine-godot/spine_godot/SpineAttachment.h | 15 ++++++------- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/spine-godot/spine_godot/SpineAttachment.cpp b/spine-godot/spine_godot/SpineAttachment.cpp index e25f54c5e..2e00e0dd1 100644 --- a/spine-godot/spine_godot/SpineAttachment.cpp +++ b/spine-godot/spine_godot/SpineAttachment.cpp @@ -28,28 +28,30 @@ *****************************************************************************/ #include "SpineAttachment.h" +#include "common.h" void SpineAttachment::_bind_methods() { ClassDB::bind_method(D_METHOD("get_attachment_name"), &SpineAttachment::get_attachment_name); ClassDB::bind_method(D_METHOD("copy"), &SpineAttachment::copy); } -SpineAttachment::SpineAttachment() : attachment(NULL) {} +SpineAttachment::SpineAttachment() : attachment(nullptr) { +} + SpineAttachment::~SpineAttachment() { - if (attachment) { - attachment->dereference(); - attachment = NULL; - } + if (attachment) attachment->dereference(); } String SpineAttachment::get_attachment_name() { + SPINE_CHECK(attachment, "") return attachment->getName().buffer(); } Ref SpineAttachment::copy() { - auto a = attachment->copy(); - if (a == NULL) return NULL; - Ref gd_attachment(memnew(SpineAttachment)); - gd_attachment->set_spine_object(a); - return gd_attachment; -} \ No newline at end of file + SPINE_CHECK(attachment, nullptr) + auto copy = attachment->copy(); + if (!copy) return nullptr; + Ref attachment_ref(memnew(SpineAttachment)); + attachment_ref->set_spine_object(copy); + return attachment_ref; +} diff --git a/spine-godot/spine_godot/SpineAttachment.h b/spine-godot/spine_godot/SpineAttachment.h index 81ec52c9d..297fb7467 100644 --- a/spine-godot/spine_godot/SpineAttachment.h +++ b/spine-godot/spine_godot/SpineAttachment.h @@ -30,12 +30,11 @@ #ifndef GODOT_SPINEATTACHMENT_H #define GODOT_SPINEATTACHMENT_H -#include "core/variant_parser.h" - #include +#include "core/reference.h" class SpineAttachment : public Reference { - GDCLASS(SpineAttachment, Reference); + GDCLASS(SpineAttachment, Reference) protected: static void _bind_methods(); @@ -47,12 +46,12 @@ public: SpineAttachment(); ~SpineAttachment(); - inline void set_spine_object(spine::Attachment *a) { - attachment = a; - if (attachment) - attachment->reference(); + void set_spine_object(spine::Attachment *_attachment) { + attachment = _attachment; + if (attachment) attachment->reference(); } - inline spine::Attachment *get_spine_object() { + + spine::Attachment *get_spine_object() { return attachment; }