Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

idelovski

macrumors regular
Original poster
Sep 11, 2008
235
0
I have a problem in simulator that started today and it just won't go away. My app crashes with NSInvalidArgumentException, unrecognized selector but the method exists and it all works just fine on device (both an iPhone and an iPod).

Did everything I could - rebuild everything several times, erased my app from simulator, did "Reset content and settings" and nothing helped. I even brought several backups from yesterday and the day before, but nothing helped.


*** -[NetworkController initWithMainViewController:]: unrecognized selector sent to instance 0x4c39e10
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NetworkController initWithMainViewController:]: unrecognized selector sent to instance 0x4c39e10'
 

amorya

macrumors 6502
Jun 17, 2007
252
7
Could be a pesky memory management bug. Assuming it's always crashing on the same line of code, can you NSLog(@"%@", NetworkController); on the line before? That'll tell you whether the variable points to an instance of the class you think it does.

Amorya
 

idelovski

macrumors regular
Original poster
Sep 11, 2008
235
0
Just did NSlog() and to do that I broke up my init method into its parts. The init method that was crashing is not doing much so I'm calling now the regular -init.

Code:
   // NetworkController  *tmpNetController = [[NetworkController alloc] initWithMainViewController:self];

   NetworkController  *tmpNetController = [NetworkController alloc];
   NSLog (@"Ptr: %p, Obj: %@", tmpNetController, tmpNetController);
   tmpNetController = [tmpNetController init];
   tmpNetController.mainViewController = self;
   ...

Ptr: 0x4c39df0, Obj: <NetworkController: 0x4c39df0>
*** Assertion failure in -[NSThread performOneway:result:withTarget:selector:], /SourceCache/Message_Sim/Message-428.11/Utilities.subproj/MainThread.m:71
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Couldn't find signature for target 0x4c39df0 selector _registerForNotificationKeys:patterns:'


Then I moved that line before anything else in my application, in -viewDidLoad for the initial screen:

Code:
- (void)viewDidLoad
{
   [super viewDidLoad];
   
   NetworkController  *tmpNetController = [[NetworkController alloc] initWithMainViewController:self];
   ...

And it crashed with the same "unrecognized selector" message. On that main screen I have four other buttons that call other parts of the application and it all works just fine. The only thing that fails is this alloc/init for the NewtworkController and only in simulator.

I think I'm in real trouble! ;)
 

chown33

Moderator
Staff member
Aug 9, 2009
10,740
8,416
A sea of green
Code:
   // NetworkController  *tmpNetController = [[NetworkController alloc] initWithMainViewController:self];

   NetworkController  *tmpNetController = [NetworkController alloc];
   NSLog (@"Ptr: %p, Obj: [COLOR="Red"]%@[/COLOR]", tmpNetController, tmpNetController);
   tmpNetController = [tmpNetController init];
   tmpNetController.mainViewController = self;
   ...

The red-hilited "%@" causes tmpNetController's -description method to be invoked (read the reference doc for print formatting). Since the object has only been alloc'ed, but not yet init'ed, it is quite possible, or even quite likely, that the object is not yet in a valid condition to respond to -description.

You don't show the superclass of of NetworkController, so there's no way to tell how badly it's going to respond, but it's almost certainly going to respond badly.
 

idelovski

macrumors regular
Original poster
Sep 11, 2008
235
0
The red-hilited "%@" causes tmpNetController's -description method to be invoked (read the reference doc for print formatting). Since the object has only been alloc'ed, but not yet init'ed, it is quite possible, or even quite likely, that the object is not yet in a valid condition to respond to -description.

Well maybe, but NSLog() gives me the right name of the class, and most importantly, init method crashes even without that NSLog() call.

You don't show the superclass of of NetworkController, ...

NSObject.
 

JustSomeDude

macrumors regular
Apr 10, 2010
104
0
Google reveals somebody having a similar problem because of an preexisting NetworkController class in the MessageUI framework (I'm guessing that you might be using this based on the assertion failure) - they fixed the issue by renaming their class.

see:
http://www.iphonedevsdk.com/forum/iphone-sdk-development/34915-problem-sdk3-framework-messageui.html

Edit: Although, I am curious why it only happens in the simulator since you would think you would still be creating the wrong object on the actual device(I am assume that is the actual issue in the simulator). Maybe conditional compile directives in the framework that are only applicable to the simulator in this case?
 

idelovski

macrumors regular
Original poster
Sep 11, 2008
235
0
OMG, changed the name from NetworkController to NetworkingController now and all works ok. I was sure Apple always adds prefix to their stuff. I guess I was wrong.
 

Thomas Harte

macrumors 6502
Nov 30, 2005
400
4
OMG, changed the name from NetworkController to NetworkingController now and all works ok. I was sure Apple always adds prefix to their stuff. I guess I was wrong.

They don't; we've also tripped over undocumented internal class names. What they do is strongly recommend that you use prefixes.
 

chown33

Moderator
Staff member
Aug 9, 2009
10,740
8,416
A sea of green
Although, I am curious why it only happens in the simulator since you would think you would still be creating the wrong object on the actual device(I am assume that is the actual issue in the simulator). Maybe conditional compile directives in the framework that are only applicable to the simulator in this case?
Maybe NetworkController only exists on the Simulator SDK. It doesn't have to be conditional compilation. There is no reason to expect that the code needed to run the simulator is 100% identical in name to code on the device. Remember that the simulator is a bunch of adapter classes layered on top of the existing Mac OS X classes, that make them appear to be something they aren't.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.