Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Texture & TextureCache: uses current thread and cocos2d thread
Texture2D: uses current thread for glDeleteTexture() TextureCache: uses cocos2d thread to invoke async callback() These bugs were causing kernel panics on Mac
- Loading branch information
1 parent
d92cdff
commit b6c6cb4
Showing
8 changed files
with
148 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* cocos2d for iPhone | ||
* | ||
* http://www.cocos2d-iphone.org | ||
* | ||
* | ||
* Idea taken from: http://stackoverflow.com/a/3940757 | ||
* | ||
*/ | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
@interface NSThread (sendBlockToBackground) | ||
/** performs a block on the thread. It won't wait until it is done. */ | ||
- (void) performBlock:(void (^)(void))block; | ||
|
||
/** performs a block on the thread. */ | ||
- (void) performBlock:(void (^)(void))block waitUntilDone:(BOOL)wait; | ||
|
||
/** performs a block on the thread. */ | ||
- (void) performBlock:(void (^)(id param))block withObject:(id)object waitUntilDone:(BOOL)wait; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* cocos2d for iPhone | ||
* | ||
* http://www.cocos2d-iphone.org | ||
* | ||
* | ||
* Idea taken from: http://stackoverflow.com/a/3940757 | ||
* | ||
*/ | ||
|
||
|
||
#import "NSThread+performBlock.h" | ||
#import "../ccMacros.h" | ||
|
||
typedef void (^BlockWithParam)(id param); | ||
@interface CCObjectWith2Params : NSObject | ||
{ | ||
@public | ||
BlockWithParam block; | ||
id param; | ||
} | ||
@property (nonatomic,copy) id block; | ||
@property (nonatomic,readwrite,retain) id param; | ||
@end | ||
|
||
@implementation CCObjectWith2Params | ||
@synthesize block, param; | ||
- (void)dealloc { | ||
CCLOG(@"cocos2d: deallocing %@", self); | ||
[block release]; | ||
[param release]; | ||
|
||
[super dealloc]; | ||
} | ||
@end | ||
|
||
@implementation NSThread (sendBlockToBackground) | ||
|
||
- (void) performBlock: (void (^)(void))block; | ||
{ | ||
return [self performBlock:block waitUntilDone:NO]; | ||
} | ||
|
||
- (void) performBlock:(void (^)(void))block waitUntilDone:(BOOL)wait | ||
{ | ||
[self performSelector:@selector(executeBlock:) | ||
onThread:self | ||
withObject: block | ||
waitUntilDone: wait]; | ||
} | ||
|
||
- (void) performBlock:(void (^)(id param))block withObject:(id)object waitUntilDone:(BOOL)wait | ||
{ | ||
CCObjectWith2Params * obj = [[CCObjectWith2Params alloc] init]; | ||
obj.block = block; | ||
obj.param = object; | ||
|
||
[obj autorelease]; | ||
|
||
[self performSelector:@selector(executeBlock2:) | ||
onThread:self | ||
withObject:obj | ||
waitUntilDone:wait]; | ||
} | ||
|
||
- (void) executeBlock: (void (^)(void))block; | ||
{ | ||
block(); | ||
} | ||
|
||
- (void) executeBlock2:(CCObjectWith2Params*)object | ||
{ | ||
BlockWithParam block = object.block; | ||
block( object.param ); | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters