Crashes in Core Data's Inferred Mapping Model Creation (Lightweight Migration). Threading Issue?

Posted by enchilada on Stack Overflow See other posts from Stack Overflow or by enchilada
Published on 2010-03-22T00:46:02Z Indexed on 2010/03/22 0:51 UTC
Read the original article Hit count: 295

Filed under:
|
|
|

I'm getting random crashes when creating an inferred mapping model (with Core Data's lightweight migration) within my application. By the way, I have to do it programmatically in my application while it is running.

This is how I create this model (after I have made proper currentModel and newModel objects, of course):

NSMappingModel *mappingModel = [NSMappingModel inferredMappingModelForSourceModel:currentModel destinationModel:newModel error:&error];

The problem is this: This method is crashing randomly. When it works, it works just fine without issues. But when it crashes, it crashes my application (instead of returning nil to signify that the method failed, as it should). By randomly, I mean that sometimes it happens and sometimes not. It is unpredictable.

Now, here is the deal: I'm running this method in another thread. More precisely, it is located inside a block that is passed via GCD to run on the global main queue. I need to do this for my UI to appear crisp to the user, i.e. so that I can display a progress indicator while the work is underway.

The strange thing seems to be that if I remove the GCD stuff and just let it run on the main thread, it seems to be working fine and never crashing. Thus, could it be because I'm running this on a different thread that this is crashing?

I somehow find that weird because I don't believe I'm breaking any Core Data rules regarding multi-threading. In particular, I'm not passing any managed objects around, and whenever I need access to the MOC, I create a new MOC, i.e. I'm not relying on any MOC (or for that matter: anything) that has been created earlier on the main thread. Besides the little MOC stuff that occurs, occurs after the mapping model creation method, i.e. after the point at which the app crashes, so it can't possibly be a cause of the crashes under consideration here.

All I'm doing is taking two MOMs and asking for a mapping model between them. That can't be wrong even under threading, now can it?

Any ideas on what could be going on?

© Stack Overflow or respective owner

Related posts about cocoa

Related posts about mac