mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-02-13 02:28:44 +08:00
[cpp] Return error if skeleton version doesn't match runtime version. See #1998
This commit is contained in:
parent
ba1de97f04
commit
0e122e1877
@ -5,6 +5,7 @@
|
||||
* Support for sequences.
|
||||
* Support for `shortestRotation` in animation state. See https://github.com/esotericsoftware/spine-runtimes/issues/2027.
|
||||
* Added CMake parameter `SPINE_SANITIZE` which will enable sanitizers on macOS and Linux.
|
||||
* Added `SPINE_MAJOR_VERSION`, `SPINE_MINOR_VERSION`, and `SPINE_VERSION_STRING`. Parsing skeleton .JSON and .skel files will report an error if the skeleton version does not match the runtime version.
|
||||
* **Breaking changes**
|
||||
* `spRegionAttachment` and `spMeshAttachment` now contain a `spTextureRegion*` instead of encoding region fields directly.
|
||||
* `sp_AttachmentLoader_newRegionAttachment()` and `spAttachmentLoader_newMeshAttachment()` now take an additional `Sequence*` parameter.
|
||||
@ -24,6 +25,7 @@
|
||||
* Support for sequences.
|
||||
* Support for `shortestRotation` in animation state. See https://github.com/esotericsoftware/spine-runtimes/issues/2027.
|
||||
* Added CMake parameter `SPINE_SANITIZE` which will enable sanitizers on macOS and Linux.
|
||||
* Added `SPINE_MAJOR_VERSION`, `SPINE_MINOR_VERSION`, and `SPINE_VERSION_STRING`. Parsing skeleton .JSON and .skel files will report an error if the skeleton version does not match the runtime version.
|
||||
* **Breaking changes**
|
||||
* `RegionAttachment` and `MeshAttachment` now contain a `TextureRegion*` instead of encoding region fields directly.
|
||||
* `AttachmentLoader::newRegionAttachment()` and `AttachmentLoader::newMeshAttachment()` now take an additional `Sequence*` parameter.
|
||||
|
||||
@ -182,6 +182,14 @@ namespace spine {
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool startsWith(const String &needle) {
|
||||
if (needle.length() > length()) return false;
|
||||
for (int i = 0; i < (int)needle.length(); i++) {
|
||||
if (buffer()[i] != needle.buffer()[i]) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
friend bool operator==(const String &a, const String &b) {
|
||||
if (a._buffer == b._buffer) return true;
|
||||
if (a._length != b._length) return false;
|
||||
|
||||
37
spine-cpp/spine-cpp/include/spine/Version.h
Normal file
37
spine-cpp/spine-cpp/include/spine/Version.h
Normal file
@ -0,0 +1,37 @@
|
||||
/******************************************************************************
|
||||
* 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.
|
||||
*****************************************************************************/
|
||||
|
||||
#ifndef SPINE_VERTEXEFFECT_H_
|
||||
#define SPINE_VERTEXEFFECT_H_
|
||||
|
||||
#define SPINE_MAJOR_VERSION 4
|
||||
#define SPINE_MINOR_VERSION 1
|
||||
#define SPINE_VERSION_STRING "4.1"
|
||||
|
||||
#endif
|
||||
@ -72,7 +72,8 @@
|
||||
#include <spine/TransformConstraintData.h>
|
||||
#include <spine/TransformConstraintTimeline.h>
|
||||
#include <spine/TranslateTimeline.h>
|
||||
#include "spine/SequenceTimeline.h"
|
||||
#include <spine/SequenceTimeline.h>
|
||||
#include <spine/Version.h>
|
||||
|
||||
using namespace spine;
|
||||
|
||||
@ -121,6 +122,13 @@ SkeletonData *SkeletonBinary::readSkeletonData(const unsigned char *binary, cons
|
||||
char *skeletonDataVersion = readString(input);
|
||||
skeletonData->_version.own(skeletonDataVersion);
|
||||
|
||||
if (!skeletonData->_version.startsWith(SPINE_VERSION_STRING)) {
|
||||
char errorMsg[255];
|
||||
sprintf(errorMsg, "Skeleton version %s does not match runtime version %s", skeletonData->_version.buffer(), SPINE_VERSION_STRING);
|
||||
setError(errorMsg, "");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
skeletonData->_x = readFloat(input);
|
||||
skeletonData->_y = readFloat(input);
|
||||
skeletonData->_width = readFloat(input);
|
||||
|
||||
@ -72,7 +72,8 @@
|
||||
#include <spine/TransformConstraintTimeline.h>
|
||||
#include <spine/TranslateTimeline.h>
|
||||
#include <spine/Vertices.h>
|
||||
#include "spine/SequenceTimeline.h"
|
||||
#include <spine/SequenceTimeline.h>
|
||||
#include <spine/Version.h>
|
||||
|
||||
using namespace spine;
|
||||
|
||||
@ -153,6 +154,12 @@ SkeletonData *SkeletonJson::readSkeletonData(const char *json) {
|
||||
if (skeleton) {
|
||||
skeletonData->_hash = Json::getString(skeleton, "hash", 0);
|
||||
skeletonData->_version = Json::getString(skeleton, "spine", 0);
|
||||
if (!skeletonData->_version.startsWith(SPINE_VERSION_STRING)) {
|
||||
char errorMsg[255];
|
||||
sprintf(errorMsg, "Skeleton version %s does not match runtime version %s", skeletonData->_version.buffer(), SPINE_VERSION_STRING);
|
||||
setError(NULL, errorMsg, "");
|
||||
return NULL;
|
||||
}
|
||||
skeletonData->_x = Json::getFloat(skeleton, "x", 0);
|
||||
skeletonData->_y = Json::getFloat(skeleton, "y", 0);
|
||||
skeletonData->_width = Json::getFloat(skeleton, "width", 0);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user