[cpp] Crashes and leaks everywhere :D

This commit is contained in:
badlogic 2018-02-14 16:49:55 +01:00
parent 3254747e94
commit e7e240d109
31 changed files with 179 additions and 97 deletions

View File

@ -61,16 +61,16 @@ void *Spine::TestSpineExtension::_realloc(void *ptr, size_t size, const char *fi
}
void Spine::TestSpineExtension::_free(void *mem, const char *file, int line) {
DefaultSpineExtension::_free(mem, file, line);
for (std::vector<Allocation>::iterator it = allocated.begin(); it != allocated.end(); it++) {
if (it->address == mem) {
DefaultSpineExtension::_free(mem, file, line);
allocated.erase(it);
return;
}
}
printf("%s:%i (address %p): Double free or not allocatedö through SpineExtension", file, line, mem);
printf("%s:%i (address %p): Double free or not allocated through SpineExtension\n", file, line, mem);
}
void Spine::TestSpineExtension::reportLeaks() {

View File

@ -33,19 +33,53 @@
#include "TestHarness.h"
#define SPINEBOY_JSON "testdata/spineboy/spineboy-ess.json"
#define SPINEBOY_ATLAS "testdata/spineboy/spineboy.atlas"
#define SPINEBOY_JSON "testdata/raptor/raptor-pro.json"
#define SPINEBOY_ATLAS "testdata/raptor/raptor.atlas"
using namespace Spine;
void loadSpineboy(Atlas* &atlas, SkeletonData* &skeletonData, AnimationStateData* &stateData, Skeleton* &skeleton, AnimationState* &state) {
atlas = new (__FILE__, __LINE__) Atlas(SPINEBOY_ATLAS, 0);
assert(atlas != 0);
SkeletonJson json(atlas);
skeletonData = json.readSkeletonDataFile(SPINEBOY_JSON);
assert(skeletonData);
skeleton = new (__FILE__, __LINE__) Skeleton(skeletonData);
assert(skeleton != 0);
stateData = new (__FILE__, __LINE__) AnimationStateData(skeletonData);
assert(stateData != 0);
stateData->setDefaultMix(0.4f);
state = new (__FILE__, __LINE__) AnimationState(stateData);
}
void dispose(Atlas* atlas, SkeletonData* skeletonData, AnimationStateData* stateData, Skeleton* skeleton, AnimationState* state) {
delete skeleton;
delete state;
delete stateData;
delete skeletonData;
delete atlas;
}
void reproduceIssue_776() {
Atlas* atlas = 0;
SkeletonData* skeletonData = 0;
AnimationStateData* stateData = 0;
Skeleton* skeleton = 0;
AnimationState* state = 0;
loadSpineboy(atlas, skeletonData, stateData, skeleton, state);
dispose(atlas, skeletonData, stateData, skeleton, state);
}
int main (int argc, char** argv) {
TestSpineExtension* ext = new TestSpineExtension();
SpineExtension::setInstance(ext);
Atlas* atlas = new (__FILE__, __LINE__) Atlas(SPINEBOY_ATLAS, 0);
delete atlas;
reproduceIssue_776();
ext->reportLeaks();
}

View File

@ -288,7 +288,7 @@ namespace Spine {
friend class EventQueue;
public:
AnimationState(AnimationStateData& data);
AnimationState(AnimationStateData* data);
~AnimationState();
@ -363,7 +363,7 @@ namespace Spine {
/// @return The track entry for the animation currently playing on the track, or NULL if no animation is currently playing.
TrackEntry* getCurrent(int trackIndex);
AnimationStateData& getData();
AnimationStateData* getData();
/// A list of tracks that have animations, which may contain NULLs.
Vector<TrackEntry*> getTracks();
@ -376,7 +376,7 @@ namespace Spine {
private:
static const int Subsequent, First, Dip, DipMix;
AnimationStateData& _data;
AnimationStateData* _data;
Pool<TrackEntry> _trackEntryPool;
Vector<TrackEntry*> _tracks;

View File

@ -47,13 +47,13 @@ namespace Spine {
public:
/// The SkeletonData to look up animations when they are specified by name.
SkeletonData& getSkeletonData();
SkeletonData* getSkeletonData();
/// The mix duration to use when no mix duration has been specifically defined between two animations.
float getDefaultMix();
void setDefaultMix(float inValue);
AnimationStateData(SkeletonData& skeletonData);
AnimationStateData(SkeletonData* skeletonData);
/// Sets a mix duration by animation names.
void setMix(std::string fromName, std::string toName, float duration);
@ -83,7 +83,7 @@ namespace Spine {
std::size_t operator()(const Spine::AnimationStateData::AnimationPair& val) const;
};
SkeletonData& _skeletonData;
SkeletonData* _skeletonData;
float _defaultMix;
HashMap<AnimationPair, float, HashAnimationPair> _animationToMixTime;
};

View File

@ -47,7 +47,7 @@ namespace Spine {
RTTI_DECL;
public:
AtlasAttachmentLoader(Atlas& atlas);
AtlasAttachmentLoader(Atlas* atlas);
virtual RegionAttachment* newRegionAttachment(Skin& skin, std::string name, std::string path);
@ -64,7 +64,7 @@ namespace Spine {
AtlasRegion* findRegion(std::string name);
private:
Atlas& _atlas;
Atlas* _atlas;
};
}

View File

@ -41,6 +41,7 @@ namespace Spine {
public:
Attachment(std::string name);
virtual ~Attachment();
const std::string& getName();

View File

@ -43,6 +43,8 @@ namespace Spine {
public:
CurveTimeline(int frameCount);
virtual ~CurveTimeline();
virtual void apply(Skeleton& skeleton, float lastTime, float time, Vector<Event*>* pEvents, float alpha, MixPose pose, MixDirection direction) = 0;

View File

@ -51,14 +51,9 @@ namespace Spine {
}
Iterator& operator++() {
_entry = _entry->next;
return *this;
}
Iterator& operator--() {
_entry = _entry->prev;
return *this;
}
_entry = _entry->next;
return *this;
}
bool operator==(const Iterator& p) const {
return _entry == p._entry;
@ -68,11 +63,11 @@ namespace Spine {
return _entry != p._entry;
}
K& first() {
K& key() {
return _entry->_key;
}
V& second() {
V& value() {
return _entry->_value;
}
@ -98,6 +93,9 @@ namespace Spine {
}
~HashMap() {
for (Iterator it = begin(); it != end(); ++it) {
delete it._entry;
}
_hashSize = 0;
}
@ -113,14 +111,6 @@ namespace Spine {
return Iterator(&_trailer);
}
Iterator rbegin() {
return Iterator(_trailer.prev);
}
Iterator rend() {
return Iterator(_header);
}
std::pair<Iterator, bool> insert(const K& key, const V& value) {
Iterator iter = find(key);

View File

@ -44,6 +44,8 @@ namespace Spine {
static const int ENTRIES;
PathConstraintPositionTimeline(int frameCount);
virtual ~PathConstraintPositionTimeline();
virtual void apply(Skeleton& skeleton, float lastTime, float time, Vector<Event*>* pEvents, float alpha, MixPose pose, MixDirection direction);

View File

@ -70,7 +70,7 @@ namespace Spine {
friend class TwoColorTimeline;
public:
Skeleton(SkeletonData& skeletonData);
Skeleton(SkeletonData* skeletonData);
~Skeleton();
@ -144,7 +144,7 @@ namespace Spine {
Bone* getRootBone();
const SkeletonData& getData();
const SkeletonData* getData();
Vector<Bone*>& getBones();
Vector<Updatable*>& getUpdateCacheList();
Vector<Slot*>& getSlots();
@ -174,7 +174,7 @@ namespace Spine {
void setFlipY(float inValue);
private:
SkeletonData& _data;
SkeletonData* _data;
Vector<Bone*> _bones;
Vector<Slot*> _slots;
Vector<Slot*> _drawOrder;

View File

@ -69,7 +69,7 @@ namespace Spine {
static const TransformMode TRANSFORM_MODE_VALUES[5];
SkeletonBinary(Atlas& atlasArray);
SkeletonBinary(Atlas* atlasArray);
SkeletonBinary(AttachmentLoader* attachmentLoader);

View File

@ -48,7 +48,7 @@ namespace Spine {
class SkeletonJson : public SpineObject {
public:
SkeletonJson(Atlas& atlas);
SkeletonJson(Atlas* atlas);
SkeletonJson(AttachmentLoader* attachmentLoader);

View File

@ -61,6 +61,7 @@ namespace Spine {
};
Skin(std::string name);
~Skin();
/// Adds an attachment to the skin for the specified slot index and name.
/// If the name already exists for the slot, the previous value is replaced.

View File

@ -38,6 +38,7 @@ namespace Spine {
public:
void* operator new(size_t sz, const char* file, int line);
void operator delete(void* p);
virtual ~SpineObject();
};
}

View File

@ -47,6 +47,8 @@ namespace Spine {
static const int ENTRIES;
TranslateTimeline(int frameCount);
virtual ~TranslateTimeline();
virtual void apply(Skeleton& skeleton, float lastTime, float time, Vector<Event*>* pEvents, float alpha, MixPose pose, MixDirection direction);

View File

@ -56,7 +56,6 @@ namespace Spine {
}
~Vector() {
clear();
deallocate(_buffer);
}
@ -149,21 +148,21 @@ namespace Spine {
T* end() {
return &_buffer[_size];
}
friend bool operator==(Vector<T>& lhs, Vector<T>& rhs) {
if (lhs.size() != rhs.size()) {
return false;
}
for (int i = 0, n = static_cast<int>(lhs.size()); i < n; ++i) {
if (lhs[i] != rhs[i]) {
return false;
}
}
return true;
}
friend bool operator!=(Vector<T>& lhs, Vector<T>& rhs) {
return !(lhs == rhs);
}
@ -186,6 +185,7 @@ namespace Spine {
void deallocate(T* buffer) {
if (_buffer) {
SpineExtension::free<T>(buffer, __FILE__, __LINE__);
// _buffer = 0;
}
}
};

View File

@ -48,6 +48,8 @@ namespace Spine {
public:
VertexAttachment(std::string name);
virtual ~VertexAttachment();
void computeWorldVertices(Slot& slot, Vector<float>& worldVertices);

View File

@ -305,7 +305,7 @@ namespace Spine {
const int AnimationState::Dip = 2;
const int AnimationState::DipMix = 3;
AnimationState::AnimationState(AnimationStateData& data) :
AnimationState::AnimationState(AnimationStateData* data) :
_data(data),
_queue(EventQueue::newEventQueue(*this, _trackEntryPool)),
_animationsChanged(false),
@ -501,7 +501,7 @@ namespace Spine {
}
TrackEntry* AnimationState::setAnimation(int trackIndex, std::string animationName, bool loop) {
Animation* animation = _data._skeletonData.findAnimation(animationName);
Animation* animation = _data->_skeletonData->findAnimation(animationName);
assert(animation != NULL);
return setAnimation(trackIndex, animation, loop);
@ -535,7 +535,7 @@ namespace Spine {
}
TrackEntry* AnimationState::addAnimation(int trackIndex, std::string animationName, bool loop, float delay) {
Animation* animation = _data._skeletonData.findAnimation(animationName);
Animation* animation = _data->_skeletonData->findAnimation(animationName);
assert(animation != NULL);
return addAnimation(trackIndex, animation, loop, delay);
@ -567,7 +567,7 @@ namespace Spine {
} else {
delay += duration;
}
delay -= _data.getMix(last->_animation, animation);
delay -= _data->getMix(last->_animation, animation);
} else {
delay = 0;
}
@ -613,7 +613,7 @@ namespace Spine {
return trackIndex >= _tracks.size() ? NULL : _tracks[trackIndex];
}
AnimationStateData& AnimationState::getData() {
AnimationStateData* AnimationState::getData() {
return _data;
}
@ -940,7 +940,7 @@ namespace Spine {
entry._alpha = 1;
entry._interruptAlpha = 1;
entry._mixTime = 0;
entry._mixDuration = (last == NULL) ? 0 : _data.getMix(last->_animation, animation);
entry._mixDuration = (last == NULL) ? 0 : _data->getMix(last->_animation, animation);
return entryP;
}

View File

@ -34,13 +34,13 @@
#include <spine/Animation.h>
namespace Spine {
AnimationStateData::AnimationStateData(SkeletonData& skeletonData) : _skeletonData(skeletonData), _defaultMix(0) {
AnimationStateData::AnimationStateData(SkeletonData* skeletonData) : _skeletonData(skeletonData), _defaultMix(0) {
// Empty
}
void AnimationStateData::setMix(std::string fromName, std::string toName, float duration) {
Animation* from = _skeletonData.findAnimation(fromName);
Animation* to = _skeletonData.findAnimation(toName);
Animation* from = _skeletonData->findAnimation(fromName);
Animation* to = _skeletonData->findAnimation(toName);
setMix(from, to, duration);
}
@ -64,13 +64,13 @@ namespace Spine {
HashMap<AnimationPair, float, HashAnimationPair>::Iterator i = _animationToMixTime.find(key);
if (i != _animationToMixTime.end()) {
return i.second();
return i.value();
}
return _defaultMix;
}
SkeletonData& AnimationStateData::getSkeletonData() {
SkeletonData* AnimationStateData::getSkeletonData() {
return _skeletonData;
}

View File

@ -26,7 +26,7 @@
* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
******************************************************S**********************/
#include <spine/AtlasAttachmentLoader.h>
@ -43,7 +43,7 @@
namespace Spine {
RTTI_IMPL(AtlasAttachmentLoader, AttachmentLoader);
AtlasAttachmentLoader::AtlasAttachmentLoader(Atlas& atlas) : AttachmentLoader(), _atlas(atlas) {
AtlasAttachmentLoader::AtlasAttachmentLoader(Atlas* atlas) : AttachmentLoader(), _atlas(atlas) {
// Empty
}
@ -64,7 +64,7 @@ namespace Spine {
attachment._regionHeight = region.height;
attachment._regionOriginalWidth = region.originalWidth;
attachment._regionOriginalHeight = region.originalHeight;
printf("New region attachment, %p %p\n", &attachmentP->getUVs(), &attachmentP->getOffset());
return attachmentP;
}
@ -111,6 +111,6 @@ namespace Spine {
AtlasRegion* AtlasAttachmentLoader::findRegion(std::string name) {
AtlasRegion* ret;
return _atlas.findRegion(name);
return _atlas->findRegion(name);
}
}

View File

@ -38,6 +38,9 @@ namespace Spine {
Attachment::Attachment(std::string name) : _name(name) {
assert(_name.length() > 0);
}
Attachment::~Attachment() {
}
const std::string& Attachment::getName() {
return _name;

View File

@ -46,6 +46,9 @@ namespace Spine {
_curves.reserve((frameCount - 1) * BEZIER_SIZE);
_curves.setSize((frameCount - 1) * BEZIER_SIZE);
}
CurveTimeline::~CurveTimeline() {
}
int CurveTimeline::getFrameCount() {
return static_cast<int>(_curves.size() / BEZIER_SIZE + 1);

View File

@ -78,23 +78,39 @@ namespace Spine {
}
void* DefaultSpineExtension::_alloc(size_t size, const char* file, int line) {
return ::malloc(size);
if (size == 0)
return 0;
void* ptr = ::malloc(size);
printf("alloc %lu bytes at %p\n", size, ptr);
return ptr;
}
void* DefaultSpineExtension::_calloc(size_t size, const char* file, int line) {
void* ptr = _alloc(size, file, line);
if (size == 0)
return 0;
void* ptr = ::malloc(size);
if (ptr) {
memset(ptr, 0, size);
}
printf("calloc %lu bytes at %p\n", size, ptr);
return ptr;
}
void* DefaultSpineExtension::_realloc(void* ptr, size_t size, const char* file, int line) {
return ::realloc(ptr, size);
void* mem = NULL;
if (size == 0)
return 0;
if (ptr == NULL)
mem = ::malloc(size);
else
mem = ::realloc(ptr, size);
printf("realloc %lu bytes from %p to %p\n", size, ptr, mem);
return mem;
}
void DefaultSpineExtension::_free(void* mem, const char* file, int line) {
printf("free %p\n", mem);
::free(mem);
}

View File

@ -52,6 +52,10 @@ namespace Spine {
_frames.reserve(frameCount * ENTRIES);
_frames.setSize(frameCount * ENTRIES);
}
PathConstraintPositionTimeline::~PathConstraintPositionTimeline() {
// Empty
}
void PathConstraintPositionTimeline::apply(Skeleton& skeleton, float lastTime, float time, Vector<Event*>* pEvents, float alpha, MixPose pose, MixDirection direction) {
PathConstraint* constraintP = skeleton._pathConstraints[_pathConstraintIndex];

View File

@ -53,7 +53,7 @@
#include <spine/Extension.h>
namespace Spine {
Skeleton::Skeleton(SkeletonData& skeletonData) :
Skeleton::Skeleton(SkeletonData* skeletonData) :
_data(skeletonData),
_skin(NULL),
_r(1),
@ -65,8 +65,8 @@ namespace Spine {
_flipY(false),
_x(0),
_y(0) {
_bones.reserve(_data.getBones().size());
for (BoneData** i = _data.getBones().begin(); i != _data.getBones().end(); ++i) {
_bones.reserve(_data->getBones().size());
for (BoneData** i = _data->getBones().begin(); i != _data->getBones().end(); ++i) {
BoneData* data = (*i);
Bone* bone;
@ -82,9 +82,9 @@ namespace Spine {
_bones.push_back(bone);
}
_slots.reserve(_data.getSlots().size());
_drawOrder.reserve(_data.getSlots().size());
for (SlotData** i = _data.getSlots().begin(); i != _data.getSlots().end(); ++i) {
_slots.reserve(_data->getSlots().size());
_drawOrder.reserve(_data->getSlots().size());
for (SlotData** i = _data->getSlots().begin(); i != _data->getSlots().end(); ++i) {
SlotData* data = (*i);
Bone* bone = _bones[data->getBoneData().getIndex()];
@ -94,8 +94,8 @@ namespace Spine {
_drawOrder.push_back(slot);
}
_ikConstraints.reserve(_data.getIkConstraints().size());
for (IkConstraintData** i = _data.getIkConstraints().begin(); i != _data.getIkConstraints().end(); ++i) {
_ikConstraints.reserve(_data->getIkConstraints().size());
for (IkConstraintData** i = _data->getIkConstraints().begin(); i != _data->getIkConstraints().end(); ++i) {
IkConstraintData* data = (*i);
IkConstraint* constraint = new (__FILE__, __LINE__) IkConstraint(*data, *this);
@ -103,8 +103,8 @@ namespace Spine {
_ikConstraints.push_back(constraint);
}
_transformConstraints.reserve(_data.getTransformConstraints().size());
for (TransformConstraintData** i = _data.getTransformConstraints().begin(); i != _data.getTransformConstraints().end(); ++i) {
_transformConstraints.reserve(_data->getTransformConstraints().size());
for (TransformConstraintData** i = _data->getTransformConstraints().begin(); i != _data->getTransformConstraints().end(); ++i) {
TransformConstraintData* data = (*i);
TransformConstraint* constraint = new (__FILE__, __LINE__) TransformConstraint(*data, *this);
@ -112,8 +112,8 @@ namespace Spine {
_transformConstraints.push_back(constraint);
}
_pathConstraints.reserve(_data.getPathConstraints().size());
for (PathConstraintData** i = _data.getPathConstraints().begin(); i != _data.getPathConstraints().end(); ++i) {
_pathConstraints.reserve(_data->getPathConstraints().size());
for (PathConstraintData** i = _data->getPathConstraints().begin(); i != _data->getPathConstraints().end(); ++i) {
PathConstraintData* data = (*i);
PathConstraint* constraint = new (__FILE__, __LINE__) PathConstraint(*data, *this);
@ -286,7 +286,7 @@ namespace Spine {
}
void Skeleton::setSkin(std::string skinName) {
Skin* foundSkin = _data.findSkin(skinName);
Skin* foundSkin = _data->findSkin(skinName);
assert(foundSkin != NULL);
@ -318,7 +318,7 @@ namespace Spine {
}
Attachment* Skeleton::getAttachment(std::string slotName, std::string attachmentName) {
return getAttachment(_data.findSlotIndex(slotName), attachmentName);
return getAttachment(_data->findSlotIndex(slotName), attachmentName);
}
Attachment* Skeleton::getAttachment(int slotIndex, std::string attachmentName) {
@ -331,7 +331,7 @@ namespace Spine {
}
}
return _data.getDefaultSkin() != NULL ? _data.getDefaultSkin()->getAttachment(slotIndex, attachmentName) : NULL;
return _data->getDefaultSkin() != NULL ? _data->getDefaultSkin()->getAttachment(slotIndex, attachmentName) : NULL;
}
void Skeleton::setAttachment(std::string slotName, std::string attachmentName) {
@ -454,7 +454,7 @@ namespace Spine {
return _bones.size() == 0 ? NULL : _bones[0];
}
const SkeletonData& Skeleton::getData() {
const SkeletonData* Skeleton::getData() {
return _data;
}
@ -592,12 +592,12 @@ namespace Spine {
sortPathConstraintAttachment(_skin, slotIndex, slotBone);
}
if (_data._defaultSkin != NULL && _data._defaultSkin != _skin) {
sortPathConstraintAttachment(_data._defaultSkin, slotIndex, slotBone);
if (_data->_defaultSkin != NULL && _data->_defaultSkin != _skin) {
sortPathConstraintAttachment(_data->_defaultSkin, slotIndex, slotBone);
}
for (int ii = 0, nn = static_cast<int>(_data._skins.size()); ii < nn; ++ii) {
sortPathConstraintAttachment(_data._skins[ii], slotIndex, slotBone);
for (int ii = 0, nn = static_cast<int>(_data->_skins.size()); ii < nn; ++ii) {
sortPathConstraintAttachment(_data->_skins[ii], slotIndex, slotBone);
}
Attachment* attachment = slot->_attachment;
@ -657,9 +657,9 @@ namespace Spine {
HashMap<Skin::AttachmentKey, Attachment*, Skin::HashAttachmentKey>& attachments = skin->getAttachments();
for (typename HashMap<Skin::AttachmentKey, Attachment*, Skin::HashAttachmentKey>::Iterator i = attachments.begin(); i != attachments.end(); ++i) {
Skin::AttachmentKey key = i.first();
Skin::AttachmentKey key = i.key();
if (key._slotIndex == slotIndex) {
Attachment* value = i.second();
Attachment* value = i.value();
sortPathConstraintAttachment(value, slotBone);
}
}

View File

@ -106,7 +106,7 @@ namespace Spine {
TransformMode_NoScaleOrReflection
};
SkeletonBinary::SkeletonBinary(Atlas& atlasArray) : _attachmentLoader(new (__FILE__, __LINE__) AtlasAttachmentLoader(atlasArray)), _error(), _scale(1), _ownsLoader(true) {
SkeletonBinary::SkeletonBinary(Atlas* atlasArray) : _attachmentLoader(new (__FILE__, __LINE__) AtlasAttachmentLoader(atlasArray)), _error(), _scale(1), _ownsLoader(true) {
}

View File

@ -86,7 +86,7 @@
#endif
namespace Spine {
SkeletonJson::SkeletonJson(Atlas& atlas) : _attachmentLoader(new (__FILE__, __LINE__) AtlasAttachmentLoader(atlas)), _scale(1), _ownsLoader(true) {
SkeletonJson::SkeletonJson(Atlas* atlas) : _attachmentLoader(new (__FILE__, __LINE__) AtlasAttachmentLoader(atlas)), _scale(1), _ownsLoader(true) {
}
SkeletonJson::SkeletonJson(AttachmentLoader* attachmentLoader) : _attachmentLoader(attachmentLoader), _scale(1), _ownsLoader(false) {

View File

@ -57,6 +57,16 @@ namespace Spine {
Skin::Skin(std::string name) : _name(name) {
assert(_name.length() > 0);
}
Skin::~Skin() {
HashMap<AttachmentKey, Attachment*, HashAttachmentKey>::Iterator i = _attachments.begin();
printf("Disposing skin\n");
for (; i != _attachments.end(); ++i) {
printf("%p %s\n", i.value(), i.value()->getName().c_str());
delete i.value();
}
printf("Disposing skin done\n");
}
void Skin::addAttachment(int slotIndex, std::string name, Attachment* attachment) {
assert(attachment);
@ -70,7 +80,7 @@ namespace Spine {
Attachment* ret = NULL;
if (i != _attachments.end()) {
ret = i.second();
ret = i.value();
}
return ret;
@ -78,16 +88,16 @@ namespace Spine {
void Skin::findNamesForSlot(int slotIndex, Vector<std::string>& names) {
for (HashMap<AttachmentKey, Attachment*, HashAttachmentKey>::Iterator i = _attachments.begin(); i != _attachments.end(); ++i) {
if (i.first()._slotIndex == slotIndex) {
names.push_back(i.first()._name);
if (i.key()._slotIndex == slotIndex) {
names.push_back(i.key()._name);
}
}
}
void Skin::findAttachmentsForSlot(int slotIndex, Vector<Attachment*>& attachments) {
for (HashMap<AttachmentKey, Attachment*, HashAttachmentKey>::Iterator i = _attachments.begin(); i != _attachments.end(); ++i) {
if (i.first()._slotIndex == slotIndex) {
attachments.push_back(i.second());
if (i.key()._slotIndex == slotIndex) {
attachments.push_back(i.value());
}
}
}
@ -104,12 +114,12 @@ namespace Spine {
Vector<Slot*>& slots = skeleton.getSlots();
for (HashMap<AttachmentKey, Attachment*, HashAttachmentKey>::Iterator i = oldSkin.getAttachments().begin(); i != oldSkin.getAttachments().end(); ++i) {
int slotIndex = i.first()._slotIndex;
int slotIndex = i.key()._slotIndex;
Slot* slot = slots[slotIndex];
if (slot->getAttachment() == i.second()) {
if (slot->getAttachment() == i.value()) {
Attachment* attachment = NULL;
if ((attachment = getAttachment(slotIndex, i.first()._name))) {
if ((attachment = getAttachment(slotIndex, i.key()._name))) {
slot->setAttachment(attachment);
}
}

View File

@ -34,11 +34,14 @@
namespace Spine {
void *SpineObject::operator new(size_t sz, const char* file, int line) {
return SpineExtension::alloc<SpineObject>(sz, file, line);
return SpineExtension::calloc<SpineObject>(sz, file, line);
}
void SpineObject::operator delete(void *p) {
((SpineObject*)p)->~SpineObject();
SpineExtension::free(p, __FILE__, __LINE__);
}
SpineObject::~SpineObject() {
// Empty
}
}

View File

@ -54,6 +54,10 @@ namespace Spine {
_frames.reserve(frameCount * ENTRIES);
_frames.setSize(frameCount * ENTRIES);
}
TranslateTimeline::~TranslateTimeline() {
// Empty
}
void TranslateTimeline::apply(Skeleton& skeleton, float lastTime, float time, Vector<Event*>* pEvents, float alpha, MixPose pose, MixDirection direction) {
Bone* boneP = skeleton._bones[_boneIndex];

View File

@ -41,6 +41,10 @@ namespace Spine {
VertexAttachment::VertexAttachment(std::string name) : Attachment(name), _worldVerticesLength(0), _id(getNextID()) {
// Empty
}
VertexAttachment::~VertexAttachment() {
// Empty
}
void VertexAttachment::computeWorldVertices(Slot& slot, Vector<float>& worldVertices) {
computeWorldVertices(slot, 0, _worldVerticesLength, worldVertices, 0);