Fixed crashes on MSVC.

This commit is contained in:
badlogic 2018-05-24 14:31:26 +02:00
parent b60f21e6d8
commit b7ae63f743
14 changed files with 80 additions and 33 deletions

View File

@ -1,6 +1,15 @@
cmake_minimum_required(VERSION 2.8.9)
project(spine)
if(MSVC)
message("MSCV detected")
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_CRT_SECURE_NO_WARNINGS")
set (CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS} -D_CRT_SECURE_NO_WARNINGS")
else()
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -pedantic -std=c89")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wnon-virtual-dtor -pedantic -std=c++03 -fno-exceptions -fno-rtti")
endif()
set(CMAKE_INSTALL_PREFIX "./")
set(CMAKE_VERBOSE_MAKEFILE ON)
set(SPINE_SFML FALSE CACHE BOOL FALSE)

View File

@ -2,7 +2,6 @@ include_directories(include)
file(GLOB INCLUDES "spine-c/include/**/*.h")
file(GLOB SOURCES "spine-c/src/**/*.c" "spine-c/src/**/*.cpp")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -std=c89 -pedantic")
add_library(spine-c STATIC ${SOURCES} ${INCLUDES})
target_include_directories(spine-c PUBLIC spine-c/include)
install(TARGETS spine-c DESTINATION dist/lib)

View File

@ -3,7 +3,7 @@ project(spine_unit_test)
set(CMAKE_INSTALL_PREFIX "./")
set(CMAKE_VERBOSE_MAKEFILE ON)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_CRT_SECURE_NO_WARNINGS -DKANJI_MEMTRACE -DUSE_CPP11_MUTEX -std=c++11")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DKANJI_MEMTRACE -DUSE_CPP11_MUTEX")
#########################################################
# set includes

View File

