Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > NSPopupButton.addItemWithTitle

NSPopupButton.addItemWithTitle
Thread Tools
absmiths
Mac Elite
Join Date: Sep 2000
Location: Edmond, OK USA
Status: Offline
Reply With Quote
Apr 2, 2004, 12:45 PM
 
Does anyone know why this method would cause a SIGSEGV? This line of code:

[gender addItemWithTitle: "@Select One"];

Every single time causes this error. I checked for a null control, and it is definitely not null. Do I need to do some initialization first? This seems rather inexplicable.
     
Uncle Skeleton
Addicted to MacNN
Join Date: Nov 2002
Location: Rockville, MD
Status: Offline
Reply With Quote
Apr 2, 2004, 01:01 PM
 
you have your @ and " transposed

also I believe it's safe (but bad style) to send messages to nil. They just get ignored
     
Catfish_Man
Mac Elite
Join Date: Aug 2001
Status: Offline
Reply With Quote
Apr 2, 2004, 02:04 PM
 
Originally posted by Uncle Skeleton:
you have your @ and " transposed

also I believe it's safe (but bad style) to send messages to nil. They just get ignored
Apple added a compiler flag in 10.3 to make stuff faster if you don't do that, so it's probably a good idea not to (f-no-nil-receivers).
     
absmiths  (op)
Mac Elite
Join Date: Sep 2000
Location: Edmond, OK USA
Status: Offline
Reply With Quote
Apr 2, 2004, 02:55 PM
 
Originally posted by Uncle Skeleton:
you have your @ and " transposed

also I believe it's safe (but bad style) to send messages to nil. They just get ignored
Hey thanks for pointing that out! Now I just have to figure out why I get periodic SIGBUSs.
     
absmiths  (op)
Mac Elite
Join Date: Sep 2000
Location: Edmond, OK USA
Status: Offline
Reply With Quote
Apr 2, 2004, 03:02 PM
 
Originally posted by absmiths:
Hey thanks for pointing that out! Now I just have to figure out why I get periodic SIGBUSs.
Looks like I got that one solved. My Java objects were being garbage collected while ObjC retained pointers.
     
Uncle Skeleton
Addicted to MacNN
Join Date: Nov 2002
Location: Rockville, MD
Status: Offline
Reply With Quote
Apr 2, 2004, 04:07 PM
 
Originally posted by Catfish_Man:
Apple added a compiler flag in 10.3 to make stuff faster if you don't do that, so it's probably a good idea not to (f-no-nil-receivers).
Thanks for the tip. Forgive my total lack of knowledge about compilers, but can you explain a little more? Is this flag set automagically if I make sure never to call an object that might be nil? and if so, how would the compiler know this? Would I also have to add specific checks for nil before every method call?
     
absmiths  (op)
Mac Elite
Join Date: Sep 2000
Location: Edmond, OK USA
Status: Offline
Reply With Quote
Apr 2, 2004, 05:01 PM
 
Originally posted by Uncle Skeleton:
Thanks for the tip. Forgive my total lack of knowledge about compilers, but can you explain a little more? Is this flag set automagically if I make sure never to call an object that might be nil? and if so, how would the compiler know this? Would I also have to add specific checks for nil before every method call?
Compiler flags don't traditionally set themselves (except of course for flags which negate or represent things which are on by default). The reason for the flag is that the compiler writer either (1) couldn't determine absolutely whether this option could be enabled, or (2) could not guarantee backwards compatibility with the flag on, or (3) that this change in some way violates a language convention that purists would complain about and thus must be explicitly enabled. My guess is that ObjC is such a dynamic language that there is no way for the compiler to know without a doubt that an object reference will not be nil. Imagine a compiler trying to determine at compile-time whether all array indexes are valid or not - this is probably very similar - and also happens to be the reason the Java VM always enforces bounds checking whether you need it or not.

Anyway, what this flag really means is that you can continue to send messages to nil, but that you will get catastrophic results instead of the usual benign ones.
     
Uncle Skeleton
Addicted to MacNN
Join Date: Nov 2002
Location: Rockville, MD
Status: Offline
Reply With Quote
Apr 2, 2004, 06:41 PM
 
how much of a speed difference is it? seems to me the whole point of cocoa is rapid deveopment, not runtime efficiency, and it's worth the slowdown if I need less time to debug. But it's still nice to know what the tradeoffs are before making that decision. (also how would I set that compiler flag?)
     
Catfish_Man
Mac Elite
Join Date: Aug 2001
Status: Offline
Reply With Quote
Apr 2, 2004, 06:52 PM
 
Originally posted by Uncle Skeleton:
how much of a speed difference is it? seems to me the whole point of cocoa is rapid deveopment, not runtime efficiency, and it's worth the slowdown if I need less time to debug. But it's still nice to know what the tradeoffs are before making that decision. (also how would I set that compiler flag?)
Most compiler flags have a checkbox in the build settings in XCode. Since nil receivers are probably a bad idea anyway I can't see this being a bad thing to turn on. It does mean being a bit more careful though, and I doubt the speedup is large.
     
   
 
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 02:00 PM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,