Cannot track down [NSData getBytes:length:] crash

坚强是说给别人听的谎言 提交于 2019-12-03 13:30:18

With the introduction of iOS 8 there are some unexpected bug occurrance also happening we've to keep that in mind as well.

Apps like MIT Mobile,Mile point also suffers from the issue like yours,this is not wide spread though as of now.

Here are the bug links for MIT & MilePoint.

com.apple.CFNetwork.addPersistCacheToStorageDaemon

CFNetwork is lower level C API and it is wrapped by higher level class like NSURLConnection.

so the crash occurs during a network operation

EXC_BAD_ACCESS

It means that message was sent to an memory address where there’s no instance of a class to execute it. Thus results “bad access”

When will it happen?

  1. An object is not initialized
  2. An object is already released
  3. Something else that is not very likely to happen

How can we solve this problem ?

  • You can catch some of the bugs(number 2) by Enabling NSZombie in xcode

Enabling NSZombie:

When this feature is enabled, a dummy object (a zombie) is kept on the place of every released object, thus allowing to debug objects which were released already. Very easy to enable:

  1. Double click your executable in the “Executables” in XCode
  2. Open “Arguments” tab In “Variables to be set in the environment” (that’s the list at the bottom, be careful which one you edit)
  3. click the “+” button and for name of the variable enter “NSZombieEnabled” and for value “YES”

Now instead of wondering what’s going on and which exact object produced the problem, you’ll see exactly which class is the trouble maker, and you’ll debug it quite fast.

Note: Do not leave the zombies enabled, when you submit your app to the App store. Also, it’s a good practice to disable them if you don’t really need them.

  • If you are using third party libraries kindly update it to the latest

Note:

My suggestion is never use third party framework unless its unavoidable because the library itself will have bugs sometimes which is out of developer control and sometimes library would be updated late to current SDK.You can find more about it here

Hope this helps

My guess is that you have

  • some __unsafe_unretained (that is unavoidable for setter Path [NSInvocation setArgument:atIndex:])
  • or an issue like this one
  • or (more likely) a deadlock during a performBlockAndWait (since I've seen a connection/timeout in the stack)

A couple of related suggestions:

1) NSManagedObject, NSManagedObjectContext, and NSPersistentStoreCoordinator (given the crash at addPersistCacheToStorageDaemon) aren't thread safe:

  • consider this if you are using performBlockAndWait to send messages to your NSManagedObjectContext (more here and here) or nested MOC.

2) CFNetwork is a lower-level class that is wrapped by the NSURLConnection:

  • so not using NSURL ? avoiding addObserver:self forKeyPath (KVO) to a property of a NSURL Session?
Mikael

The issue could actually be from SDWebImage quote from this site:

http://webcache.googleusercontent.com/search?q=cache:BCShJT0ZrvoJ:quabr.com/15786084/uicollectionview-bad-acces-on-uicollectionviewdata-setlayoutattributesatglo+&cd=7&hl=fr&ct=clnk&gl=jp

Now if you are using AFNetworking to set the image directly from the URL using the AFNetworking category you may want to use the alternate method so you can intervene and resize the image. The code below will do that.

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:imageURL];
[request addValue:@"image/*" forHTTPHeaderField:@"Accept"];

[imageView setImageWithURLRequest:request placeholderImage:nil success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image) {
    // resize image
    // set image on imageView
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error) {
    // handle error
}];

I would also check this page for related crashes:

https://github.com/rs/SDWebImage/issues?q=is%3Aopen+is%3Aissue+label%3Acrash

Check if you are using the latest version of SDWebImage, otherwise you might have to check out older issues.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!