From f77459983fbdf3cf6d4895af00ae7b648fedeb1a Mon Sep 17 00:00:00 2001 From: Victor Savu Date: Mon, 4 Mar 2013 18:54:05 +0200 Subject: [PATCH 1/4] use the states provided This allows animations to be scaled/moved easily --- spine-cpp/src/spine-sfml/Skeleton.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spine-cpp/src/spine-sfml/Skeleton.cpp b/spine-cpp/src/spine-sfml/Skeleton.cpp index 69be90e27..52b7c9393 100644 --- a/spine-cpp/src/spine-sfml/Skeleton.cpp +++ b/spine-cpp/src/spine-sfml/Skeleton.cpp @@ -23,7 +23,8 @@ void Skeleton::draw (RenderTarget& target, RenderStates states) const { const_cast(this)->vertexArray.clear(); for (int i = 0, n = slots.size(); i < n; i++) if (slots[i]->attachment) slots[i]->attachment->draw(slots[i]); - target.draw(vertexArray, texture); + states.texture = texture; + target.draw(vertexArray, states); } } /* namespace spine */ From 67aa8305117327d14f1a2410be7a6594bd00844f Mon Sep 17 00:00:00 2001 From: Victor Savu Date: Mon, 4 Mar 2013 20:43:33 +0200 Subject: [PATCH 2/4] fix use after free the string created by value.substr(index * 2, 2) is deleted after c_str() but before strtoul executes. The solution is to use a temporary string to store the value. --- spine-cpp/src/spine/BaseSkeletonJson.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/spine-cpp/src/spine/BaseSkeletonJson.cpp b/spine-cpp/src/spine/BaseSkeletonJson.cpp index fa42ce0a0..f5ea292f0 100644 --- a/spine-cpp/src/spine/BaseSkeletonJson.cpp +++ b/spine-cpp/src/spine/BaseSkeletonJson.cpp @@ -21,8 +21,9 @@ namespace spine { static float toColor (const string &value, int index) { if (value.size() != 8) throw runtime_error("Error parsing color, length must be 8: " + value); char *p; - int color = strtoul(value.substr(index * 2, 2).c_str(), &p, 16); - if (*p != 0) throw runtime_error("Error parsing color: " + value + ", invalid hex value: " + value.substr(index * 2, 2)); + string tmp = value.substr(index * 2, 2); + int color = strtoul(tmp.c_str(), &p, 16); + if (*p != 0) throw runtime_error("Error parsing color: " + value + ", invalid hex value: " + tmp); return color / (float)255; } From c93bb14708d1b40d73d1d39496c0f79f53d169e3 Mon Sep 17 00:00:00 2001 From: Victor Savu Date: Mon, 4 Mar 2013 20:51:47 +0200 Subject: [PATCH 3/4] free the texture when we are done with it --- spine-cpp/includes/spine-sfml/Atlas.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/spine-cpp/includes/spine-sfml/Atlas.h b/spine-cpp/includes/spine-sfml/Atlas.h index 25fbc2d77..14417152f 100644 --- a/spine-cpp/includes/spine-sfml/Atlas.h +++ b/spine-cpp/includes/spine-sfml/Atlas.h @@ -8,6 +8,10 @@ namespace spine { class AtlasPage: public BaseAtlasPage { public: + ~AtlasPage(){ + delete texture; + } + sf::Texture *texture; }; From b0f8468ddc2e88f3fdb3858abb37818ff158b38f Mon Sep 17 00:00:00 2001 From: Victor Savu Date: Mon, 4 Mar 2013 21:00:17 +0200 Subject: [PATCH 4/4] initialize variable --- spine-cpp/src/spine/BaseAtlas.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spine-cpp/src/spine/BaseAtlas.cpp b/spine-cpp/src/spine/BaseAtlas.cpp index 2d25a9b80..60fa24655 100644 --- a/spine-cpp/src/spine/BaseAtlas.cpp +++ b/spine-cpp/src/spine/BaseAtlas.cpp @@ -105,7 +105,7 @@ void BaseAtlas::load (const char *current, const char *end) { string value; string tuple[4]; - BaseAtlasPage *page; + BaseAtlasPage *page = NULL; while (current != end) { readLine(current, end, value); trim(value);