• Runtimes
  • [Spine-C] spSkin_addSkin error

Related Discussions
...

Hi.

I want to apply some skins into my skeleton in my objective c project, but i got an error in spSkin_addSkin.

Thread 1: EXC_BAD_ACCESS (code=1, address=0x8)

This is how I created my skeleton

const char *atlasStr = [atlas UTF8String];
    spAtlas* myAtlas = spAtlas_createFromFile(atlasStr, 0);
    
const char *skeletonStr = [skeleton UTF8String]; spSkeletonJson* myJson = spSkeletonJson_create(myAtlas); myJson->scale = 1; spSkeletonData* skeletonData = spSkeletonJson_readSkeletonDataFile(myJson, skeletonStr); spSkin* skin = spSkin_create("mix-and-match"); spSkin_addSkin(skin, spSkeletonData_findSkin(skeletonData, "face")); spSkin_addSkin(skin, spSkeletonData_findSkin(skeletonData, "base_head")); spSkin_addSkin(skin, spSkeletonData_findSkin(skeletonData, "base_body")); spSkeleton* drawable = spSkeleton_create(skeletonData); spSkeleton_setSkin(drawable, skin); spSkeleton_setSlotsToSetupPose(drawable); skeletonNode = [SkeletonAnimation skeletonWithData:skeletonData ownsSkeletonData:TRUE];

My assets are exported using spine 3.8.59, and I am using runtimes from branch 3.8. Any ideas? Thank you

Please post the full stack trace for the exception. My guess is that spSkeletonData_findSkin() returns NULL, which means the skin couldn't be found.

badlogic a écrit

Please post the full stack trace for the exception. My guess is that spSkeletonData_findSkin() returns NULL, which means the skin couldn't be found.

After debug then I realized, there is something wrong in spSkin_addSkin function, in this line

entry = spSkin_getAttachments(other);
while (entry) {
   spSkin_setAttachment(self, entry->slotIndex, entry->name, entry->attachment);
   entry = entry->next;
}

while block is running for a while, entry per entry, then after the entry.name is face1, then the entry is NULL and crashed. This is my asset https://drive.google.com/open?id=1CSXknVpcQ2RL8FGi8HVIg9g0Dp6mbtdi Thank you!


filterSekai a écrit
badlogic a écrit

Please post the full stack trace for the exception. My guess is that spSkeletonData_findSkin() returns NULL, which means the skin couldn't be found.

After debug then I realized, there is something wrong in spSkin_addSkin function, in this line

entry = spSkin_getAttachments(other);
while (entry) {
   spSkin_setAttachment(self, entry->slotIndex, entry->name, entry->attachment);
   entry = entry->next;
}

while block is running for a while, entry per entry, then after the entry.name is face1, then the entry is NULL and crashed. This is my asset https://drive.google.com/open?id=1CSXknVpcQ2RL8FGi8HVIg9g0Dp6mbtdi Thank you!

Hi @badlogic,

My fault. There are no "base_head" and "base_body" in my json skeleton skin. But I think I still have a question, how to apply spSkin object into our skeletonData?

spSkin* skin = spSkin_create("default");
spSkin_addSkin(skin, spSkeletonData_findSkin(skeletonData, "face"));
spSkin_addSkin(skin, spSkeletonData_findSkin(skeletonData, "bottom_short"));

I created custom skin and I read in spine-runtimes/main.cpp at 3.8 but still have no clue how to add into our skeletonData. Tried to look at the example code, but found nothing. Thank you.

You use the skin by setting it on the skeleton, this line:
spine-runtimes/main.cpp at 3.8

spSkeleton_setSkin(skeleton, skin);

Note you often want to call Skeleton setSlotsToSetupPose after changing the skin (see Skeleton setSkin).

You don't need to add it to the SkeletonData (though you could).

Nate a écrit

You use the skin by setting it on the skeleton, this line:
spine-runtimes/main.cpp at 3.8

spSkeleton_setSkin(skeleton, skin);

Note you often want to call Skeleton setSlotsToSetupPose after changing the skin (see Skeleton setSkin).

You don't need to add it to the SkeletonData (though you could).

I created drawable as my skeleton

spSkeletonData* skeletonData = spSkeletonJson_readSkeletonDataFile(myJson, skeletonStr);
spSkin* skin = spSkin_create("default");
spSkin_addSkin(skin, spSkeletonData_findSkin(skeletonData, "face"));
spSkin_addSkin(skin, spSkeletonData_findSkin(skeletonData, "bottom_short"));

spSkeleton* drawable = spSkeleton_create(skeletonData);
spSkeleton_setSkin(drawable, skin);
spSkeleton_setSlotsToSetupPose(drawable);

But how can I create SkeletonAnimation with spSkeleton object? I need that for my CCNode properties (as the example said).

@interface CharPreviewNode : CCNode {
    SkeletonAnimation* skeletonNode;
}

Thank you, Nate!

badlogic a écrit

You don't need to create a new spSkeleton. Just get the spSkeleton from the SkeletonAnimation. The property is called skeleton, see spine-runtimes/SkeletonRenderer.h at 3.8

I called skeleton from my skeletonNode, but the instance variable skeleton is protected (readonly).

spSkeleton_setSkin(skeletonNode->_skeleton, skin);
spSkeleton_setSlotsToSetupPose(skeletonNode->_skeleton);

Any idea?

It's a property, so you'll have to use skeletonNode.skeleton.