[c][cpp] Check if slot attachment is NULL when applying sequence timeline.

This commit is contained in:
Mario Zechner 2022-10-07 12:24:07 +02:00
parent 9d6afa1853
commit 88515ec1a9
5 changed files with 100 additions and 3 deletions

View File

@ -22,7 +22,7 @@ endif()
if((${SPINE_SFML}) OR (${CMAKE_CURRENT_BINARY_DIR} MATCHES "spine-sfml"))
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set(CMAKE_OSX_ARCHITECTURES x86_64;arm64)
set(CMAKE_OSX_ARCHITECTURES x86_64)
set(ONLY_ACTIVE_ARCH NO)
endif()
add_subdirectory(spine-c)

View File

@ -2016,7 +2016,8 @@ void _spSequenceTimeline_apply(spTimeline *timeline, spSkeleton *skeleton, float
slotAttachment = slot->attachment;
if (slotAttachment != self->attachment) {
switch (slot->attachment->type) {
if (slotAttachment == NULL) return;
switch (slotAttachment->type) {
case SP_ATTACHMENT_BOUNDING_BOX:
case SP_ATTACHMENT_CLIPPING:
case SP_ATTACHMENT_MESH:

View File

@ -72,7 +72,7 @@ void SequenceTimeline::apply(Skeleton &skeleton, float lastTime, float time, Vec
if (!slot->getBone().isActive()) return;
Attachment *slotAttachment = slot->getAttachment();
if (slotAttachment != _attachment) {
if (!slotAttachment->getRTTI().instanceOf(VertexAttachment::rtti) || ((VertexAttachment *) slotAttachment)->getTimelineAttachment() != _attachment) return;
if (slotAttachment == NULL || !slotAttachment->getRTTI().instanceOf(VertexAttachment::rtti) || ((VertexAttachment *) slotAttachment)->getTimelineAttachment() != _attachment) return;
}
Vector<float> &frames = this->_frames;

View File

@ -62,6 +62,7 @@ install(FILES ${INCLUDES} DESTINATION dist/include)
# Define spine-sfml example executable
add_executable(spine-sfml-cpp-example example/main.cpp)
add_executable(spine-sfml-cpp-test example/test.cpp)
# Link in SFML libraries and OS dependencies like OpenGL
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
@ -70,8 +71,10 @@ if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
find_library(SFML_WINDOW sfml-window PATHS ${SFML_DIR}/Frameworks)
find_library(SFML_GRAPHICS sfml-graphics PATHS ${SFML_DIR}/Frameworks)
target_link_libraries(spine-sfml-cpp-example ${SFML} ${SFML_SYSTEM} ${SFML_WINDOW} ${SFML_GRAPHICS})
target_link_libraries(spine-sfml-cpp-test ${SFML} ${SFML_SYSTEM} ${SFML_WINDOW} ${SFML_GRAPHICS})
elseif (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
target_link_libraries(spine-sfml-cpp-example sfml-graphics sfml-window sfml-system)
target_link_libraries(spine-sfml-cpp-test sfml-graphics sfml-window sfml-system)
else()
set(SFML_LIBS ${SFML_DIR}/lib)
target_link_libraries(spine-sfml-cpp-example ${SFML_LIBS}/sfml-main-d.lib)
@ -83,6 +86,15 @@ else()
target_link_libraries(spine-sfml-cpp-example opengl32)
target_link_libraries(spine-sfml-cpp-example gdi32)
target_link_libraries(spine-sfml-cpp-example winmm)
target_link_libraries(spine-sfml-cpp-test ${SFML_LIBS}/sfml-main-d.lib)
target_link_libraries(spine-sfml-cpp-test ${SFML_LIBS}/sfml-graphics-s-d.lib)
target_link_libraries(spine-sfml-cpp-test ${SFML_LIBS}/sfml-window-s-d.lib)
target_link_libraries(spine-sfml-cpp-test ${SFML_LIBS}/sfml-system-s-d.lib)
target_link_libraries(spine-sfml-cpp-test ${SFML_LIBS}/freetype.lib)
target_link_libraries(spine-sfml-cpp-test ${SFML_LIBS}/jpeg.lib)
target_link_libraries(spine-sfml-cpp-test opengl32)
target_link_libraries(spine-sfml-cpp-test gdi32)
target_link_libraries(spine-sfml-cpp-test winmm)
add_definitions(-DSFML_STATIC)
endif()
@ -90,6 +102,12 @@ endif()
add_custom_command(TARGET spine-sfml-cpp-example PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_CURRENT_LIST_DIR}/data $<TARGET_FILE_DIR:spine-sfml-cpp-example>/data)
add_custom_command(TARGET spine-sfml-cpp-test PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_CURRENT_LIST_DIR}/data $<TARGET_FILE_DIR:spine-sfml-cpp-example>/data)
target_link_libraries(spine-sfml-cpp-example spine-cpp)
target_link_libraries(spine-sfml-cpp-example spine-sfml-cpp)
target_link_libraries(spine-sfml-cpp-test spine-cpp)
target_link_libraries(spine-sfml-cpp-test spine-sfml-cpp)

View File

@ -0,0 +1,78 @@
/******************************************************************************
* Spine Runtimes License Agreement
* Last updated September 24, 2021. Replaces all prior versions.
*
* Copyright (c) 2013-2021, Esoteric Software LLC
*
* Integration of the Spine Runtimes into software or otherwise creating
* derivative works of the Spine Runtimes is permitted under the terms and
* conditions of Section 2 of the Spine Editor License Agreement:
* http://esotericsoftware.com/spine-editor-license
*
* Otherwise, it is permitted to integrate the Spine Runtimes into software
* or otherwise create derivative works of the Spine Runtimes (collectively,
* "Products"), provided that each user of the Products must obtain their own
* Spine Editor license and redistribution of the Products in any form must
* include this license and copyright notice.
*
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#include <SFML/Graphics.hpp>
#include <spine/Debug.h>
#include <spine/Log.h>
#include <spine/spine-sfml.h>
using namespace std;
using namespace spine;
DebugExtension dbgExtension(SpineExtension::getInstance());
void test() {
SFMLTextureLoader textureLoader;
Atlas atlas("data/bomb.atlas", &textureLoader);
SkeletonBinary loader(&atlas);
SkeletonData *skeletonData = loader.readSkeletonDataFile("data/bomb.skel");
SkeletonDrawable drawable(skeletonData);
drawable.setUsePremultipliedAlpha(true);
drawable.skeleton->setPosition(320, 590);
drawable.state->setAnimation(0, "expl", false);
drawable.skeleton->setSkin("mdl");
sf::RenderWindow window(sf::VideoMode(640, 640), "Spine SFML - Test");
window.setFramerateLimit(60);
sf::Event event;
sf::Clock deltaClock;
while (window.isOpen()) {
while (window.pollEvent(event))
if (event.type == sf::Event::Closed) window.close();
float delta = deltaClock.getElapsedTime().asSeconds();
deltaClock.restart();
drawable.update(delta);
window.clear();
window.draw(drawable);
window.display();
}
delete skeletonData;
}
int main() {
SpineExtension::setInstance(&dbgExtension);
test();
dbgExtension.reportLeaks();
return 0;
}