@ -307,13 +307,13 @@ void MemoryTestFixture::skeletonClipper() {
spSkeletonClipping_clipTriangles(clipping, vertices->items, vertices->size, indices->items, indices->size, uvs->items, 2);
float expectedVertices[8] = { 83.333328, 50.000000, 76.666664, 70.000000, 23.333334, 70.000000, 16.666672, 50.000000 };
float expectedVertices[8] = { 83.333328f, 50.000000f, 76.666664f, 70.000000f, 23.333334f, 70.000000f, 16.666672f, 50.000000f };
ASSERT(clipping->clippedVertices->size == 8);
for (int i = 0; i < clipping->clippedVertices->size; i++) {
ASSERT(ABS(clipping->clippedVertices->items[i] - expectedVertices[i]) < 0.001);
}
float expectedUVs[8] = { 0.833333f, 0.333333, 0.766667, 0.466667, 0.233333, 0.466667, 0.166667, 0.333333 };
float expectedUVs[8] = { 0.833333f, 0.333333f, 0.766667f, 0.466667f, 0.233333f, 0.466667f, 0.166667f, 0.333333f };
ASSERT(clipping->clippedUVs->size == 8);
for (int i = 0; i < clipping->clippedUVs->size; i++) {
ASSERT(ABS(clipping->clippedUVs->items[i] - expectedUVs[i]) < 0.001);

View File

@ -1,8 +1,16 @@
if(MSVC)
message("MSCV detected")
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_CRT_SECURE_NO_WARNINGS")
set (CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS} -D_CRT_SECURE_NO_WARNINGS")
else()
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -pedantic -std=c89")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wnon-virtual-dtor -pedantic -std=c++03 -fno-exceptions -fno-rtti")
endif()
include_directories(include)
file(GLOB INCLUDES "spine-cpp/include/**/*.h")
file(GLOB SOURCES "spine-cpp/src/**/*.cpp")
set(CMAKE_CPP_FLAGS "${CMAKE_CPP_FLAGS} -Wall -Wall -Wextra -Wshadow -Wnon-virtual-dtor -pedantic -std=c++03 -fno-exceptions -fno-rtti")
add_library(spine-cpp STATIC ${SOURCES} ${INCLUDES})
target_include_directories(spine-cpp PUBLIC spine-cpp/include)
install(TARGETS spine-cpp DESTINATION dist/lib)

View File

@ -3,8 +3,6 @@ project(spine_cpp_unit_test)
set(CMAKE_INSTALL_PREFIX "./")
set(CMAKE_VERBOSE_MAKEFILE ON)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wshadow -Wnon-virtual-dtor -pedantic -std=c++03 -fno-exceptions -fno-rtti")
set(CMAKE_CPP_FLAGS "${CMAKE_CPP_FLAGS} -Wall -Wextra -Wshadow -Wnon-virtual-dtor -pedantic -std=c++03 -fno-exceptions -fno-rtti")
include_directories(../spine-cpp/include teamcity minicppunit tests memory)

View File

@ -32,6 +32,8 @@
#include <spine/spine.h>
#include <spine/Debug.h>
#pragma warning ( disable : 4710 )
using namespace Spine;
void loadBinary(const String &binaryFile, const String &atlasFile, Atlas *&atlas, SkeletonData *&skeletonData,
@ -92,16 +94,16 @@ struct TestData {
void testLoading() {
Vector<TestData> testData;
/*testData.add(TestData("testdata/coin/coin-pro.json", "testdata/coin/coin-pro.skel", "testdata/coin/coin.atlas"));
testData.add(TestData("testdata/goblins/goblins-pro.json", "testdata/goblins/goblins-pro.skel",
testData.add(TestData("testdata/coin/coin-pro.json", "testdata/coin/coin-pro.skel", "testdata/coin/coin.atlas"));
/*testData.add(TestData("testdata/goblins/goblins-pro.json", "testdata/goblins/goblins-pro.skel",
"testdata/goblins/goblins.atlas"));
testData.add(TestData("testdata/raptor/raptor-pro.json", "testdata/raptor/raptor-pro.skel",
"testdata/raptor/raptor.atlas"));
testData.add(TestData("testdata/spineboy/spineboy-pro.json", "testdata/spineboy/spineboy-pro.skel",
"testdata/spineboy/spineboy.atlas"));
testData.add(TestData("testdata/stretchyman/stretchyman-pro.json", "testdata/stretchyman/stretchyman-pro.skel",
"testdata/stretchyman/stretchyman.atlas"));*/
testData.add(TestData("testdata/tank/tank-pro.json", "testdata/tank/tank-pro.skel", "testdata/tank/tank.atlas"));
"testdata/stretchyman/stretchyman.atlas"));
testData.add(TestData("testdata/tank/tank-pro.json", "testdata/tank/tank-pro.skel", "testdata/tank/tank.atlas"));*/
for (size_t i = 0; i < testData.size(); i++) {
TestData &data = testData[i];

View File

@ -85,8 +85,10 @@ public:
}
~HashMap() {
for (Entry *entry = _head; entry != NULL; entry = entry->next) {
for (Entry *entry = _head; entry != NULL;) {
Entry* next = entry->next;
delete entry;
entry = next;
}
}

View File

@ -34,6 +34,8 @@
#include <spine/ContainerUtil.h>
#include <ctype.h>
using namespace Spine;
Atlas::Atlas(const String &path, TextureLoader *textureLoader) : _textureLoader(textureLoader) {

View File

@ -641,7 +641,9 @@ Animation *SkeletonBinary::readAnimation(const String &name, DataInput *input, S
AttachmentTimeline *timeline = new(__FILE__, __LINE__) AttachmentTimeline(frameCount);
timeline->_slotIndex = slotIndex;
for (int frameIndex = 0; frameIndex < frameCount; ++frameIndex) {
timeline->setFrame(frameIndex, readFloat(input), String(readString(input), true));
float time = readFloat(input);
String attachmentName = String(readString(input), true);
timeline->setFrame(frameIndex, time, attachmentName);
}
timelines.add(timeline);
duration = MathUtil::max(duration, timeline->_frames[frameCount - 1]);
@ -710,7 +712,9 @@ Animation *SkeletonBinary::readAnimation(const String &name, DataInput *input, S
RotateTimeline *timeline = new(__FILE__, __LINE__) RotateTimeline(frameCount);
timeline->_boneIndex = boneIndex;
for (int frameIndex = 0; frameIndex < frameCount; ++frameIndex) {
timeline->setFrame(frameIndex, readFloat(input), readFloat(input));
float time = readFloat(input);
float degrees = readFloat(input);
timeline->setFrame(frameIndex, time, degrees);
if (frameIndex < frameCount - 1) {
readCurve(input, frameIndex, timeline);
}
@ -734,8 +738,10 @@ Animation *SkeletonBinary::readAnimation(const String &name, DataInput *input, S
}
timeline->_boneIndex = boneIndex;
for (int frameIndex = 0; frameIndex < frameCount; ++frameIndex) {
timeline->setFrame(frameIndex, readFloat(input), readFloat(input) * timelineScale,
readFloat(input) * timelineScale);
float time = readFloat(input);
float x = readFloat(input) * timelineScale;
float y = readFloat(input) * timelineScale;
timeline->setFrame(frameIndex, time, x, y);
if (frameIndex < frameCount - 1) {
readCurve(input, frameIndex, timeline);
}
@ -761,7 +767,10 @@ Animation *SkeletonBinary::readAnimation(const String &name, DataInput *input, S
IkConstraintTimeline *timeline = new(__FILE__, __LINE__) IkConstraintTimeline(frameCount);
timeline->_ikConstraintIndex = index;
for (int frameIndex = 0; frameIndex < frameCount; ++frameIndex) {
timeline->setFrame(frameIndex, readFloat(input), readFloat(input), readSByte(input));
float time = readFloat(input);
float mix = readFloat(input);
signed char bendDirection = readSByte(input);
timeline->setFrame(frameIndex, time, mix, bendDirection);
if (frameIndex < frameCount - 1) {
readCurve(input, frameIndex, timeline);
}
@ -777,8 +786,12 @@ Animation *SkeletonBinary::readAnimation(const String &name, DataInput *input, S
TransformConstraintTimeline *timeline = new(__FILE__, __LINE__) TransformConstraintTimeline(frameCount);
timeline->_transformConstraintIndex = index;
for (int frameIndex = 0; frameIndex < frameCount; ++frameIndex) {
timeline->setFrame(frameIndex, readFloat(input), readFloat(input), readFloat(input), readFloat(input),
readFloat(input));
float time = readFloat(input);
float rotateMix = readFloat(input);
float translateMix = readFloat(input);
float scaleMix = readFloat(input);
float shearMix = readFloat(input);
timeline->setFrame(frameIndex, time, rotateMix, translateMix, scaleMix, shearMix);
if (frameIndex < frameCount - 1) {
readCurve(input, frameIndex, timeline);
}
@ -814,7 +827,9 @@ Animation *SkeletonBinary::readAnimation(const String &name, DataInput *input, S
}
timeline->_pathConstraintIndex = index;
for (int frameIndex = 0; frameIndex < frameCount; ++frameIndex) {
timeline->setFrame(frameIndex, readFloat(input), readFloat(input) * timelineScale);
float time = readFloat(input);
float value = readFloat(input) * timelineScale;
timeline->setFrame(frameIndex, time, value);
if (frameIndex < frameCount - 1) {
readCurve(input, frameIndex, timeline);
}
@ -829,7 +844,10 @@ Animation *SkeletonBinary::readAnimation(const String &name, DataInput *input, S
timeline->_pathConstraintIndex = index;
for (int frameIndex = 0; frameIndex < frameCount; ++frameIndex) {
timeline->setFrame(frameIndex, readFloat(input), readFloat(input), readFloat(input));
float time = readFloat(input);
float rotateMix = readFloat(input);
float translateMix = readFloat(input);
timeline->setFrame(frameIndex, time, rotateMix, translateMix);
if (frameIndex < frameCount - 1) {
readCurve(input, frameIndex, timeline);
}

View File

@ -147,7 +147,7 @@ void spineboy (SkeletonData* skeletonData, Atlas* atlas) {
SkeletonBounds_update(bounds, skeleton, true);
sf::Vector2i position = sf::Mouse::getPosition(window);
if (SkeletonBounds_containsPoint(bounds, position.x, position.y)) {
if (SkeletonBounds_containsPoint(bounds, (float)position.x, (float)position.y)) {
headSlot->color.g = 0;
headSlot->color.b = 0;
} else {
@ -230,7 +230,7 @@ void raptor (SkeletonData* skeletonData, Atlas* atlas) {
deltaClock.restart();
swirlTime += delta;
float percent = fmod(swirlTime, 2);
float percent = (float)fmod(swirlTime, 2);
if (percent > 1) percent = 1 - (percent - 1);
effect->angle = _spMath_interpolate(_spMath_pow2_apply, -60, 60, percent);
@ -401,11 +401,11 @@ void owl (SkeletonData* skeletonData, Atlas* atlas) {
if (event.type == sf::Event::MouseMoved) {
float x = event.mouseMove.x / 640.0f;
left->alpha = (MAX(x, 0.5f) - 0.5f) * 2;
right->alpha = (0.5 - MIN(x, 0.5)) * 2;
right->alpha = (0.5f - MIN(x, 0.5f)) * 2;
float y = event.mouseMove.y / 640.0f;
down->alpha = (MAX(y, 0.5f) - 0.5f) * 2;
up->alpha = (0.5 - MIN(y, 0.5)) * 2;
up->alpha = (0.5f - MIN(y, 0.5f)) * 2;
}
}

View File

@ -43,6 +43,15 @@ else()
endif()
endif()
if(MSVC)
message("MSCV detected")
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_CRT_SECURE_NO_WARNINGS")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_CRT_SECURE_NO_WARNINGS")
else()
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -pedantic -std=c89")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wnon-virtual-dtor -pedantic -std=c++03 -fno-exceptions -fno-rtti")
endif()
# Define spine-sfml-cpp library
include_directories(src ${SFML_DIR}/include)
file(GLOB INCLUDES "src/**/*.h")

View File

@ -145,7 +145,7 @@ void spineboy (SkeletonData* skeletonData, Atlas* atlas) {
bounds.update(*skeleton, true);
sf::Vector2i position = sf::Mouse::getPosition(window);
if (bounds.containsPoint(position.x, position.y)) {
if (bounds.containsPoint((float)position.x, (float)position.y)) {
headSlot->getColor().g = 0;
headSlot->getColor().b = 0;
} else {
@ -408,11 +408,11 @@ void owl (SkeletonData* skeletonData, Atlas* atlas) {
if (event.type == sf::Event::MouseMoved) {
float x = event.mouseMove.x / 640.0f;
left->setAlpha((MathUtil::max(x, 0.5f) - 0.5f) * 2);
right->setAlpha((0.5 - MathUtil::min(x, 0.5f)) * 2);
right->setAlpha((0.5f - MathUtil::min(x, 0.5f)) * 2);
float y = event.mouseMove.y / 640.0f;
down->setAlpha((MathUtil::max(y, 0.5f) - 0.5f) * 2);
up->setAlpha((0.5 - MathUtil::min(y, 0.5f)) * 2);
up->setAlpha((0.5f - MathUtil::min(y, 0.5f)) * 2);
}
}
@ -453,10 +453,10 @@ void test (SkeletonData* skeletonData, Atlas* atlas) {
int main () {
DebugExtension dbgExtension;
SpineExtension::setInstance(&dbgExtension);
// SpineExtension::setInstance(&dbgExtension);
testcase(raptor, "data/raptor-pro.json", "data/raptor-pro.skel", "data/raptor.atlas", 0.5f);
testcase(test, "data/tank-pro.json", "data/tank-pro.skel", "data/tank.atlas", 1.0f);
// testcase(raptor, "data/raptor-pro.json", "data/raptor-pro.skel", "data/raptor.atlas", 0.5f);
// testcase(test, "data/tank-pro.json", "data/tank-pro.skel", "data/tank.atlas", 1.0f);
testcase(spineboy, "data/spineboy-ess.json", "data/spineboy-ess.skel", "data/spineboy.atlas", 0.6f);
testcase(owl, "data/owl-pro.json", "data/owl-pro.skel", "data/owl.atlas", 0.5f);
testcase(coin, "data/coin-pro.json", "data/coin-pro.skel", "data/coin.atlas", 0.5f);
@ -465,6 +465,6 @@ int main () {
testcase(raptor, "data/raptor-pro.json", "data/raptor-pro.skel", "data/raptor.atlas", 0.5f);
testcase(goblins, "data/goblins-pro.json", "data/goblins-pro.skel", "data/goblins.atlas", 1.4f);
testcase(stretchyman, "data/stretchyman-pro.json", "data/stretchyman-pro.skel", "data/stretchyman.atlas", 0.6f);
dbgExtension.reportLeaks();
// dbgExtension.reportLeaks();
return 0;
}

View File

@ -95,7 +95,7 @@ void SkeletonDrawable::draw(RenderTarget &target, RenderStates states) const {
sf::Vertex vertex;
Texture *texture = NULL;
for (int i = 0; i < skeleton->getSlots().size(); ++i) {
for (unsigned i = 0; i < skeleton->getSlots().size(); ++i) {
Slot &slot = *skeleton->getDrawOrder()[i];
Attachment *attachment = slot.getAttachment();
if (!attachment) continue;