mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2025-12-21 01:36:02 +08:00
prevent a crash when a skin has no attachments. (#2114)
This commit is contained in:
parent
3cdfb25a48
commit
85af0f6580
@ -508,43 +508,43 @@ SkeletonData *SkeletonJson::readSkeletonData(const char *json) {
|
|||||||
skeletonData->_defaultSkin = skin;
|
skeletonData->_defaultSkin = skin;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (attachmentsMap = Json::getItem(skinMap,
|
Json *attachments = Json::getItem(skinMap, "attachments");
|
||||||
"attachments")
|
if (attachments)
|
||||||
->_child;
|
for (attachmentsMap = attachments->_child;
|
||||||
attachmentsMap; attachmentsMap = attachmentsMap->_next) {
|
attachmentsMap; attachmentsMap = attachmentsMap->_next) {
|
||||||
SlotData *slot = skeletonData->findSlot(attachmentsMap->_name);
|
SlotData *slot = skeletonData->findSlot(attachmentsMap->_name);
|
||||||
Json *attachmentMap;
|
Json *attachmentMap;
|
||||||
|
|
||||||
for (attachmentMap = attachmentsMap->_child; attachmentMap; attachmentMap = attachmentMap->_next) {
|
for (attachmentMap = attachmentsMap->_child; attachmentMap; attachmentMap = attachmentMap->_next) {
|
||||||
Attachment *attachment = NULL;
|
Attachment *attachment = NULL;
|
||||||
const char *skinAttachmentName = attachmentMap->_name;
|
const char *skinAttachmentName = attachmentMap->_name;
|
||||||
const char *attachmentName = Json::getString(attachmentMap, "name", skinAttachmentName);
|
const char *attachmentName = Json::getString(attachmentMap, "name", skinAttachmentName);
|
||||||
const char *attachmentPath = Json::getString(attachmentMap, "path", attachmentName);
|
const char *attachmentPath = Json::getString(attachmentMap, "path", attachmentName);
|
||||||
const char *color;
|
const char *color;
|
||||||
Json *entry;
|
Json *entry;
|
||||||
|
|
||||||
const char *typeString = Json::getString(attachmentMap, "type", "region");
|
const char *typeString = Json::getString(attachmentMap, "type", "region");
|
||||||
AttachmentType type;
|
AttachmentType type;
|
||||||
if (strcmp(typeString, "region") == 0) type = AttachmentType_Region;
|
if (strcmp(typeString, "region") == 0) type = AttachmentType_Region;
|
||||||
else if (strcmp(typeString, "mesh") == 0)
|
else if (strcmp(typeString, "mesh") == 0)
|
||||||
type = AttachmentType_Mesh;
|
type = AttachmentType_Mesh;
|
||||||
else if (strcmp(typeString, "linkedmesh") == 0)
|
else if (strcmp(typeString, "linkedmesh") == 0)
|
||||||
type = AttachmentType_Linkedmesh;
|
type = AttachmentType_Linkedmesh;
|
||||||
else if (strcmp(typeString, "boundingbox") == 0)
|
else if (strcmp(typeString, "boundingbox") == 0)
|
||||||
type = AttachmentType_Boundingbox;
|
type = AttachmentType_Boundingbox;
|
||||||
else if (strcmp(typeString, "path") == 0)
|
else if (strcmp(typeString, "path") == 0)
|
||||||
type = AttachmentType_Path;
|
type = AttachmentType_Path;
|
||||||
else if (strcmp(typeString, "clipping") == 0)
|
else if (strcmp(typeString, "clipping") == 0)
|
||||||
type = AttachmentType_Clipping;
|
type = AttachmentType_Clipping;
|
||||||
else if (strcmp(typeString, "point") == 0)
|
else if (strcmp(typeString, "point") == 0)
|
||||||
type = AttachmentType_Point;
|
type = AttachmentType_Point;
|
||||||
else {
|
else {
|
||||||
delete skeletonData;
|
delete skeletonData;
|
||||||
setError(root, "Unknown attachment type: ", typeString);
|
setError(root, "Unknown attachment type: ", typeString);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case AttachmentType_Region: {
|
case AttachmentType_Region: {
|
||||||
attachment = _attachmentLoader->newRegionAttachment(*skin, attachmentName, attachmentPath);
|
attachment = _attachmentLoader->newRegionAttachment(*skin, attachmentName, attachmentPath);
|
||||||
if (!attachment) {
|
if (!attachment) {
|
||||||
@ -624,8 +624,8 @@ SkeletonData *SkeletonJson::readSkeletonData(const char *json) {
|
|||||||
bool inheritDeform = Json::getInt(attachmentMap, "deform", 1) ? true : false;
|
bool inheritDeform = Json::getInt(attachmentMap, "deform", 1) ? true : false;
|
||||||
LinkedMesh *linkedMesh = new (__FILE__, __LINE__) LinkedMesh(mesh,
|
LinkedMesh *linkedMesh = new (__FILE__, __LINE__) LinkedMesh(mesh,
|
||||||
String(Json::getString(
|
String(Json::getString(
|
||||||
attachmentMap,
|
attachmentMap,
|
||||||
"skin", 0)),
|
"skin", 0)),
|
||||||
slot->getIndex(),
|
slot->getIndex(),
|
||||||
String(entry->_valueString),
|
String(entry->_valueString),
|
||||||
inheritDeform);
|
inheritDeform);
|
||||||
@ -653,7 +653,7 @@ SkeletonData *SkeletonJson::readSkeletonData(const char *json) {
|
|||||||
int vertexCount = 0;
|
int vertexCount = 0;
|
||||||
pathAttatchment->_closed = Json::getInt(attachmentMap, "closed", 0) ? true : false;
|
pathAttatchment->_closed = Json::getInt(attachmentMap, "closed", 0) ? true : false;
|
||||||
pathAttatchment->_constantSpeed = Json::getInt(attachmentMap, "constantSpeed", 1) ? true
|
pathAttatchment->_constantSpeed = Json::getInt(attachmentMap, "constantSpeed", 1) ? true
|
||||||
: false;
|
: false;
|
||||||
vertexCount = Json::getInt(attachmentMap, "vertexCount", 0);
|
vertexCount = Json::getInt(attachmentMap, "vertexCount", 0);
|
||||||
readVertices(attachmentMap, pathAttatchment, vertexCount << 1);
|
readVertices(attachmentMap, pathAttatchment, vertexCount << 1);
|
||||||
|
|
||||||
@ -696,11 +696,11 @@ SkeletonData *SkeletonJson::readSkeletonData(const char *json) {
|
|||||||
_attachmentLoader->configureAttachment(attachment);
|
_attachmentLoader->configureAttachment(attachment);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
skin->setAttachment(slot->getIndex(), skinAttachmentName, attachment);
|
skin->setAttachment(slot->getIndex(), skinAttachmentName, attachment);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user