Results 1 to 4 of 4

Thread: Some ObjC help needed

  1. #1
    QCar Creator Jirka Jirout's Avatar
    Join Date
    Jul 2005
    Location
    Netherlands
    Posts
    590

    Some ObjC help needed

    Could someone have a look at the attached files - it is a sub-class of NSTextField that is supposed to scroll its content if it is too long and does not fit the box.

    There seems to be some memory management-related problem in the implementation, causing application crash from time to time (mostly when changing the contents of the field, so I guess the problem is in -setStringValue: method). I am pretty sure there is some small and stupid error in the code, but I just don't see it :-(
    Attached Files Attached Files

  2. #2
    CarFrontEnd Creator iamgnat's Avatar
    Join Date
    Jul 2004
    Location
    NoVA
    Posts
    867
    Quote Originally Posted by Jirka Jirout
    There seems to be some memory management-related problem in the implementation, causing application crash from time to time (mostly when changing the contents of the field, so I guess the problem is in -setStringValue: method). I am pretty sure there is some small and stupid error in the code, but I just don't see it :-(
    I haven't extended a UI object, so take this all with a grain of salt.

    The first thing I see if that you are using the -display from NSView method rather than -setNeedsDisplay from NSControl. The first forces the display, while the second just marks it as needing the display and lets the run loop handle updating it when it gets around it to. All the examples I have seen use the later approach.

    The second thing is that (at a quick glance) I wonder if you really need a sub-class of the object. Why not just make a delegate object that listens for the NSControlTextDidChangeNotification notification and then update your position accordingly?

    The only thing that jumps out at me is how you handle attrString. You are not initializing it anywhere, so your -autorelease call on it (should be -release rather than -autorelease anyway) in -setStringValue is going to have unknown results. Secondly when you are creating the string later, you are not issuing a -retain call on it which means it goes out of scope (and see the previous issue).

    I would suggest that you:
    1) Add an -init method to (at a minimum) set all your class variable to nil (or 0).

    2) Test for attrString to not be nil before you try to release it.

    3) Add a retain call when you create attrString so that it is available to all your methods and is carried over from call to call (if that is indeed it's purpose as it appears).

    Finally, I have spent many hours debugging what I thought was the problem (based the debugger) only to find that it was actually an entirely different object causing the issue. If none of the above helps, i'd try throwing NSLog's every where to figure out exactly where it is crashing (my case was a completly unrelated object being nil when I tried to reference it, but the debugger had me looking at something else ).

    Hope some of that helps,
    -dave

  3. #3
    QCar Creator Jirka Jirout's Avatar
    Join Date
    Jul 2005
    Location
    Netherlands
    Posts
    590
    Ups, I uploaded the old version of the files - this version worked fine, except 60% of the processor load (apparently due to text rendering :-O ).

    Here is the newest version - it creates an NSImage representation of the string during -setStringValue: and then only draws that image. This reduces the processor load to a fraction of what it used to be.

    Thanks for your notes. Will look at this today and see whether it helps.
    Attached Files Attached Files

  4. #4
    CarFrontEnd Creator iamgnat's Avatar
    Join Date
    Jul 2004
    Location
    NoVA
    Posts
    867
    Quote Originally Posted by Jirka Jirout
    Here is the newest version - it creates an NSImage representation of the string during -setStringValue: and then only draws that image. This reduces the processor load to a fraction of what it used to be.
    Jirka,
    Sorry it took awhile. In this version, I don't see anything that jumps out at me beyond the items mentioned above (though textImage has the same init, retain, and release issues as attrString).
    Hope some of the above helps.

    -dave

Similar Threads

  1. Help needed from EE gurus - 5 channel A/B switch
    By Dr. Jeff in forum Hardware Development
    Replies: 13
    Last Post: 02-17-2005, 09:10 PM
  2. Stand-alone programs (no installation needed)
    By d_sellers1 in forum Software & Software Development
    Replies: 1
    Last Post: 07-19-2004, 08:45 AM
  3. Amplifier Needed?
    By c0rrupti0n in forum Newbie
    Replies: 7
    Last Post: 03-15-2004, 04:04 AM
  4. Sony LCD tv part needed!
    By mp3hombre in forum General MP3Car Discussion
    Replies: 2
    Last Post: 02-03-2003, 01:15 PM
  5. My project for the day - advice needed
    By ddt in forum General MP3Car Discussion
    Replies: 2
    Last Post: 12-02-2002, 08:51 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •