1

I'm creating a new NSManagedObject and inserting it into a context with concurrency type private queue (so it runs on a background thread).

Right before I save, I call this:

[appDelegate.backgroundMOC obtainPermanentIDsForObjects:
       [NSArray arrayWithObject:newObject] error:&error];

Then I save:

[appDelegate.backgroundMOC save:&err];

However, I get a EXC_BAD_ACCESS crash. Looking at the stacktrace, I see:

0 semaphore_wait_trap
7-[NSManagedObjectContentSave:]

I'm guessing the problematic line is the semaphore_wait_trap, but I'm not sure how that's caused.

If I comment out the line obtainPermanentIDsForObjects, the problem goes away.

Any ideas?

Snowman
  • 31,411
  • 46
  • 180
  • 303
  • Do you have any other new managed objects that are "children" of the object you're getting the objectID for? If so, you need to add those objects to the array. It is a bug in core data. – Brandon A Jul 03 '12 at 20:14
  • No I don't think I deal with children and parent objects.. – Snowman Jul 03 '12 at 20:18
  • Were any other objects created and set as properties on newObject (other than core data primitives)? – Brandon A Jul 03 '12 at 20:21
  • You mean relationships? Yes I did assign some relationships, though not always creating those new objects, but fetching them, then assigning them.. – Snowman Jul 03 '12 at 20:24
  • Any new objects that were created should get passed to -obtainPermanentIDsForObjects: due to a bug that has been reported. – Brandon A Jul 03 '12 at 20:25
  • If I do `[backgroundMOC obtainPermanentIDsForObjects: backgroundMOC.managedObjects.allObjects error:&error];`, the problem goes away. Maybe this has something to do with what you're talking about? – Snowman Jul 03 '12 at 20:27
  • 1
    How do you know this is a bug? Do you have a link? – Snowman Jul 03 '12 at 20:30
  • Here's the open radar link: http://openradar.appspot.com/11478919 – Brandon A Jul 05 '12 at 20:34

1 Answers1

1

Due to a bug in obtaining object ids (http://openradar.appspot.com/11478919), you need to pass in all newly created objects to -[NSManagedObjectContext obtainPermanentIDsForObjects:error:].

Brandon A
  • 926
  • 7
  • 6