Skip to content

Commit 59754e6

Browse files
committed
Hop back to the Cocos "main" thread instead of the real one
1 parent b66ab58 commit 59754e6

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

cocos2d/CCPackageManager.m

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#import "ccMacros.h"
1010
#import "CCPackageHelper.h"
1111
#import "CCPackage_private.h"
12+
#import "CCDirector.h"
1213

1314

1415
@interface CCPackageManager()
@@ -338,7 +339,7 @@ - (void)downloadProgressOfPackage:(CCPackage *)package downloadedBytes:(NSUInteg
338339

339340
- (void)unzipFinished:(CCPackageUnzipper *)packageUnzipper
340341
{
341-
[self runOnMainQueue:^
342+
[self runOnCocosThread:^
342343
{
343344
[self removeDownloadFile:packageUnzipper.package];
344345

@@ -362,7 +363,7 @@ - (void)unzipFinished:(CCPackageUnzipper *)packageUnzipper
362363

363364
- (void)unzipFailed:(CCPackageUnzipper *)packageUnzipper error:(NSError *)error
364365
{
365-
[self runOnMainQueue:^
366+
[self runOnCocosThread:^
366367
{
367368
[_unzipTasks removeObject:packageUnzipper];
368369

@@ -372,7 +373,7 @@ - (void)unzipFailed:(CCPackageUnzipper *)packageUnzipper error:(NSError *)error
372373

373374
- (void)unzipProgress:(CCPackageUnzipper *)packageUnzipper unzippedBytes:(NSUInteger)unzippedBytes totalBytes:(NSUInteger)totalBytes
374375
{
375-
[self runOnMainQueue:^
376+
[self runOnCocosThread:^
376377
{
377378
if ([_delegate respondsToSelector:@selector(packageUnzippingProgress:unzippedBytes:totalBytes:)])
378379
{
@@ -752,15 +753,15 @@ - (void)request:(NSMutableURLRequest *)request ofPackage:(CCPackage *)package
752753
}
753754
}
754755

755-
- (void)runOnMainQueue:(dispatch_block_t)block
756+
- (void)runOnCocosThread:(dispatch_block_t)block
756757
{
757-
if ([NSThread isMainThread])
758+
if ([[NSThread currentThread] isEqual:[[CCDirector sharedDirector] runningThread]])
758759
{
759760
block();
760761
}
761762
else
762763
{
763-
dispatch_sync(dispatch_get_main_queue(), block);
764+
[self performSelector:_cmd onThread:[[CCDirector sharedDirector] runningThread] withObject:block waitUntilDone:YES];
764765
}
765766
}
766767

0 commit comments

Comments
 (0)