Skip to content

Commit f1b2006

Browse files
committed
Make CCXMLParser thread safe (avoid re entry on same thread). github issue: #964
Fix orientation bug for ios8/xcode6 builds (by forcing the orientation of the statusbar, yes this is a weird hack to work around Apple's bug). github issue: #973
1 parent 072f1b8 commit f1b2006

File tree

3 files changed

+40
-13
lines changed

3 files changed

+40
-13
lines changed

cocos2d-tests-ios.xcodeproj/project.pbxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
B7EE69811818760700B983FE /* CCSprite9SliceTest.m in Sources */ = {isa = PBXBuildFile; fileRef = B7EE69801818760700B983FE /* CCSprite9SliceTest.m */; };
6767
B7EE69CF1819D82300B983FE /* CCLayoutTest.m in Sources */ = {isa = PBXBuildFile; fileRef = B7EE69CE1819D82300B983FE /* CCLayoutTest.m */; };
6868
B7EE6A28181B075E00B983FE /* CCSliderTest.m in Sources */ = {isa = PBXBuildFile; fileRef = B7EE6A27181B075E00B983FE /* CCSliderTest.m */; };
69+
D23CD73119CB881200C7EB14 /* CCShaders.metal in Resources */ = {isa = PBXBuildFile; fileRef = D3C1281C199D43E0005D2119 /* CCShaders.metal */; };
6970
D24FAEED198014C80043E27D /* GLKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D34CD3C118ABEE9C00D8E537 /* GLKit.framework */; };
7071
D28A2E181954F68200ADC03D /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D28A2E171954F68200ADC03D /* UIKit.framework */; };
7172
D28A2E1F1954F7E900ADC03D /* OpenGLES.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D28A2E1E1954F7E900ADC03D /* OpenGLES.framework */; };
@@ -78,7 +79,6 @@
7879
D34CD3C518ABF4AA00D8E537 /* CCRendererTests.m in Sources */ = {isa = PBXBuildFile; fileRef = D34CD3C418ABF4AA00D8E537 /* CCRendererTests.m */; };
7980
D3870C6018B440150033D885 /* SpritePerformanceTest.m in Sources */ = {isa = PBXBuildFile; fileRef = D3870C5F18B440150033D885 /* SpritePerformanceTest.m */; };
8081
D3B2A7E5187DD60B00406C5A /* CCBMFontTest.m in Sources */ = {isa = PBXBuildFile; fileRef = D3B2A7E4187DD60B00406C5A /* CCBMFontTest.m */; };
81-
D3C1281D199D43E0005D2119 /* CCShaders.metal in Sources */ = {isa = PBXBuildFile; fileRef = D3C1281C199D43E0005D2119 /* CCShaders.metal */; };
8282
D3C9C867188078B900C58900 /* CCSchedulerTest.m in Sources */ = {isa = PBXBuildFile; fileRef = D3C9C866188078B900C58900 /* CCSchedulerTest.m */; };
8383
D3D6CF5F18BD5F0500A51531 /* CCRendererTest.m in Sources */ = {isa = PBXBuildFile; fileRef = D3D6CF5E18BD5F0500A51531 /* CCRendererTest.m */; };
8484
D4AFE9131977100000261299 /* A Damn Mess.ttf in Resources */ = {isa = PBXBuildFile; fileRef = D4AFE8D81977100000261299 /* A Damn Mess.ttf */; };
@@ -867,6 +867,7 @@
867867
D4AFE9371977100000261299 /* konqa32-hd.png in Resources */,
868868
D4AFE9161977100000261299 /* arial-unicode-26.fnt in Resources */,
869869
B7E2621417E7D34D007067F0 /* Icon-Small.png in Resources */,
870+
D23CD73119CB881200C7EB14 /* CCShaders.metal in Resources */,
870871
D4AFE9361977100000261299 /* konqa32-hd.fnt in Resources */,
871872
D4AFE93C1977100000261299 /* larabie-16.plist in Resources */,
872873
D4AFE93A1977100000261299 /* larabie-16-hd.plist in Resources */,
@@ -944,7 +945,6 @@
944945
D3870C6018B440150033D885 /* SpritePerformanceTest.m in Sources */,
945946
B71B088217EA5B6A0082EBC0 /* CCScrollViewTest.m in Sources */,
946947
B7EE697918186D5200B983FE /* CCTextFieldTest.m in Sources */,
947-
D3C1281D199D43E0005D2119 /* CCShaders.metal in Sources */,
948948
B7E2620017E7D321007067F0 /* AppDelegate.m in Sources */,
949949
0E28FE1A197FCE4500F78989 /* CCCacheTest.m in Sources */,
950950
B77060AB1832E3310043CC67 /* CCTextureCacheTest.m in Sources */,

