diff --git a/spine-c/spine-c/src/spine/Animation.c b/spine-c/spine-c/src/spine/Animation.c index 2135a8704..65b02a3d1 100644 --- a/spine-c/spine-c/src/spine/Animation.c +++ b/spine-c/spine-c/src/spine/Animation.c @@ -2042,6 +2042,7 @@ void _spSequenceTimeline_apply(spTimeline *timeline, spSkeleton *skeleton, float if (self->attachment->type == SP_ATTACHMENT_REGION) sequence = ((spRegionAttachment *) self->attachment)->sequence; if (self->attachment->type == SP_ATTACHMENT_MESH) sequence = ((spMeshAttachment *) self->attachment)->sequence; + if (!sequence) return; index = modeAndIndex >> 4; count = sequence->regions->size; mode = modeAndIndex & 0xf; @@ -2056,7 +2057,7 @@ void _spSequenceTimeline_apply(spTimeline *timeline, spSkeleton *skeleton, float break; case SP_SEQUENCE_MODE_PINGPONG: { int n = (count << 1) - 2; - index %= n; + index = n == 0 ? 0 : index % n; if (index >= count) index = n - index; break; } @@ -2068,7 +2069,7 @@ void _spSequenceTimeline_apply(spTimeline *timeline, spSkeleton *skeleton, float break; case SP_SEQUENCE_MODE_PINGPONGREVERSE: { int n = (count << 1) - 2; - index = (index + count - 1) % n; + index = n == 0 ? 0 : (index + count - 1) % n; if (index >= count) index = n - index; } } diff --git a/spine-cpp/spine-cpp/src/spine/SequenceTimeline.cpp b/spine-cpp/spine-cpp/src/spine/SequenceTimeline.cpp index 2740de80b..652def340 100644 --- a/spine-cpp/spine-cpp/src/spine/SequenceTimeline.cpp +++ b/spine-cpp/spine-cpp/src/spine/SequenceTimeline.cpp @@ -89,6 +89,7 @@ void SequenceTimeline::apply(Skeleton &skeleton, float lastTime, float time, Vec Sequence *sequence = NULL; if (_attachment->getRTTI().instanceOf(RegionAttachment::rtti)) sequence = ((RegionAttachment *) _attachment)->getSequence(); if (_attachment->getRTTI().instanceOf(MeshAttachment::rtti)) sequence = ((MeshAttachment *) _attachment)->getSequence(); + if (!sequence) return; int index = modeAndIndex >> 4, count = (int) sequence->getRegions().size(); int mode = modeAndIndex & 0xf; if (mode != SequenceMode::hold) { @@ -102,7 +103,7 @@ void SequenceTimeline::apply(Skeleton &skeleton, float lastTime, float time, Vec break; case SequenceMode::pingpong: { int n = (count << 1) - 2; - index %= n; + index = n == 0 ? 0 : index % n; if (index >= count) index = n - index; break; } @@ -114,10 +115,10 @@ void SequenceTimeline::apply(Skeleton &skeleton, float lastTime, float time, Vec break; case SequenceMode::pingpongReverse: { int n = (count << 1) - 2; - index = (index + count - 1) % n; + index = n == 0 ? 0 : (index + count - 1) % n; if (index >= count) index = n - index; } } } slot->setSequenceIndex(index); -} \ No newline at end of file +}