I have two classes, using Box2d,Cocos2d.
Construct.mm and Level1.mm
Construct contains all the methods for creating different objects in the box2d physics engine
Level1 contains the information on the plotting of objects.
In the construct implementation I have:
Construct.mm
-(void) someInitMethod{
Level1 *level1 = [[Level1 alloc] init];
[level1 mapping];
}
-(void) someCreateRectMethod:(argue)ments{
//create rect
}
In the Level1 implementation I have:
Level1.mm
-(void) mapping{
Construct *constr;
if (constr == nil) constr = [[Construct alloc] init];
[constr someCreateRectMethod:(argue)ments];
}
Now, I know the allocation of Level1 *level1 is working fine. It jumps to -(void)mapping{
}.
My problem is in creating the Construct *constr object and initialising it. Without the if(constr == nil) statement. The simulator will die straight away, before even posting any error report.
If i put the if(constr == nil) and then try to call [constr someCreateRectMethod:arguement];
The console reports:
* Terminating app due to uncaught exception
‘NSInvalidArgumentException’, reason:
‘-[Level1 someCreateRectMethod:]: unrecognized
selector sent to instance 0x5557fc0’
I think this is because its not allocing, therefore trying to send to self (Level1) rather than Construct.
Why isnt my Construct *constr class object not allocing? Like I said, no error reporting it occurring.. I have imported the Construct.h file. I’ve spent the last 4 hours trying to get this to work.
EDIT
I just made Layer 1 inherit from Construct. And instead of calling [constr someCreateRectMethod]; I simply call [super someCreateRectMethod];
This should theoretically work, but Simulator crashes and no error reporting is logged..
Once again, Thanks for your time.
Oliver.
You probably don’t end up creating constr – the initial value is undefined and therefore very unlikely to be nil. If your code otherwise terminates at [[constr alloc] init] then it seems likely that you’ve failed to subclass NSObject (which you should) and not implemented init (which you often want to).