0

I've just got a crash through when running with Xcode and I'm pretty sure there's no way it's my fault.

enter image description here enter image description here

How can there be a bad access error? fetch is created right before it so it must exist in memory, and self is the context itself (this method is in a Swift extension on NSManagedObjectContext), and the context is one that exists permanently in the app and isn't released. It's created and is stored in the app delegate.

How can I prevent this, because I get it every now and then and it doesn't seem right.

The context is a private queue context, and this method is being called within that queue (context.performBlock)

Sencha
  • 415
  • 3
  • 12
  • 1
    I'd partially agree with you if my code was running at machine level, but I'm writing on top of layer after layer of foundations and frameworks that are not written by me. Those layers can contain bugs you know! Which address in that line 43 could be invalid if `fetch` clearly exists, and the object referenced at `self` is persistent over the app's lifecycle? So "You made a mistake" is an erroneous statement if it is at all possible, however unlikely, that this is a framework bug. – Sencha Jan 25 '16 at 10:11
  • @gnasher729 Perhaps you could offer some guidance to help me find the mistake I made? – Sencha Jan 25 '16 at 10:41
  • You are experiencing concurrency issues, trust me I know. This is a huge pain in the ass. You are not properly wrapping these commands in perform blocks and then you may or may not be using multiple contexts incorrectly. Hard to say without seeing the method being called. Check: http://oleb.net/media/xcode-scheme-core-data-concurrency-debug.png you will get the allthatisleftousishonour errors I presume. – Orion Jan 25 '16 at 10:42
  • Well that's what stands out to me, but and I always have `-com.apple.CoreData.ConcurrencyDebug` enabled during development and it throws no warnings, and I'm extremely careful about working with Core Data and ensuring all the work is queued up correctly. It's a very complex app so hunting down an issue is going to be a nightmare! Do you think that the fact it is breaking in this context means that it is somehow that very same context that is being used outside the queue? If so that will narrow down the search. – Sencha Jan 25 '16 at 10:47
  • yes I think the method isnt called properly. That has to be it but I guess you suspected so. I've been having too many issues with Core Data, yet still don't know how to efficiently track down the issues. It may even be that this bit of code isn't even where the app crashes. But it most likely is though. Yes I think you are not using the correct context in the queue'd operation. I have had to resort to creating a new private context and use that in certain situations. – Orion Jan 25 '16 at 12:05
  • Could you please post the full stack of the crash you are experiencing and any message printed in the console? It may tell us something about the nature of your problem. – Xavier Jurado Jan 25 '16 at 21:06

0 Answers0