First cocoa app & crashes
First cocoa app & crashes
- Subject: First cocoa app & crashes
- From: Oliver Donald <email@hidden>
- Date: Mon, 18 Nov 2002 14:43:13 -0000
Hi,
I am new to the list, and also new to OO programming (I come from purely C
background). Last night I wrote my first obj-c cocoa app, a simple program
that reads in an HTML file specified by the user, extracts the URL's, and
then downloads all of the files pointed to by those URL's that match the
user-specified file types. I may make it follow links to further HTML pages
a little later :) As I said, I am new to OO and so I think my architecure is
to blame for these problems.
My app largely works. I gave it a 1 meg HTML file full of links to 'wav'
files, and it downloaded every single one as expected. But there are two
problems: the application totally locks up while it is 'processing', and
crashes when processing has finished. The overall architecture is like this:
WebSucker.m is the controller, containing the GUI code for an NSOpenPanel
to choose the HTML source file, a text-box for the user to type his desired
file-types into, and a "Go" button with is connected to
-(IBAction)doSucking. The doSucking action allocates an instance of my
'Sucker' object, inits it with it's initWithHTML method, and calls its
'suck' method. It then releases the Sucker object, and prints a little
message to say all is done. The message prints, but after that, the
application crashes due to error 10 or 11, in 'objc msg-send' called from
NSAutoreleasePoolPop (or something similar). If it helps, I'll post part of
the app's crash log when I get home tonight.
Sucker.m does the work. It's -(void)suck method repeatedly fetches the next
URL from its (NSString *)htmlData variable, sees if it is the correct type,
and downloads it if it is. It then repeats the process until it reaches the
end of the HTML file, and returns to the Controller.
I presume that the reason the GUI freezes when [mySucker suck] is called, is
that sucker doesn't return until after it has finished processing, and this
prevents the event-loop from getting any time. Is this correct? Or am I
stuck in a Carbon mind-set? How do I get around this problem? I have a
feeling that the architecture of my app is all wrong; Controller calls
Sucker, but Sucker consists entirely of [self ***] invocations. Any
suggestions? Should Controller be invoking Sucker's methods rather than
Sucker itself? Is the Controller pretty much the Cocoa equivalent of the
WaitNextEvent() loop in pre-X applications?
I am not sure why my app crashes when the doSucking method exits. I am sure
I am releasing/retaining etc correctly, but I'm not confident about my
understanding of how obj-c does reference counting.
Any help greatly appreciated,
Thanks,
Oli
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.