from spine source code (#16330)

Related to:

* Github issue #16263
* Github issue #16294
This commit is contained in:
Ricardo Quesada 2016-08-07 18:47:05 -07:00 committed by minggo
parent f7464f8de5
commit e5b14733c8
1 changed files with 16 additions and 7 deletions

View File

@ -62,6 +62,7 @@ GLuint filter (spAtlasFilter filter) {
void _spAtlasPage_createTexture (spAtlasPage* self, const char* path) {
Texture2D* texture = Director::getInstance()->getTextureCache()->addImage(path);
CCASSERT(texture != nullptr, "Invalid image");
texture->retain();
Texture2D::TexParams textureParams = {filter(self->minFilter), filter(self->magFilter), wrap(self->uWrap), wrap(self->vWrap)};
@ -77,11 +78,19 @@ void _spAtlasPage_disposeTexture (spAtlasPage* self) {
}
char* _spUtil_readFile (const char* path, int* length) {
Data data = FileUtils::getInstance()->getDataFromFile(
FileUtils::getInstance()->fullPathForFilename(path).c_str());
if (data.isNull()) return 0;
*length = static_cast<int>(data.getSize());
char* bytes = MALLOC(char, *length);
memcpy(bytes, data.getBytes(), *length);
return bytes;
Data data = FileUtils::getInstance()->getDataFromFile(FileUtils::getInstance()->fullPathForFilename(path));
if (data.isNull()) return 0;
// avoid buffer overflow (int is shorter than ssize_t in certain platforms)
#if COCOS2D_VERSION >= 0x00031200
ssize_t tmpLen;
char *ret = (char*)data.takeBuffer(&tmpLen);
*length = static_cast<int>(tmpLen);
return ret;
#else
*length = static_cast<int>(data.getSize());
char* bytes = MALLOC(char, *length);
memcpy(bytes, data.getBytes(), *length);
return bytes;
#endif
}