discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: signal SIGSEGV, Segmentation fault


From: Riccardo Mottola
Subject: Re: signal SIGSEGV, Segmentation fault
Date: Tue, 22 May 2018 16:33:36 +0200
User-agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Firefox/52.0 SeaMonkey/2.49.3

Hi,

Yavor Doganov wrote:
Good practice is to check the result of that assignment.  If it fails for
some reason, it would explain (to an extent) why your program crashes
when you attempt to assign a value to the ivar at line 168.  Also, if
self is nil, -retain will do nothing.

exactly, this is exactly what I was proposing. I assume the code listed was more trimmed example, but:

- (id)initWithFrame:(NSRect)frameRect
{
   NSLog(@"initWithFrame ...");
   self = [super initWithFrame: frameRect];
   if (self)
   {
       /* your code here */
    }
   return self

}

most usually it makes no real difference, if the init code does not have some special code that can fail. However it can help track down things. E.g. if here self is "nil" your problem is in the super class, but your subclass is working on a bad object (of course: if it is "nil" all calls should do nothing, it should not crash.. but accessing an structure is usually invalid, e.g. a NSPoint! with GCC it will crash on most architectures.
Thus it is importat to check your "nil" objects in the whole chain.

Riccardo



reply via email to

[Prev in Thread] Current Thread [Next in Thread]