DNESS / cocos2d-iphone

Automatically exported from code.google.com/p/cocos2d-iphone
1 stars 0 forks source link

NSAssert of name passed in removeChildByName always causes exception #1509

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Remove a sprite by using [self removeChildByName:@"testName"];

What is the expected output? What do you see instead?
Expected to see sprite removed.  However every time, no matter how the name of 
the sprite was formatted, the NSAssert in the removeChildByName function 
(CCNode.m, line 723) would cause an exception.  A CCLOG of the name variable 
just before the NSAssert showed name had a the expected value in it.

What cocos2d version are you using ?
V3

What iOS / Mac SDK are you using ?
iOS 7.0

Debug or Release ?
Debug

Which target device / target OS are you using ?
iPad/iOS 7.0

iOS only: Does this happens on device ? or on the simulator ? or on both ?
Both

Mac only: x86 or i386 ?

Please provide any additional information below.
If appears that the NSAssert is being used to make sure the name variable is 
not blank...however NSAssert's purpose is to "Generates an assertion if a given 
condition is false."  So if you are checking !name, the condition is always 
false if it contains a value.  So it should be NSAssert(name, @"Invalid 
value"); or to be safe just check directly for nil NSAssert(name != nil, 
@"Invalid value");.  The later is what I did to fix the problem and have had no 
issues since.

Original issue reported on code.google.com by mdol...@gmail.com on 28 Jan 2014 at 8:28

GoogleCodeExporter commented 8 years ago
Surely an empty string is as bad as a nul pointer, so the assertion should be 
NSAssert([name length] > 0, @"Invalid value");

Original comment by trojan...@gmail.com on 19 Feb 2014 at 12:52