Method parameter is sometimes zeroed (weird problem)

  • Hi, I'm having a really weird problem, which is probably something
    obvious...

    ObjectA is a subclass of NSObject and implements the method (void)
    tabView:(NSTabView *)tabview didChangeHeightBy:(float)change, which
    is a delegate method (of my own creation, not Cocoa's) for ObjectB.

    ObjectB is a subclass of NSTabView, which holds ObjectA as its
    delegate and invokes the delegate method on it with [[self delegate]
    tabView: self didChangeHeightBy: change] where 'change' is a float
    value.

    The problem is that in the delegate method, the 'change' parameter is
    always 0.0. I've put in NSLogs, traced the values in debug and passed
    in constant float values, and while a non-zero value is always
    passed, the received parameter 'change' is always 0.0. BUT only when
    called in this way. If I get ObjectA to call the method on itself,
    the change parameter is passed correctly. The same is true if I call
    the method from ObjectC, another NSObject subclass.

    This is under 10.4.11 on Intel. All objects are compiled from source
    inside the same project.
  • On Nov 19, 2007, at 8:58 AM, Stuart Crook wrote:

    > Hi, I'm having a really weird problem, which is probably something
    > obvious...
    >
    > ObjectA is a subclass of NSObject and implements the method
    > (void)tabView:(NSTabView *)tabview didChangeHeightBy:(float)change,
    > which is a delegate method (of my own creation, not Cocoa's) for
    > ObjectB.
    >
    > ObjectB is a subclass of NSTabView, which holds ObjectA as its
    > delegate and invokes the delegate method on it with [[self delegate]
    > tabView: self didChangeHeightBy: change] where 'change' is a float
    > value.
    >
    > The problem is that in the delegate method, the 'change' parameter
    > is always 0.0. I've put in NSLogs, traced the values in debug and
    > passed in constant float values, and while a non-zero value is
    > always passed, the received parameter 'change' is always 0.0. BUT
    > only when called in this way. If I get ObjectA to call the method on
    > itself, the change parameter is passed correctly. The same is true
    > if I call the method from ObjectC, another NSObject subclass.
    >
    > This is under 10.4.11 on Intel. All objects are compiled from source
    > inside the same project.

    Do you see any warnings emitted by the compiler about not knowing
    about that particular method? It sounds like the compiler is assuming
    you are passing an int (what the compiler assumes when it don't know
    about a method). This results in code pushing data into registers that
    the callee doesn't look at.

    As a test try changing the definition to pass an int instead to see if
    the correct values start to show up.

    -Shawn
previous month november 2007 next month
MTWTFSS
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30    
Go to today