From 41cfd380495fb984098c19dbdd7539c2b48dffd6 Mon Sep 17 00:00:00 2001 From: badlogic Date: Tue, 19 Nov 2019 16:36:25 +0100 Subject: [PATCH] [cpp][cocos2dx] Skin and attachment setters now handle empty strings correctly. Closes #1543. --- spine-cocos2dx/src/spine/SkeletonRenderer.cpp | 8 ++++++-- spine-cpp/spine-cpp/src/spine/Skeleton.cpp | 7 ++----- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/spine-cocos2dx/src/spine/SkeletonRenderer.cpp b/spine-cocos2dx/src/spine/SkeletonRenderer.cpp index 538e4aab5..c10e3ac3e 100644 --- a/spine-cocos2dx/src/spine/SkeletonRenderer.cpp +++ b/spine-cocos2dx/src/spine/SkeletonRenderer.cpp @@ -766,10 +766,14 @@ namespace spine { return _skeleton->getAttachment(slotName.c_str(), attachmentName.c_str()); } bool SkeletonRenderer::setAttachment (const std::string& slotName, const std::string& attachmentName) { - return _skeleton->getAttachment(slotName.c_str(), attachmentName.empty() ? 0 : attachmentName.c_str()) ? true : false; + bool result = _skeleton->getAttachment(slotName.c_str(), attachmentName.empty() ? 0 : attachmentName.c_str()) ? true : false; + _skeleton->setAttachment(slotName.c_str(), attachmentName.empty() ? 0 : attachmentName.c_str()); + return result; } bool SkeletonRenderer::setAttachment (const std::string& slotName, const char* attachmentName) { - return _skeleton->getAttachment(slotName.c_str(), attachmentName) ? true : false; + bool result = _skeleton->getAttachment(slotName.c_str(), attachmentName) ? true : false; + _skeleton->setAttachment(slotName.c_str(), attachmentName); + return result; } void SkeletonRenderer::setTwoColorTint(bool enabled) { diff --git a/spine-cpp/spine-cpp/src/spine/Skeleton.cpp b/spine-cpp/spine-cpp/src/spine/Skeleton.cpp index 113483244..3307b1f1a 100644 --- a/spine-cpp/spine-cpp/src/spine/Skeleton.cpp +++ b/spine-cpp/spine-cpp/src/spine/Skeleton.cpp @@ -303,10 +303,7 @@ int Skeleton::findSlotIndex(const String &slotName) { } void Skeleton::setSkin(const String &skinName) { - Skin *foundSkin = _data->findSkin(skinName); - - assert(foundSkin != NULL); - + Skin *foundSkin = skinName.isEmpty() ? NULL : _data->findSkin(skinName); setSkin(foundSkin); } @@ -340,7 +337,7 @@ Attachment *Skeleton::getAttachment(const String &slotName, const String &attach } Attachment *Skeleton::getAttachment(int slotIndex, const String &attachmentName) { - assert(attachmentName.length() > 0); + if (attachmentName.isEmpty()) return NULL; if (_skin != NULL) { Attachment *attachment = _skin->getAttachment(slotIndex, attachmentName);