Hey, I am trying to make some custom Cocos2DX examples to get to know the engine better.
As far as I can see, the "automatic" method:
spine::SkeletonAnimation::createWithJsonFile
doesn't seem to be efficient in case you want to create lots of copies of an animated object. The correct way is probably this:
- create atlas from file
- create skeleton data from atlas + (json) file
- create as many instances as you like from skeleton data
Well, that crashes when I try to
addChild
the created instance in my scene. Here is my crashing code:
if (true)
{
// this works
skeletonInstance = spine::SkeletonAnimation::createWithJsonFile(PATH + "goblins.json", PATH + "goblins.atlas", 1.f);
addChild(skeletonInstance);
skeletonInstance->setPosition(400, 300);
skeletonInstance->setAnimation(0, "walk", true);
skeletonInstance->setSkin("goblin");
}
else
{
// this crashes at render time
spAtlas* atlas = spAtlas_createFromFile((PATH + "goblins.atlas").c_str(), 0);
spSkeletonJson* json = spSkeletonJson_create(atlas);
json->scale = 1.f;
spSkeletonData* skeletonData = spSkeletonJson_readSkeletonDataFile(json, (PATH + "goblins.json").c_str());
if (!skeletonData) {
CCLOG("OOPSA: %s\n", json->error);
//exit(0);
}
skeletonInstance = spine::SkeletonAnimation::createWithData(skeletonData, true);
addChild(skeletonInstance);
spSkeletonJson_dispose(json);
}
crash info:
Exception thrown: read access violation.
attachmentVertices->_triangles was 0x2D.
in file
SkeletonRenderer.cpp, line 226
I've checked how
spine::SkeletonAnimation::createWithJsonFile
works, and it seems it has these lines different:
_attachmentLoader = SUPER(Cocos2dAttachmentLoader_create(_atlas));
spSkeletonJson* json = spSkeletonJson_createWithLoader(_attachmentLoader);
The spine docs IIRC don't mention that the attachmentLoader is essential, but maybe it is? Or is it a library (spine-cpp) bug? Or what?