[cocos2d-objc] Closes #442, loading sprites concurrently may crash in spSkeletonData_readSkeletonDataFile and spAtlas_createFromFile due to the underlying Cocos2D-ObjC implementations of spUtils_readFile and _spAtlasPage_createTexture not being thread safe

This commit is contained in:
badlogic 2016-07-18 17:42:01 +02:00
parent ffafd67873
commit 1d73c3e220
2 changed files with 16 additions and 4 deletions

View File

@ -39,6 +39,7 @@
bool _debugSlots;
bool _debugBones;
bool _premultipliedAlpha;
bool _skipVisibilityCheck;
ccBlendFunc _blendFunc;
CCDrawNode* _drawNode;
bool _ownsSkeletonData;
@ -85,6 +86,7 @@
@property (nonatomic, readonly) spSkeleton* skeleton;
@property (nonatomic) bool debugSlots;
@property (nonatomic) bool debugBones;
@property (nonatomic) bool skipVisibilityCheck;
@property (nonatomic) spBone* rootBone;
@end

View File

@ -99,7 +99,11 @@ static const unsigned short quadTriangles[6] = {0, 1, 2, 2, 3, 0};
spSkeletonJson* json = spSkeletonJson_create(atlas);
json->scale = scale;
spSkeletonData* skeletonData = spSkeletonJson_readSkeletonDataFile(json, [skeletonDataFile UTF8String]);
spSkeletonData* skeletonData = nil;
@synchronized(self.class) {
spSkeletonJson_readSkeletonDataFile(json, [skeletonDataFile UTF8String]);
}
NSAssert(skeletonData, ([NSString stringWithFormat:@"Error reading skeleton data file: %@\nError: %s", skeletonDataFile, json->error]));
spSkeletonJson_dispose(json);
if (!skeletonData) return 0;
@ -113,13 +117,19 @@ static const unsigned short quadTriangles[6] = {0, 1, 2, 2, 3, 0};
self = [super init];
if (!self) return nil;
_atlas = spAtlas_createFromFile([atlasFile UTF8String], 0);
@synchronized(self.class) {
_atlas = spAtlas_createFromFile([atlasFile UTF8String], 0);
}
NSAssert(_atlas, ([NSString stringWithFormat:@"Error reading atlas file: %@", atlasFile]));
if (!_atlas) return 0;
spSkeletonJson* json = spSkeletonJson_create(_atlas);
json->scale = scale;
spSkeletonData* skeletonData = spSkeletonJson_readSkeletonDataFile(json, [skeletonDataFile UTF8String]);
spSkeletonData* skeletonData;
@synchronized(self.class) {
skeletonData = spSkeletonJson_readSkeletonDataFile(json, [skeletonDataFile UTF8String]);
}
NSAssert(skeletonData, ([NSString stringWithFormat:@"Error reading skeleton data file: %@\nError: %s", skeletonDataFile, json->error]));
spSkeletonJson_dispose(json);
if (!skeletonData) return 0;
@ -217,7 +227,7 @@ static const unsigned short quadTriangles[6] = {0, 1, 2, 2, 3, 0};
CGSize size = texture.contentSize;
GLKVector2 center = GLKVector2Make(size.width / 2.0, size.height / 2.0);
GLKVector2 extents = GLKVector2Make(size.width / 2.0, size.height / 2.0);
if (CCRenderCheckVisbility(transform, center, extents)) {
if (_skipVisibilityCheck || CCRenderCheckVisbility(transform, center, extents)) {
CCRenderBuffer buffer = [renderer enqueueTriangles:(trianglesCount / 3) andVertexes:verticesCount withState:self.renderState globalSortOrder:0];
for (int i = 0; i * 2 < verticesCount; ++i) {
CCVertex vertex;