(sigbus) mystery :-)

Discussion in 'Mac Programming' started by mdeh, Jul 25, 2009.

  1. macrumors 6502

    Jan 3, 2009
    I am working ( or trying to) work my way through Apple's Core Data Utility Tutorial:

    in order to solve an earlier issue :)

    But, from the very first change of code ie implementing GC, I am getting this error.

    and stepping through the code, the line
    throws an EXC_BAD_ACCESS.

    I am at a loss as to what is going on, as this is word for word from the tutorial.

    For the sake of completeness, here is the code so far.

    #import <Foundation/Foundation.h>
    #import <CoreData/CoreData.h>
    NSManagedObjectModel *managedObjectModel();
    int main (int argc, const char * argv[]) {
       /* NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];  */
    	NSManagedObjectModel *mom = managedObjectModel();
    	NSLog(@"The managed object model is defined as follows:\n%@", mom);
        // insert code here...
        NSLog(@"Hello, World!");
     /*   [pool drain];    */
        return 0;
    NSManagedObjectModel *managedObjectModel() {
        static NSManagedObjectModel *mom = nil;
        if (mom != nil) {
            return mom;
        mom = [[NSManagedObjectModel alloc] init];
    	NSEntityDescription *runEntity = [[NSEntityDescription alloc] init];
    	[runEntity setName:@"Run"];
    	[runEntity setManagedObjectClassName:@"Run"];
    	[mom setEntities:[NSArray arrayWithObject:runEntity]];
    	NSAttributeDescription *dateAttribute = [[NSAttributeDescription alloc] init];
    	[dateAttribute setName:@"date"];
    	[dateAttribute setAttributeType:NSDateAttributeType];
    	[dateAttribute setOptional:NO];
    	NSAttributeDescription *idAttribute = [[NSAttributeDescription alloc] init];
    	[idAttribute setName:@"processID"];
    	[idAttribute setAttributeType:NSInteger32AttributeType];
    	[idAttribute setOptional:NO];
    	[idAttribute setDefaultValue:[NSNumber numberWithInteger:-1]];
    	NSExpression *lhs = [NSExpression expressionForEvaluatedObject];
    	NSExpression *rhs = [NSExpression expressionForConstantValue:
    						 [NSNumber numberWithInteger:0]];
    	NSPredicate *validationPredicate = [NSComparisonPredicate
    	NSString *validationWarning = @"Process ID < 1";
    	[idAttribute setValidationPredicates:[NSArray arrayWithObject:validationPredicate]
    				  withValidationWarnings:[NSArray arrayWithObject:validationWarning]];
    	NSArray *properties = [NSArray arrayWithObjects: dateAttribute, idAttribute, nil];
    	[runEntity setProperties:properties];
    	NSMutableDictionary *localizationDictionary = [NSMutableDictionary dictionary];
    	[localizationDictionary setObject:@"Date" forKey:@"Property/date/Entity/Run"];
    	[localizationDictionary setObject:@"Process ID" forKey:@"Property/processID/Entity/Run"];
    	[localizationDictionary setObject:@"Process ID must not be less than 1" forKey:@"ErrorString/Process ID < 1"];
    	[mom setLocalizationDictionary:localizationDictionary];
        return mom;
    Any help as to how to approach this will be immensely appreciated.
  2. macrumors 68040


    Jan 10, 2005
    Dallas, TX
    Did you compile with -fobjc-gc or -fobjc-gc-only?
    Can you do a bt/backtrace from the gdb prompt when the program fails?

  3. thread starter macrumors 6502

    Jan 3, 2009
    The tutorial calls for "-fobjc-gc-only"

    Lee...not entirely sure how to do this, but the Console in Xcode gives me this.

    Does this help? Not quite sure if the ref to the iPhone OS is the issue? Maybe that's a clue? Not quite sure what to do with this in terms of fixing the problem.
  4. macrumors G5


    Nov 25, 2005
    Seems the tutorial is written for MacOS X. iPhone doesn't support garbage collection.
  5. thread starter macrumors 6502

    Jan 3, 2009
    Hi Gnasher,
    Well, as soon as I had thought about this, I realize that the app **was** written for Mac OS X, which now makes even less sense. Moreover, I have been unable to reproduce this line in the Console. But the following type of line is repeated much more consistently.

    So, having said this, do you have any further insights.
  6. thread starter macrumors 6502

    Jan 3, 2009

    I am embarrassed to say that the reason was a real **newbie** error. I **thought** I had implemented GC for the debug version, but what I had done was implement it for the release version. So, the take home lesson ( for me!!) is to check one is setting GC for the correct version...obvious to people like gnasher, but a mistake I bet many have made :)

Share This Page