cocos2d/CCTMXXMLParser.m

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -192,16 +192,16 @@ - (void) dealloc
192192

193193
- (void) parseXMLData:(NSData*)data
194194
{
195-
NSXMLParser *parser = [[NSXMLParser alloc] initWithData:data];
196-
197-
// we'll do the parsing
198-
[parser setDelegate:self];
199-
[parser setShouldProcessNamespaces:NO];
200-
[parser setShouldReportNamespacePrefixes:NO];
201-
[parser setShouldResolveExternalEntities:NO];
202-
[parser parse];
203-
204-
NSAssert1( ![parser parserError], @"Error parsing TMX data: %@.", [NSString stringWithCharacters:[data bytes] length:[data length]] );
195+
NSXMLParser *parser = [[NSXMLParser alloc] initWithData:data];
196+
197+
// we'll do the parsing
198+
[parser setDelegate:self];
199+
[parser setShouldProcessNamespaces:NO];
200+
[parser setShouldReportNamespacePrefixes:NO];
201+
[parser setShouldResolveExternalEntities:NO];
202+
[parser parse];
203+
204+
NSAssert1( ![parser parserError], @"Error parsing TMX data: %@.", [NSString stringWithCharacters:[data bytes] length:[data length]] );
205205
}
206206

207207
- (void) parseXMLString:(NSString *)xmlString
@@ -252,7 +252,13 @@ -(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName name
252252

253253
_currentFirstGID = [[attributeDict objectForKey:@"firstgid"] intValue];
254254

255-
[self parseXMLFile:externalTilesetFilename];
255+
// since the xml parser is not reentrant, we need to invoke each child xml parser in its own queue
256+
dispatch_queue_t reentrantAvoidanceQueue = dispatch_queue_create("xmlParserSafeQueue", DISPATCH_QUEUE_SERIAL);
257+
dispatch_async(reentrantAvoidanceQueue, ^{
258+
[self parseXMLFile:externalTilesetFilename];
259+
});
260+
dispatch_sync(reentrantAvoidanceQueue, ^{ });
261+
256262
} else {
257263
CCTiledMapTilesetInfo *tileset = [CCTiledMapTilesetInfo new];
258264
tileset.name = [attributeDict objectForKey:@"name"];

cocos2d/Platforms/iOS/CCAppDelegate.m

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,27 @@ - (void) setupCocos2dWithOptions:(NSDictionary*)config
261261

262262
// make main window visible
263263
[window_ makeKeyAndVisible];
264+
265+
[self forceOrientation];
266+
}
267+
268+
// iOS8 hack around orientation bug
269+
-(void)forceOrientation
270+
{
271+
#if __CC_PLATFORM_IOS && defined(__IPHONE_8_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_8_0
272+
if([navController_.screenOrientation isEqual:CCScreenOrientationAll])
273+
{
274+
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationUnknown];
275+
}
276+
else if([navController_.screenOrientation isEqual:CCScreenOrientationPortrait])
277+
{
278+
[[UIApplication sharedApplication] setStatusBarOrientation:UIDeviceOrientationPortrait | UIDeviceOrientationPortraitUpsideDown];
279+
}
280+
else
281+
{
282+
[[UIApplication sharedApplication] setStatusBarOrientation:UIDeviceOrientationLandscapeLeft | UIDeviceOrientationLandscapeRight];
283+
}
284+
#endif
264285
}
265286

266287
// getting a call, pause the game

0 commit comments

Comments
 (0)