Skip to content

Commit ae2ca0f

Browse files
author
Thayer J Andrews
committed
CCEffects - Fix assertion failures when texture + normal map are missing
Under certain circumstances, the effect renderer could allocate a render target with 0 x 0 dimensions which resulted in a GL error and assertion failure. Those circumstances were: - Sprite has no texture - Sprite has no normal map - An unstitchable effect stack is attached to the sprite This is now fixed in the following ways: - The effect renderer's render target dimensions now come from sprite.contentSize not just sprite.texture.contentSize. This means that if the sprite has a normal map but not a texture, the resulting size will come from the normal map instead of being 0 x 0 as it was before. - If the computed render target size is still 0 x 0, it is bumped to 1 x 1. - An assertion on 0 x 0 dimensions is added to the render target allocation code so this sort of error is caught higher up in the stack in the future.
1 parent 7a41aaa commit ae2ca0f

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

cocos2d/CCEffectNode.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ -(void)draw:(CCRenderer *)renderer transform:(const GLKMatrix4 *)transform
168168

169169
if (_effect)
170170
{
171-
_effectRenderer.contentSize = self.texture.contentSize;
171+
_effectRenderer.contentSize = self.contentSize;
172172
if ([_effect prepareForRendering] == CCEffectPrepareSuccess)
173173
{
174174
// Preparing an effect for rendering can modify its uniforms

cocos2d/CCEffectRenderer.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,9 @@ -(void)drawSprite:(CCSprite *)sprite withEffect:(CCEffect *)effect uniforms:(NSM
191191
renderPass.transform = GLKMatrix4MakeOrtho(0.0f, _contentSize.width, 0.0f, _contentSize.height, -1024.0f, 1024.0f);
192192

193193
CGSize rtSize = CGSizeMake(_contentSize.width * _contentScale, _contentSize.height * _contentScale);
194+
rtSize.width = (rtSize.width <= 1.0f) ? 1.0f : rtSize.width;
195+
rtSize.height = (rtSize.height <= 1.0f) ? 1.0f : rtSize.height;
196+
194197
rt = [self renderTargetWithSize:rtSize];
195198

196199
[renderPass begin:previousPassTexture];
@@ -249,6 +252,8 @@ - (void)restoreRenderTargetWithRenderer:(CCRenderer *)renderer
249252

250253
- (CCEffectRenderTarget *)renderTargetWithSize:(CGSize)size
251254
{
255+
NSAssert((size.width > 0.0f) && (size.height > 0.0f), @"Render targets must have non-zero dimensions.");
256+
252257
// If there is a free render target available for use, return that one. If
253258
// not, create a new one and return that.
254259
CCEffectRenderTarget *rt = nil;

cocos2d/CCSprite.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ -(void)draw:(CCRenderer *)renderer transform:(const GLKMatrix4 *)transform;
369369

370370
if (_effect)
371371
{
372-
_effectRenderer.contentSize = self.texture.contentSize;
372+
_effectRenderer.contentSize = self.contentSize;
373373
if ([self.effect prepareForRendering] == CCEffectPrepareSuccess)
374374
{
375375
// Preparing an effect for rendering can modify its uniforms

0 commit comments

Comments
 (0)