Skip to content

Commit 4e9cc94

Browse files
committed
Adding class guards to +initialize methods.
1 parent 89cc197 commit 4e9cc94

File tree

5 files changed

+18
-0
lines changed

5 files changed

+18
-0
lines changed

cocos2d/CCDrawNode.m

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ @implementation CCDrawNode {
5656

5757
+(void)initialize
5858
{
59+
// +initialize may be called due to loading a subclass.
60+
if(self != [CCDrawNode class]) return;
61+
5962
SHADER = [[CCShader alloc] initWithFragmentShaderSource:FRAGMENT_SHADER_SOURCE];
6063
}
6164

cocos2d/CCRenderer.m

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,9 @@ -(instancetype)initWithOptions:(NSDictionary *)options
170170

171171
+(void)initialize
172172
{
173+
// +initialize may be called due to loading a subclass.
174+
if(self != [CCBlendMode class]) return;
175+
173176
CCBLENDMODE_CACHE = [[CCBlendModeCache alloc] init];
174177

175178
// Add the default modes
@@ -276,6 +279,9 @@ @implementation CCRenderState {
276279

277280
+(void)initialize
278281
{
282+
// +initialize may be called due to loading a subclass.
283+
if(self != [CCRenderState class]) return;
284+
279285
CCRENDERSTATE_CACHE = [[CCRenderStateCache alloc] init];
280286
CCRENDERSTATE_DEBUGCOLOR = [[self alloc] initWithBlendMode:CCBLEND_DISABLED shader:[CCShader positionColorShader] shaderUniforms:@{}];
281287
}

cocos2d/CCShader.m

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,9 @@ -(instancetype)copyWithZone:(NSZone *)zone
449449

450450
+(void)initialize
451451
{
452+
// +initialize may be called due to loading a subclass.
453+
if(self != [CCShader class]) return;
454+
452455
CC_SHADER_CACHE = [[CCShaderCache alloc] init];
453456

454457
// Setup the builtin shaders.

cocos2d/CCTexture.m

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,9 @@ @implementation CCTexture
163163

164164
+(void)initialize
165165
{
166+
// +initialize may be called due to loading a subclass.
167+
if(self != [CCTexture class]) return;
168+
166169
CCTextureNone = [self alloc];
167170
CCTextureNone->_name = 0;
168171
CCTextureNone->_format = CCTexturePixelFormat_RGBA8888;

cocos2d/Support/CCColor.m

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,9 @@ - (CCColor*) interpolateTo:(CCColor *) toColor alpha:(float) t
237237

238238
+(void)initialize
239239
{
240+
// +initialize may be called due to loading a subclass.
241+
if(self != [CCColor class]) return;
242+
240243
BLACK_COLOR = [CCColor colorWithRed:0 green:0 blue:0 alpha:1];
241244
DARK_GRAY_COLOR = [CCColor colorWithWhite:1.0/3.0 alpha:1];
242245
LIGHT_GRAY_COLOR = [CCColor colorWithWhite:2.0/3.0 alpha:1];

0 commit comments

Comments
 (0)