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 > Getting icons with Cocoa/Obj-C

Getting icons with Cocoa/Obj-C
Thread Tools
Fresh-Faced Recruit
Join Date: Aug 2001
Location: California
Status: Offline
Reply With Quote
Aug 12, 2001, 07:26 AM
 
I am writing a little cocoa file browser (just for practice) and I need to get the icons for different files. The way I'm doing it right now is this:

NSFileWrapper *fwrap = [[NSFileWrapper alloc] initWithPath:[pathField string Value];
[imageView setImage:[fwrap icon]];
[fwrap release];

When the stringValue for pathField is /, /Applications, /Users and all others within the root directory, the app crashes with this error:
-----
*** malloc[696]: error: Can't allocate region

NSFileWrapper.app has exited due to signal 10 (SIGBUS).
-----

I have tried to retain fwrap or remove the release statement, but I still get errors. Is the code just plain bad?
AHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH!
     
Fresh-Faced Recruit
Join Date: Aug 2001
Location: California
Status: Offline
Reply With Quote
Aug 12, 2001, 04:03 PM
 
I tried a little debugging and from what little I could make out of the crazy feedback was that the application didn't want to allocate space with the <BLOCKQUOTE><font size="1"face="Geneva, Verdana, Arial">code:</font><HR><pre><font size=1 face=courier>alloc</font>[/code] statement.

Any help on this would be great, even if it's "i dunno". Just so I know people can understand my problem.
AHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH!
     
Dedicated MacNNer
Join Date: Apr 2001
Location: San Francisco, USA
Status: Offline
Reply With Quote
Aug 13, 2001, 12:30 PM
 
I dunno.

Actually, I've never used NSFileWrapper so I'm not sure where your problem is. I looked over the documentation and I'm still confused as to what NSFileWrapper does. It represents the entire file, right? But in a file browser you are not really interested in the file itself, just the meta data.

You may have better luck using NSFileManager coupled with NSWorkspace. I've used these two classes to make my own file browser. You can find a good example of NSFileManager in Examples/AppKit/OutlineView. NSFileManager will get you all the basic information such as file name, size and permissions. Then use NSWorkspace's method <font face = "courier">iconForFile:</font> to get the Finder icon.

As far as debugging your current app, have you tried MallocDebug?
     
Fresh-Faced Recruit
Join Date: Aug 2001
Location: California
Status: Offline
Reply With Quote
Aug 13, 2001, 09:00 PM
 
Originally posted by honeydew:
<STRONG>As far as debugging your current app, have you tried MallocDebug?</STRONG>
I have tried, but I have know idea what to make of it. I actually solved my problem, though. The problem was with "initWithPath". I needed to use initSymbolicLinkWithDestination because some of the root files can't be accessed with initWithPath (i don't know why).

Now I have another problem. I'll try to figure it out, I might use NSWorkspace but I would be even more convinced to so so if it were faster, is it?

thanks for your feedback
AHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH!
     
Dedicated MacNNer
Join Date: Jan 2001
Location: Virginia, US
Status: Offline
Reply With Quote
Aug 14, 2001, 03:37 PM
 
NSFileWrapper will bomb if you give it a symlink path where it's expecting a regular file or directory. It should just raise an exception however, not bomb with a malloc() error. Either there's an Apple bug in this case or you're damaging the malloc arena somehow in other code by overwriting the end of some allocated memory.

NSFileWrapper most likely just uses the NSWorkspace method to get the icon, so it'd be better to go that route. You don't have to worry about symlinks and all that stuff that way. The only way I could see a speed difference is if NSFileWrapper does more work resolving symlinks than the NSWorkspace method does -- if so, for a lot of files the difference might be noticeable. Not sure though.
     
Dedicated MacNNer
Join Date: Apr 2001
Location: San Francisco, USA
Status: Offline
Reply With Quote
Aug 15, 2001, 12:54 PM
 
El Presidente, I like your sig.

Just FYI, <font face = "courier">iconForFile:</font> in NSWorkspace is very very slow. I think this was also discussed in the alternative Finder thread. I was going to investigate the icon related APIs in Carbon in search of a speed boost, but never got around to it.
     
   
Thread Tools
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
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 11:24 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2