Crash in setTextColor

  • One of my users found a strange bug. In my application, I have an
    NSTableView where I set the colour of rows within:

    -(void)tableView:(NSTableView *)aTableView willDisplayCell:(id)aCell
    forTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex
    {
    ...
      [aCell setTextColor:newColor];

    If newColor is one of the primary colours then everything works fine.
    If he selects a colour from the colour wheel rather than from the list
    of colours provided in the Apple group then it crashes. As a test, I
    picked Carnation as a colour from the Color Picker window via a Color
    Well in my preferences window and I got the following exception:

    #0    0x908311f4 in objc_msgSend
    #1    0x92e5a044 in -[NSCalibratedWhiteColor isEqual:]
    #2    0x92e24ca8 in -[NSTextFieldCell setTextColor:]
    #3    0x0068aab8 in -[AppController
    tableView:willDisplayCell:forTableColumn:row:] at AppController.m:1402

    I've done an archive search and a web search and I can find no record
    of this problem or of any limitations on the type of colours that can
    be used with setTextColor on a table cell. Does this sound familiar to
    anybody?

    Thanks!
    - Steve
    _______________________________________________
    cocoa-dev mailing list | <cocoa-dev...>
    Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
    Do not post admin requests to the list. They will be ignored.
  • On 18.4.2004, at 18:31, Steve Palmer wrote:

    > If newColor is one of the primary colours then everything works fine.
    > If he selects a colour from the colour wheel rather than from the list
    > of colours provided in the Apple group then it crashes...

    Can't say for sure, but it looks like it gets released?
    ---
    Ondra Hada
    OCSoftware:    <ocs...>              http://www.ocs.cz
    private        <ondra...>            http://www.ocs.cz/oc

    [demime 0.98b removed an attachment of type application/pkcs7-signature which had a name of smime.p7s]
    _______________________________________________
    cocoa-dev mailing list | <cocoa-dev...>
    Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
    Do not post admin requests to the list. They will be ignored.
  • Hmm... Yes. The way I was originally handling it was by saving the new
    colour to the defaults, sending a notification from the preferences
    controller to the main controller then reloading the colour from the
    defaults overwriting the old object. Here's what I have now in the
    notification handler:

    NSData * colourData;
    NSColor * newColour;

    colourData = [[NSUserDefaults standardUserDefaults]
    objectForKey:@"foobar"];
    newColour = [[NSUnarchiver unarchiveObjectWithData:colourData] retain];
    [myColour release];
    myColour = newColour;

    So the change is that each time I get a new colour from the defaults, I
    retain it and release the old copy then pass myColour to setTextColor
    in willDisplayCell. I've tested this and the crash has gone away but...
    it would be nice to get some confirmation that I'm doing this
    correctly. From reading the documentations on alloc, retain and release
    I thought I was following the rules in the first place.

    On Apr 18, 2004, at 9:45 AM, Ondra Cada wrote:

    > On 18.4.2004, at 18:31, Steve Palmer wrote:
    >
    >> If newColor is one of the primary colours then everything works fine.
    >> If he selects a colour from the colour wheel rather than from the list
    >> of colours provided in the Apple group then it crashes...
    >
    > Can't say for sure, but it looks like it gets released?
    > ---
    > Ondra Hada
    > OCSoftware:    <ocs...>              http://www.ocs.cz
    > private        <ondra...>            http://www.ocs.cz/oc
    >
    > [demime 0.98b removed an attachment of type
    > application/pkcs7-signature which had a name of smime.p7s]
    > _______________________________________________
    > cocoa-dev mailing list | <cocoa-dev...>
    > Help/Unsubscribe/Archives:
    > http://www.lists.apple.com/mailman/listinfo/cocoa-dev
    > Do not post admin requests to the list. They will be ignored.
    _______________________________________________
    cocoa-dev mailing list | <cocoa-dev...>
    Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
    Do not post admin requests to the list. They will be ignored.
  • Is this code the correct thing to do here. From my reading of the
    alloc/retain/release documents, it seems that unarchiveObjectWithData
    returns an autoreleased object that gets released at the end of the
    function, right?

    - Steve

    On Apr 18, 2004, at 6:27 PM, Steve Palmer wrote:

    > Hmm... Yes. The way I was originally handling it was by saving the new
    > colour to the defaults, sending a notification from the preferences
    > controller to the main controller then reloading the colour from the
    > defaults overwriting the old object. Here's what I have now in the
    > notification handler:
    >
    > NSData * colourData;
    > NSColor * newColour;
    >
    > colourData = [[NSUserDefaults standardUserDefaults]
    > objectForKey:@"foobar"];
    > newColour = [[NSUnarchiver unarchiveObjectWithData:colourData]
    > retain];
    > [myColour release];
    > myColour = newColour;
    >
    > So the change is that each time I get a new colour from the defaults, I
    > retain it and release the old copy then pass myColour to setTextColor
    > in willDisplayCell. I've tested this and the crash has gone away but...
    > it would be nice to get some confirmation that I'm doing this
    > correctly. From reading the documentations on alloc, retain and release
    > I thought I was following the rules in the first place.
    >
    >
    >
    > On Apr 18, 2004, at 9:45 AM, Ondra Cada wrote:
    >
    >> On 18.4.2004, at 18:31, Steve Palmer wrote:
    >>
    >>> If newColor is one of the primary colours then everything works fine.
    >>> If he selects a colour from the colour wheel rather than from the
    >>> list
    >>> of colours provided in the Apple group then it crashes...
    >>
    >> Can't say for sure, but it looks like it gets released?
    >> ---
    >> Ondra Hada
    >> OCSoftware:    <ocs...>              http://www.ocs.cz
    >> private        <ondra...>            http://www.ocs.cz/oc
    >>
    >> [demime 0.98b removed an attachment of type
    >> application/pkcs7-signature which had a name of smime.p7s]
    >> _______________________________________________
    >> cocoa-dev mailing list | <cocoa-dev...>
    >> Help/Unsubscribe/Archives:
    >> http://www.lists.apple.com/mailman/listinfo/cocoa-dev
    >> Do not post admin requests to the list. They will be ignored.
    > _______________________________________________
    > cocoa-dev mailing list | <cocoa-dev...>
    > Help/Unsubscribe/Archives:
    > http://www.lists.apple.com/mailman/listinfo/cocoa-dev
    > Do not post admin requests to the list. They will be ignored.
    _______________________________________________
    cocoa-dev mailing list | <cocoa-dev...>
    Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
    Do not post admin requests to the list. They will be ignored.
previous month april 2004 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