iOS -[UIImage initWithCGImage:scale:orientation:] crashes on a background thread - ios

I'm creating a UIImage on a background queue with -[UIImage initWithCGImage:scale:orientation:], and it's crashing thusly:
Crash 1
Crashed: com.apple.root.background-qos
0 libsystem_kernel.dylib 0x183778140 __pthread_kill + 8
1 libsystem_pthread.dylib 0x183840ef8 pthread_kill + 112
2 libsystem_c.dylib 0x1836e9dac abort + 140
3 libsystem_malloc.dylib 0x1837acd34 free_list_checksum_botch + 438
4 libsystem_malloc.dylib 0x1837aced8 free_tiny_botch + 84
5 CoreFoundation 0x183c08038 __CFBasicHashRehash + 2448
6 CoreFoundation 0x183c09034 __CFBasicHashAddValue + 100
7 CoreFoundation 0x183ab49c4 CFDictionarySetValue + 248
8 UIKit 0x18926fd30 _UITraitCollectionCacheForBuiltinStorage + 152
9 UIKit 0x189272090 +[UITraitCollection traitCollectionWithDisplayScale:] + 52
10 UIKit 0x1888d5070 -[UIImage initWithCGImage:scale:orientation:] + 236
11 UIKit 0x1888d4f74 +[UIImage imageWithCGImage:scale:orientation:] + 72
12 MyApp 0x10001a168 -[UIImage(Additions) foo_scaledImageData] (Foo.m:1527)
13 MyApp 0x100017304 -[Foo bar] (Foo.m:731)
14 MyApp 0x100017094 __95-[Foo bar]_block_invoke_3 (Foo.m:691)
15 libdispatch.dylib 0x183629630 _dispatch_call_block_and_release + 24
16 libdispatch.dylib 0x1836295f0 _dispatch_client_callout + 16
17 libdispatch.dylib 0x183637a88 _dispatch_root_queue_drain + 2140
18 libdispatch.dylib 0x183637224 _dispatch_worker_thread3 + 112
19 libsystem_pthread.dylib 0x18383d470 _pthread_wqthread + 1092
20 libsystem_pthread.dylib 0x18383d020 start_wqthread + 4
I also have a crash with the following two threads:
Crash 2, thread 1:
Crashed: com.apple.root.background-qos
0 libsystem_kernel.dylib 0x237d3c5c __pthread_kill + 8
1 libsystem_pthread.dylib 0x23879b47 pthread_kill + 62
2 libsystem_c.dylib 0x237680c5 abort + 108
3 libsystem_malloc.dylib 0x238040e9 free_list_checksum_botch + 362
4 libsystem_malloc.dylib 0x23804105 free_list_checksum_botch + 28
5 libsystem_malloc.dylib 0x237fbbff tiny_malloc_from_free_list + 202
6 libsystem_malloc.dylib 0x237fa987 szone_malloc_should_clear + 218
7 libsystem_malloc.dylib 0x237fa879 malloc_zone_malloc + 88
8 CoreFoundation 0x23a4e291 _CFRuntimeCreateInstance + 236
9 CoreGraphics 0x24e792a9 CGTypeCreateInstance + 20
10 CoreGraphics 0x24db7d23 CGColorTransformCreate + 246
11 ImageIO 0x2533c64b IIO_ConvertCGColorToColorComponents + 26
12 ImageIO 0x252f5775 CGImagePixelDataProviderCreate + 276
13 ImageIO 0x25319af1 CGImagePixelDataProviderCreateConforming + 1684
14 ImageIO 0x252f418d CGImageDestinationAddImage + 2852
15 UIKit 0x283fe4f5 _UIImageJPEGRepresentation + 620
16 MyApp 0xf6785 -[UIImage(Additions) foo_scaledImageData] (Foo.m:1538)
17 MyApp 0xf3ecd -[Foo bar] (Foo.m:731)
18 MyApp 0xf3d29 __95-[Foo bar]_block_invoke_3 (Foo.m:691)
19 libdispatch.dylib 0x236d7cbf _dispatch_call_block_and_release + 10
20 libdispatch.dylib 0x236e36a1 _dispatch_root_queue_drain + 1572
21 libdispatch.dylib 0x236e307b _dispatch_worker_thread3 + 94
22 libsystem_pthread.dylib 0x23876e0d _pthread_wqthread + 1024
23 libsystem_pthread.dylib 0x238769fc start_wqthread + 8
Crash 2, thread 2:
com.apple.root.background-qos
0 libsystem_malloc.dylib 0x238041d8 free_tiny_botch
1 CoreFoundation 0x23b6f560 __CFBasicHashRehash + 2968
2 CoreFoundation 0x23b706d4 __CFBasicHashAddValue + 100
3 CoreFoundation 0x23a4f933 CFDictionarySetValue + 206
4 UIKit 0x28a87ffb _UITraitCollectionCacheForBuiltinStorage + 146
5 UIKit 0x28a8a2a7 +[UITraitCollection traitCollectionWithDisplayScale:] + 50
6 UIKit 0x2812390f -[UIImage initWithCGImage:scale:orientation:] + 214
7 UIKit 0x2812382b +[UIImage imageWithCGImage:scale:orientation:] + 62
8 MyApp 0xf676d -[UIImage(Additions) foo_scaledImageData] (Foo.m:1527)
9 MyApp 0xf3ecd -[Foo bar] (Foo.m:731)
10 MyApp 0xf3d29 __95-[Foo bar]_block_invoke_3 (Foo.m:691)
11 libdispatch.dylib 0x236d7cbf _dispatch_call_block_and_release + 10
12 libdispatch.dylib 0x236e36a1 _dispatch_root_queue_drain + 1572
13 libdispatch.dylib 0x236e307b _dispatch_worker_thread3 + 94
14 libsystem_pthread.dylib 0x23876e0d _pthread_wqthread + 1024
15 libsystem_pthread.dylib 0x238769fc start_wqthread + 8
Crash 2, thread 2 looks like Crash 1, thread 1, which makes me think that they're related, but Crash 2, thread 2 is an outlier. I have a lot of other crashes that look like Crash 2 without a thread 2 stack, which makes me think that UIImageJPEGRepresentation may not be thread-safe either.

This looks similar to an AFNetworking issue
I can't name the source, but it's being taken care of. (or at least a
radar has been filed by someone inside Apple)
Side note: I've looked at the UIKit disassembly and that API calls up
traitCollection and a few other things and really is everything but
thread safe; more so it really should only be called on the main
thread ideally. We could swizzle and add the lock directly into the
implementation, that would at least remove the fact that any
non-AFNetworking consumer would still call this without the lock and
might trigger the race condition; but it's also very much not pretty.
Using CGImageSource directly is more work but might be the better
solution.
As the AFNetworking issue mentions and the stack traces reveal, this looks like -[UIImage initWithCGImage:scale:orientation:] calls through to UITraitCollection. I can't find anything in UITraitCollection.h or in the UITraitCollection documentation that says UITraitCollection is thread safe.
Thus, even though the UIImage documentation says UIImages are thread-safe:
Because image objects are immutable, you cannot change their
properties after creation. Most image properties are set automatically
using metadata in the accompanying image file or image data. The
immutable nature of image objects also means that they are safe to use
from any thread.
The documentation must mean they're safe to use after being created on the main thread, or maybe that they're safe to use if they're only being created serially. (This is how AFNetworking fixed their issue.) For my workaround, I switched to using CoreGraphics:
CGImageRef image = ...
CGSize scaledSize = ...
CGContextRef context = CGBitmapContextCreate(NULL,
scaledSize.width,
scaledSize.height,
CGImageGetBitsPerComponent(image),
CGImageGetBytesPerRow(image),
CGImageGetColorSpace(image),
CGImageGetAlphaInfo(image));
CGImageRef scaledImage;
if (context)
{
CGContextDrawImage(context,
CGRectMake(0,
0,
scaledSize.width,
scaledSize.height),
image);
scaledImage = CGBitmapContextCreateImage(context);
CGContextRelease(context);
}
else
{
scaledImage = NULL;
}
Then, to avoid using UIImageJPEGRepresentation on a background thread, I use ImageIO to export JPEG data:
NSData *NSDataFromCGImage(CGImageRef scaledImage)
{
NSMutableData *scaledImageMutableData = scaledImage ? [NSMutableData new] : nil;
CGDataConsumerRef scaledImageDataConsumer = scaledImageMutableData ? CGDataConsumerCreateWithCFData((__bridge CFMutableDataRef) scaledImageMutableData) : NULL;
// from the iOS 9.3 header:
// The `options' dictionary is reserved for future use; currently, you
// should pass NULL for this parameter.
CGImageDestinationRef scaledImageDestination = scaledImageDataConsumer ? CGImageDestinationCreateWithDataConsumer(scaledImageDataConsumer,
kUTTypeJPEG,
1,
NULL) : NULL;
BOOL success = (^BOOL ()
{
if (scaledImageDestination)
{
NSDictionary *addImageOptions = #{(__bridge NSString *)kCGImageDestinationLossyCompressionQuality : #(0.9),
};
CGImageDestinationAddImage(scaledImageDestination,
scaledImage,
(__bridge CFDictionaryRef)addImageOptions);
return (BOOL) CGImageDestinationFinalize(scaledImageDestination);
}
else
{
return NO;
}
})();
if (scaledImageDestination)
{
CFRelease(scaledImageDestination);
}
CGDataConsumerRelease(scaledImageDataConsumer);
if (success)
{
return scaledImageMutableData;
}
else
{
return nil;
}
}

Related

CoreData _NSIsNSSet EXC_BAD_ACCESS KERN_INVALID_ADDRESS - crash on app launch

We are getting this crash on multiple devices but cannot figure out where it originates from. The main thread is crashing.
Stack trace:
Crashed: com.apple.main-thread
0 libobjc.A.dylib 0x193dfd58c object_getMethodImplementation + 20
1 CoreFoundation 0x1940f6928 _NSIsNSSet + 40
2 CoreFoundation 0x193fc2c04 -[NSMutableSet unionSet:] + 112
3 CoreData 0x198abe014 -[_NSFaultingMutableSet willReadWithContents:] + 668
4 CoreData 0x198ae4280 -[_NSFaultingMutableSet count] + 32
5 CoreData 0x198be1bb4 __107-[NSManagedObjectContext(_NestedContextSupport) newValueForRelationship:forObjectWithID:withContext:error:]_block_invoke + 360
6 CoreData 0x198be2e70 internalBlockToNSManagedObjectContextPerform + 104
7 libdispatch.dylib 0x193d8b5ac _dispatch_client_callout + 20
8 libdispatch.dylib 0x193d9843c _dispatch_async_and_wait_invoke + 96
9 libdispatch.dylib 0x193d8b5ac _dispatch_client_callout + 20
10 libdispatch.dylib 0x193d977d4 _dispatch_main_queue_callback_4CF + 832
11 CoreFoundation 0x1940648d4 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 16
12 CoreFoundation 0x19405f58c __CFRunLoopRun + 1692
13 CoreFoundation 0x19405ebc8 CFRunLoopRunSpecific + 480
14 GraphicsServices 0x19e4475cc GSEventRunModal + 164
15 UIKitCore 0x198211744 UIApplicationMain + 1936
16 My App 0x100b37324 main + 16 (main.m:16)
17 libdyld.dylib 0x193edb384 start + 4
At the same time, a background thread operating in a PrivateQueue ManagedObjectContext is busy accessing a ManagedObject via awakeFromFetch, stack trace of this thread:
NSManagedObjectContext 0x28066c700
0 libsystem_kernel.dylib 0x1b09617e4 __ulock_wait + 8
1 libdispatch.dylib 0x1b081bf48 _dlock_wait + 56
2 libdispatch.dylib 0x1b081bcf4 _dispatch_thread_event_wait_slow + 56
3 libdispatch.dylib 0x1b0828618 __DISPATCH_WAIT_FOR_QUEUE__ + 336
4 libdispatch.dylib 0x1b0828204 _dispatch_sync_f_slow + 144
5 CoreData 0x1b56686cc _perform + 200
6 CoreData 0x1b558e2c4 -[NSManagedObjectContext(_NestedContextSupport) newValueForRelationship:forObjectWithID:withContext:error:] + 156
7 CoreData 0x1b555033c -[NSFaultHandler retainedFulfillAggregateFaultForObject:andRelationship:withContext:] + 428
8 CoreData 0x1b554df10 -[_NSFaultingMutableSet willReadWithContents:] + 408
9 CoreData 0x1b55ea5bc -[_NSFaultingMutableSet allObjects] + 32
10 My App 0x1044fdc3c PSUser.isAdmin.getter + 286 (PSUser.swift:286)
11 My App 0x1044fdb04 #objc PSUser.isAdmin.getter + 4309900036 (<compiler-generated>:4309900036)
12 My App 0x1044fc694 PSUser.initCurrentTeam() + 212 (PSUser.swift:212)
13 My App 0x1044fcbc0 #objc PSUser.initCurrentTeam() + 4309896128 (<compiler-generated>:4309896128)
14 My App 0x1044fc658 #objc PSUser.awakeFromFetch() + 4309894744 (<compiler-generated>:4309894744)
15 CoreData 0x1b56520e4 _PFFaultHandlerFulfillFault + 3168
16 CoreData 0x1b5650ab0 _PFFaultHandlerLookupRow + 908
17 CoreData 0x1b56527fc _PF_FulfillDeferredFault + 260
18 CoreData 0x1b5666a2c _pvfk_header + 120
19 CoreData 0x1b5663218 _sharedIMPL_pvfk_core + 32
20 My App 0x10438918c +[PSAppSettings isAutoPilotAllowed:] + 97 (PSAppSettings.m:97)
21 My App 0x1043fbb9c LocationTracker.updateTrackingState(user:) + 1120 (LocationTracker.swift:1120)
22 My App 0x104413b4c partial apply for closure #1 in LocationTracker.store(filteredLocations:) + 1275 (LocationTracker.swift:1275)
23 My App 0x1043bae3c thunk for #escaping #callee_guaranteed () -> () + 4308577852 (<compiler-generated>:4308577852)
24 CoreData 0x1b566b650 developerSubmittedBlockToNSManagedObjectContextPerform + 164
25 libdispatch.dylib 0x1b081b5ac _dispatch_client_callout + 20
26 libdispatch.dylib 0x1b0821a64 _dispatch_lane_serial_drain + 568
27 libdispatch.dylib 0x1b0822498 _dispatch_lane_invoke + 400
28 libdispatch.dylib 0x1b082ba5c _dispatch_workloop_worker_thread + 584
29 libsystem_pthread.dylib 0x1b0881718 _pthread_wqthread + 276
30 libsystem_pthread.dylib 0x1b08879c8 start_wqthread + 8
I am not certain if the two stacks are related, or if the background thread is dispatching anything to the main thread (why should it?), but the call newValueForRelationship:forObjectWithID:withContext:error does appear in both stack traces.
The method for awakeFromFetch is initializing a calculated object property currentTeam via the initCurrentTeam() method. This method accesses the teams relationship on that object. Here is the relevant code:
#objc extension PSUser {
override open func awakeFromFetch() {
super.awakeFromFetch()
initCurrentTeam()
}
/**
This method sets the currentTeam by picking
the appropriate team from the `teams` set.
*/
func initCurrentTeam() {
if (isAdmin || isManager), !isEmployee,
var teams = teams?.allObjects as? [PSTeam],
currentTeam == nil {
...
currentTeam = teams.first
}
}
...
}
Enabled com.apple.CoreData.ConcurrencyDebug in Xcode Scheme but Xcode console does not complain. I have not been able to reproduce this issue while debugging in Xcode. The issue is only reported via Crashlytics in production environment.
Any ideas what might be causing this?

Incorrect strange nonsense making iOS Crashlytics reports due to insufficient free ram?

I have a concerning amount of crashes for my iOS app. When I look at the stacktrace I can follow the flow of the stacktrace up until the 3d line 'fetchDeezerTracks(forAlbum)'. When inspecting my code it should be impossible for this line to be even called. the ApplePlayerManager.play method calls the ApplePlayerManager.fetchTrackIds method which calls a NetworkManager's 'fetchAppleMusicTracks' and this method has a networkRequestResponseHandler to deal with the fetched data, but NEVER ever should/could the 'fetchDeezerTracks' method be called.
My question is the following: Is it possible for Crashlytics to give incorrect reports maybe when the device's free RAM is insufficient? Maybe due to memory leaks or something... I just can't make sense out of the crash report so it would help me a lot to know if something else is at play. Some of the free RAM values of the multiple reports (of the same crash) are the following:
233MB (iPad Air 2), 8MB (iPAad 5th gen), 198MB (iPad Mini 2), 332MB (iPad Mini), 71MB (iPad Air 2), 174MB (iPad 5th gen), 223MB (iPad Air 2), 130MB (iPhone6+), 58MB (iPhoneXR), 381MB (iPhoneXSMax), etc.
Are these normal values?
If these are normal values and crashlytics reports are never "corrupted" then I need to make sense of the stacktrace. I'll add my networking code for reference.
Any help very much appreciated! This is driving me mad and crashes keep on piling up.
Crashed: com.apple.root.background-qos
0 MyApp 0x10045da40 closure #2 in ApplePlayerManager.play(album:withTrack:) + 4302494272 (<compiler-generated>:4302494272)
1 MyApp 0x10045d884 closure #1 in closure #1 in ApplePlayerManager.fetchTrackIds(forAlbum:completionHandler:) + 4302493828 (<compiler-generated>:4302493828)
2 MyApp 0x1004da218 specialized NetworkManager.networkRequestResponseHandler(withResponse:completionHandler:retryHandler:) + 4303004184 (<compiler-generated>:4303004184)
3 MyApp 0x1004d9404 closure #1 in NetworkManager.fetchDeezerTracks(forAlbum:withAccessToken:withCompletionHandler:) + 4303000580
4 MyApp 0x1004d8294 closure #1 in NetworkManager.fetchAppleMusicTracks(forAlbumID:withAccessToken:withCompletionHandler:) + 4302996116
5 Alamofire 0x100a73e64 $s9Alamofire15DownloadRequestC8response5queue0D10Serializer17completionHandlerACXDSo012OS_dispatch_E0CSg_xyAA0B8ResponseVy16SerializedObjectQzGctAA0bkF8ProtocolRzlFyycfU_yycfU_AA0bkF0VyypG_Tg5Tm + 132
6 Alamofire 0x100a79d08 $s9Alamofire15DownloadRequestC8response5queue0D10Serializer17completionHandlerACXDSo012OS_dispatch_E0CSg_xyAA0B8ResponseVy16SerializedObjectQzGctAA0bkF8ProtocolRzlFyycfU_yycfU_AA0bkF0VyypG_Tg5TATm + 36
7 Alamofire 0x100a5b3b0 $sIeg_IeyB_TR + 28
8 libdispatch.dylib 0x18f0eb9a8 _dispatch_call_block_and_release + 24
9 libdispatch.dylib 0x18f0ec524 _dispatch_client_callout + 16
10 libdispatch.dylib 0x18f0a156c _dispatch_root_queue_drain + 684
11 libdispatch.dylib 0x18f0a1bf8 _dispatch_worker_thread2 + 124
12 libsystem_pthread.dylib 0x18f13db38 _pthread_wqthread + 212
13 libsystem_pthread.dylib 0x18f140740 start_wqthread + 8
How I fetch my trackIds (NetworkManager)
func fetchAppleMusicTracks(forAlbumID albumID:String,
withAccessToken accessToken:String,
withCompletionHandler completionHandler:#escaping(JSON?)->Void) {
let url = kAppleMusicAlbumURL + albumID
guard let encodedURL = url.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) else { return completionHandler(nil) }
let headers = [kAppleMusicAuthoritationKey : kAppleMusicBearerKey + accessToken]
Alamofire.request(encodedURL,
method: .get,
parameters: nil,
encoding: URLEncoding.default,
headers: headers).responseJSON(queue: backgroundQueue) {
[weak self]
response in
guard let self = self else { completionHandler(nil); return }
self.networkRequestResponseHandler(withResponse:response,
completionHandler:completionHandler) {
self.fetchAppleMusicTracks(forAlbumID: albumID,
withAccessToken: accessToken,
withCompletionHandler: completionHandler)
}
}
}
my network request handler (NetworkManager):
func networkRequestResponseHandler(withResponse response:DataResponse<Any>,
completionHandler: #escaping(JSON?)->Void,
retryHandler: #escaping()->Void) {
switch response.result {
case .success(let value):
completionHandler(JSON(value))
case .failure(let error):
if self.noConnectionValidator(forError: error, withRetryHandler:retryHandler) { return completionHandler(nil) }
if let status = response.response?.statusCode {
let message = BackendManager.sharedInstance.APIErrorMessageHandler(status: status)
AlertsManager.sharedInstance.displayAlertWithOKButton(forTitle: kGenericErrorTitle,
message: message,
buttonTitle: "Ok")
} else {
AlertsManager.sharedInstance.displayNetworkErrorMessage(withError: error)
}
completionHandler(nil)
}
}
method to fetch tracks (ApplePlayerManager):
private func fetchTrackIds(forAlbum album:String, completionHandler:#escaping([String]?)->Void) {
retrieveAccessToken {
accessToken in
guard let accessToken = accessToken else { completionHandler(nil); return }
NetworkManager.sharedInstance.fetchAppleMusicTracks(forAlbumID: album, withAccessToken: accessToken) {
JSON in
guard let JSON = JSON else {
completionHandler(nil)
return
}
if let tracks = JSON[kAppleMusicDataKey].array?[0][kAppleMusicRelationshipsKey][kAppleMusicTracksKey][kAppleMusicDataKey].array {
let trackIds = tracks.map{ $0[kAppleMusicTrackIdentifierKey].string }.compactMap{ $0 }
completionHandler(trackIds)
} else {
//AlertsManager.sharedInstance.displayAppleMusicCouldNotFetchTracks()
completionHandler(nil)
}
}
}
}
entry-point -> method to play an Apple track (ApplePlayerManager):
override public func play(album:String, withTrack track:Int) {
super.play(album: album, withTrack: track)
guard let streamingManager = streamingManager else { return setup { self.play(album: album, withTrack: track) } }
indexOfLastPlayingItem = track
fetchTrackIds(forAlbum: album) {
[weak self]
trackIds in
guard let self = self else { return }
guard let trackIds = trackIds else {
return //AlertsManager.sharedInstance.displayAppleMusicTracksFetchFailed()
}
self.loadedAlbumTrackIDs = trackIds
if let remainingTracks = self.calculateRemainingTrackList(fromCurrentTrack: track) {
ThreadManager.sharedInstance.executeOnMainThread {
self.play(forStreamingManager: streamingManager, remainingTracks: remainingTracks)
}
}
}
}
EDIT - MORE INFO:
Since my app is using multiple services, I made an abstract PlayerManager singleton class with concrete singleton subclasses for every service. so the PlayerManager.play(track: trackId) will call the correct concrete class method on ApplePlayerManager if beforehand the PlayerManager.service is set to .Apple
I know it looks like somewhere in code the singleton has incorrectly changed service, but again it would not make any sense + I can not reproduce it nor getting a breakpoint hit.
EDIT PART II - ALL THREADS STACKTRACES:
I am getting the suspicion that this might be thread related? Here are all the threads:
Crashed: com.apple.root.background-qos
EXC_BREAKPOINT 0x0000000104cd5a40
Crashed: com.apple.root.background-qos
0 MyApp 0x104cd5a40 closure #2 in ApplePlayerManager.play(album:withTrack:) + 4376304192 (<compiler-generated>:4376304192)
1 MyApp 0x104cd5884 closure #1 in closure #1 in ApplePlayerManager.fetchTrackIds(forAlbum:completionHandler:) + 4376303748 (<compiler-generated>:4376303748)
2 MyApp 0x104d52218 specialized NetworkManager.networkRequestResponseHandler(withResponse:completionHandler:retryHandler:) + 4376814104 (<compiler-generated>:4376814104)
3 MyApp 0x104d51404 closure #1 in NetworkManager.fetchDeezerTracks(forAlbum:withAccessToken:withCompletionHandler:) + 4376810500
4 MyApp 0x104d50294 closure #1 in NetworkManager.fetchAppleMusicTracks(forAlbumID:withAccessToken:withCompletionHandler:) + 4376806036
5 Alamofire 0x105313e64 $s9Alamofire15DownloadRequestC8response5queue0D10Serializer17completionHandlerACXDSo012OS_dispatch_E0CSg_xyAA0B8ResponseVy16SerializedObjectQzGctAA0bkF8ProtocolRzlFyycfU_yycfU_AA0bkF0VyypG_Tg5Tm + 132
6 Alamofire 0x105319d08 $s9Alamofire15DownloadRequestC8response5queue0D10Serializer17completionHandlerACXDSo012OS_dispatch_E0CSg_xyAA0B8ResponseVy16SerializedObjectQzGctAA0bkF8ProtocolRzlFyycfU_yycfU_AA0bkF0VyypG_Tg5TATm + 36
7 Alamofire 0x1052fb3b0 $sIeg_IeyB_TR + 28
8 libdispatch.dylib 0x1b2e9a9a8 _dispatch_call_block_and_release + 24
9 libdispatch.dylib 0x1b2e9b524 _dispatch_client_callout + 16
10 libdispatch.dylib 0x1b2e8165c _dispatch_root_queue_drain + 640
11 libdispatch.dylib 0x1b2e81cd0 _dispatch_worker_thread2 + 112
12 libsystem_pthread.dylib 0x1b2eecb38 _pthread_wqthread + 212
13 libsystem_pthread.dylib 0x1b2eef740 start_wqthread + 8
com.apple.main-thread
com.apple.main-thread
0 libsystem_kernel.dylib 0x1b2fa9198 mach_msg_trap + 8
1 libsystem_kernel.dylib 0x1b2fa860c mach_msg + 72
2 CoreFoundation 0x1b31533b4 __CFRunLoopServiceMachPort + 148
3 CoreFoundation 0x1b314e3e8 __CFRunLoopRun + 1160
4 CoreFoundation 0x1b314dc34 CFRunLoopRunSpecific + 424
5 GraphicsServices 0x1bd29738c GSEventRunModal + 160
6 UIKitCore 0x1b728022c UIApplicationMain + 1932
7 MyApp 0x104cd1060 main + 12 (AppDelegate.swift:12)
8 libdyld.dylib 0x1b2fd5800 start + 4
com.apple.uikit.eventfetch-thread
com.apple.uikit.eventfetch-thread
0 libsystem_kernel.dylib 0x1b2fa9198 mach_msg_trap + 8
1 libsystem_kernel.dylib 0x1b2fa860c mach_msg + 72
2 CoreFoundation 0x1b31533b4 __CFRunLoopServiceMachPort + 148
3 CoreFoundation 0x1b314e3e8 __CFRunLoopRun + 1160
4 CoreFoundation 0x1b314dc34 CFRunLoopRunSpecific + 424
5 Foundation 0x1b3490bcc -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 228
6 Foundation 0x1b3490aac -[NSRunLoop(NSRunLoop) runUntilDate:] + 88
7 UIKitCore 0x1b7322160 -[UIEventFetcher threadMain] + 152
8 Foundation 0x1b35bf9d0 __NSThread__start__ + 848
9 libsystem_pthread.dylib 0x1b2eebd98 _pthread_start + 156
10 libsystem_pthread.dylib 0x1b2eef74c thread_start + 8
com.twitter.crashlytics.ios.MachExceptionServer
com.twitter.crashlytics.ios.MachExceptionServer
0 MyApp 0x104d7b448 CLSProcessRecordAllThreads + 4376982600
1 MyApp 0x104d7b830 CLSProcessRecordAllThreads + 4376983600
2 MyApp 0x104d6b09c CLSHandler + 4376916124
3 MyApp 0x104d66ac4 CLSMachExceptionServer + 4376898244
4 libsystem_pthread.dylib 0x1b2eebd98 _pthread_start + 156
5 libsystem_pthread.dylib 0x1b2eef74c thread_start + 8
com.apple.root.background-qos
com.apple.root.background-qos
0 libsystem_malloc.dylib 0x1b2ec6154 calloc + 98
1 CoreFoundation 0x1b31e23c4 __CFAllocateObject + 20
2 CoreFoundation 0x1b3205b38 __NSDictionaryM_new + 128
3 Foundation 0x1b3586e68 _encodeObject + 964
4 Foundation 0x1b34a2334 -[NSKeyedArchiver _encodeArrayOfObjects:forKey:] + 360
5 Foundation 0x1b3586f58 _encodeObject + 1204
6 MyApp 0x104d372f8 Album.encode(with:) + 4376703736 (<compiler-generated>:4376703736)
7 MyApp 0x104d37354 #objc Album.encode(with:) + 4376703828 (<compiler-generated>:4376703828)
8 Foundation 0x1b3586f58 _encodeObject + 1204
9 Foundation 0x1b34a2334 -[NSKeyedArchiver _encodeArrayOfObjects:forKey:] + 360
10 Foundation 0x1b3586f58 _encodeObject + 1204
11 MyApp 0x104cec884 Series.encode(with:) + 4376397956 (<compiler-generated>:4376397956)
12 MyApp 0x104cec93c #objc Series.encode(with:) + 4376398140 (<compiler-generated>:4376398140)
13 Foundation 0x1b3586f58 _encodeObject + 1204
14 Foundation 0x1b34a2334 -[NSKeyedArchiver _encodeArrayOfObjects:forKey:] + 360
15 Foundation 0x1b3586f58 _encodeObject + 1204
16 MyApp 0x104cfcaf0 User.encode(with:) + 4376464112 (<compiler-generated>:4376464112)
17 MyApp 0x104cfcc64 #objc User.encode(with:) + 4376464484 (<compiler-generated>:4376464484)
18 Foundation 0x1b3586f58 _encodeObject + 1204
19 Foundation 0x1b34a2334 -[NSKeyedArchiver _encodeArrayOfObjects:forKey:] + 360
20 Foundation 0x1b34ccea0 -[NSDictionary(NSDictionary) encodeWithCoder:] + 876
21 Foundation 0x1b3586f58 _encodeObject + 1204
22 Foundation 0x1b34ed5c8 +[NSKeyedArchiver archivedDataWithRootObject:] + 124
23 SwiftyUserDefaults 0x105c9b8c4 $sSo14NSUserDefaultsC010SwiftyUserB0E7archiveyyAC0B3KeyCyxSgG_AGtlF + 292
24 MyApp 0x104d3a7f8 closure #1 in UserManager._cachedSavedUsers.didset + 4376717304 (<compiler-generated>:4376717304)
25 MyApp 0x104d05e10 partial apply for closure #1 in ThreadManager.executeOnMainThread(afterSeconds:withBlock:) + 4376501776 (<compiler-generated>:4376501776)
26 MyApp 0x104d5fc98 thunk for #escaping #callee_guaranteed () -> () + 4376870040 (<compiler-generated>:4376870040)
27 libdispatch.dylib 0x1b2e9a9a8 _dispatch_call_block_and_release + 24
28 libdispatch.dylib 0x1b2e9b524 _dispatch_client_callout + 16
29 libdispatch.dylib 0x1b2e8165c _dispatch_root_queue_drain + 640
30 libdispatch.dylib 0x1b2e81cd0 _dispatch_worker_thread2 + 112
31 libsystem_pthread.dylib 0x1b2eecb38 _pthread_wqthread + 212
32 libsystem_pthread.dylib 0x1b2eef740 start_wqthread + 8
com.apple.NSURLConnectionLoader
com.apple.NSURLConnectionLoader
0 libsystem_kernel.dylib 0x1b2fa9198 mach_msg_trap + 8
1 libsystem_kernel.dylib 0x1b2fa860c mach_msg + 72
2 CoreFoundation 0x1b31533b4 __CFRunLoopServiceMachPort + 148
3 CoreFoundation 0x1b314e3e8 __CFRunLoopRun + 1160
4 CoreFoundation 0x1b314dc34 CFRunLoopRunSpecific + 424
5 CFNetwork 0x1b6412c44 (Missing)
6 Foundation 0x1b35bf9d0 __NSThread__start__ + 848
7 libsystem_pthread.dylib 0x1b2eebd98 _pthread_start + 156
8 libsystem_pthread.dylib 0x1b2eef74c thread_start + 8
com.apple.root.background-qos
com.apple.root.background-qos
0 libsystem_platform.dylib 0x1b2edd948 _platform_memmove + 88
1 libsystem_malloc.dylib 0x1b2ebc628 szone_realloc + 544
2 libsystem_malloc.dylib 0x1b2ec5a9c malloc_zone_realloc + 168
3 libsystem_malloc.dylib 0x1b2ec625c realloc + 196
4 CoreFoundation 0x1b30f3948 __CFSafelyReallocate + 28
5 Foundation 0x1b3555ea0 _NSMutableDataGrowBytes + 344
6 Foundation 0x1b34a2a34 -[NSConcreteMutableData appendBytes:length:] + 340
7 CoreFoundation 0x1b30fcfac writeBytes + 164
8 CoreFoundation 0x1b30fa01c bufferWrite + 320
9 CoreFoundation 0x1b30fd144 _appendString + 264
10 CoreFoundation 0x1b30fa1b8 _appendObject + 348
11 CoreFoundation 0x1b30f99fc __CFBinaryPlistWriteOrPresize + 528
12 Foundation 0x1b34a27d0 -[NSKeyedArchiver finishEncoding] + 528
13 Foundation 0x1b34ed5d8 +[NSKeyedArchiver archivedDataWithRootObject:] + 140
14 SwiftyUserDefaults 0x105c9b8c4 $sSo14NSUserDefaultsC010SwiftyUserB0E7archiveyyAC0B3KeyCyxSgG_AGtlF + 292
15 MyApp 0x104d3a3bc closure #1 in UserManager._cachedActiveUser.didset + 4376716220 (<compiler-generated>:4376716220)
16 MyApp 0x104d05e10 partial apply for closure #1 in ThreadManager.executeOnMainThread(afterSeconds:withBlock:) + 4376501776 (<compiler-generated>:4376501776)
17 MyApp 0x104d5fc98 thunk for #escaping #callee_guaranteed () -> () + 4376870040 (<compiler-generated>:4376870040)
18 libdispatch.dylib 0x1b2e9a9a8 _dispatch_call_block_and_release + 24
19 libdispatch.dylib 0x1b2e9b524 _dispatch_client_callout + 16
20 libdispatch.dylib 0x1b2e8165c _dispatch_root_queue_drain + 640
21 libdispatch.dylib 0x1b2e81cd0 _dispatch_worker_thread2 + 112
22 libsystem_pthread.dylib 0x1b2eecb38 _pthread_wqthread + 212
23 libsystem_pthread.dylib 0x1b2eef740 start_wqthread + 8
AVAudioSession Notify Thread
AVAudioSession Notify Thread
0 libsystem_kernel.dylib 0x1b2fa9198 mach_msg_trap + 8
1 libsystem_kernel.dylib 0x1b2fa860c mach_msg + 72
2 CoreFoundation 0x1b31533b4 __CFRunLoopServiceMachPort + 148
3 CoreFoundation 0x1b314e3e8 __CFRunLoopRun + 1160
4 CoreFoundation 0x1b314dc34 CFRunLoopRunSpecific + 424
5 AVFAudio 0x1bfef65dc GenericRunLoopThread::Entry(void*) + 156
6 AVFAudio 0x1bff47300 CAPThread::Entry(CAPThread*) + 204
7 libsystem_pthread.dylib 0x1b2eebd98 _pthread_start + 156
8 libsystem_pthread.dylib 0x1b2eef74c thread_start + 8
Thread #1
Thread
0 libsystem_kernel.dylib 0x1b2fcb940 __workq_kernreturn + 8
1 libsystem_pthread.dylib 0x1b2eecbc0 _pthread_wqthread + 348
2 libsystem_pthread.dylib 0x1b2eef740 start_wqthread + 8
Thread #2
Thread
0 libsystem_pthread.dylib 0x1b2eef738 start_wqthread + 190
com.apple.root.background-qos
com.apple.root.background-qos
0 CoreFoundation 0x1b3206828 mdict_rehashd + 244
1 CoreFoundation 0x1b30b8f00 -[__NSDictionaryM __setObject:forKey:] + 888
2 Foundation 0x1b35876d8 addValueToTopContainerE + 128
3 Foundation 0x1b3587180 _encodeObject + 1756
4 Foundation 0x1b34a2334 -[NSKeyedArchiver _encodeArrayOfObjects:forKey:] + 360
5 Foundation 0x1b3586f58 _encodeObject + 1204
6 MyApp 0x104d372f8 Album.encode(with:) + 4376703736 (<compiler-generated>:4376703736)
7 MyApp 0x104d37354 #objc Album.encode(with:) + 4376703828 (<compiler-generated>:4376703828)
8 Foundation 0x1b3586f58 _encodeObject + 1204
9 Foundation 0x1b34a2334 -[NSKeyedArchiver _encodeArrayOfObjects:forKey:] + 360
10 Foundation 0x1b3586f58 _encodeObject + 1204
11 MyApp 0x104cec884 Series.encode(with:) + 4376397956 (<compiler-generated>:4376397956)
12 MyApp 0x104cec93c #objc Series.encode(with:) + 4376398140 (<compiler-generated>:4376398140)
13 Foundation 0x1b3586f58 _encodeObject + 1204
14 Foundation 0x1b34a2334 -[NSKeyedArchiver _encodeArrayOfObjects:forKey:] + 360
15 Foundation 0x1b3586f58 _encodeObject + 1204
16 MyApp 0x104cfcaf0 User.encode(with:) + 4376464112 (<compiler-generated>:4376464112)
17 MyApp 0x104cfcc64 #objc User.encode(with:) + 4376464484 (<compiler-generated>:4376464484)
18 Foundation 0x1b3586f58 _encodeObject + 1204
19 Foundation 0x1b34a2334 -[NSKeyedArchiver _encodeArrayOfObjects:forKey:] + 360
20 Foundation 0x1b34ccea0 -[NSDictionary(NSDictionary) encodeWithCoder:] + 876
21 Foundation 0x1b3586f58 _encodeObject + 1204
22 Foundation 0x1b34ed5c8 +[NSKeyedArchiver archivedDataWithRootObject:] + 124
23 SwiftyUserDefaults 0x105c9b8c4 $sSo14NSUserDefaultsC010SwiftyUserB0E7archiveyyAC0B3KeyCyxSgG_AGtlF + 292
24 MyApp 0x104d3a7f8 closure #1 in UserManager._cachedSavedUsers.didset + 4376717304 (<compiler-generated>:4376717304)
25 MyApp 0x104d05e10 partial apply for closure #1 in ThreadManager.executeOnMainThread(afterSeconds:withBlock:) + 4376501776 (<compiler-generated>:4376501776)
26 MyApp 0x104d5fc98 thunk for #escaping #callee_guaranteed () -> () + 4376870040 (<compiler-generated>:4376870040)
27 libdispatch.dylib 0x1b2e9a9a8 _dispatch_call_block_and_release + 24
28 libdispatch.dylib 0x1b2e9b524 _dispatch_client_callout + 16
29 libdispatch.dylib 0x1b2e8165c _dispatch_root_queue_drain + 640
30 libdispatch.dylib 0x1b2e81cd0 _dispatch_worker_thread2 + 112
31 libsystem_pthread.dylib 0x1b2eecb38 _pthread_wqthread + 212
32 libsystem_pthread.dylib 0x1b2eef740 start_wqthread + 8
com.apple.root.background-qos
com.apple.root.background-qos
0 libobjc.A.dylib 0x1b2f12aa8 objc_release + 24
1 libswiftCore.dylib 0x1c0914680 swift_arrayDestroy + 68
2 libswiftCore.dylib 0x1c06d38c8 _DictionaryStorage.deinit + 360
3 libswiftCore.dylib 0x1c06d394c _DictionaryStorage.__deallocating_deinit + 12
4 libswiftCore.dylib 0x1c091e320 _swift_release_dealloc + 28
5 SwiftyJSON 0x105c396d0 $s10SwiftyJSON6unwrap33_4625CC38AABF536BB76490A35D7233C9LLyypypF + 1400
6 SwiftyJSON 0x105c394a4 $s10SwiftyJSON6unwrap33_4625CC38AABF536BB76490A35D7233C9LLyypypF + 844
7 SwiftyJSON 0x105c395d8 $s10SwiftyJSON6unwrap33_4625CC38AABF536BB76490A35D7233C9LLyypypF + 1152
8 SwiftyJSON 0x105c394a4 $s10SwiftyJSON6unwrap33_4625CC38AABF536BB76490A35D7233C9LLyypypF + 844
9 SwiftyJSON 0x105c394a4 $s10SwiftyJSON6unwrap33_4625CC38AABF536BB76490A35D7233C9LLyypypF + 844
10 SwiftyJSON 0x105c394a4 $s10SwiftyJSON6unwrap33_4625CC38AABF536BB76490A35D7233C9LLyypypF + 844
11 SwiftyJSON 0x105c395d8 $s10SwiftyJSON6unwrap33_4625CC38AABF536BB76490A35D7233C9LLyypypF + 1152
12 SwiftyJSON 0x105c394a4 $s10SwiftyJSON6unwrap33_4625CC38AABF536BB76490A35D7233C9LLyypypF + 844
13 SwiftyJSON 0x105c383e4 $s10SwiftyJSON0B0V6objectypvs + 44
14 SwiftyJSON 0x105c49ccc $s10SwiftyJSON0B0V10jsonObjectACyp_tc33_4625CC38AABF536BB76490A35D7233C9LlfCTf4nd_n + 164
15 SwiftyJSON 0x105c49f00 $s10SwiftyJSON0B0VyACypcfCTf4nd_n + 152
16 SwiftyJSON 0x105c381ac $s10SwiftyJSON0B0VyACypcfC + 28
17 MyApp 0x104d521e4 specialized NetworkManager.networkRequestResponseHandler(withResponse:completionHandler:retryHandler:) + 51 (NetworkManager.swift:51)
18 MyApp 0x104d51404 closure #1 in NetworkManager.fetchDeezerTracks(forAlbum:withAccessToken:withCompletionHandler:) + 4376810500
19 MyApp 0x104d50294 closure #1 in NetworkManager.fetchAppleMusicTracks(forAlbumID:withAccessToken:withCompletionHandler:) + 4376806036
20 Alamofire 0x105313e64 $s9Alamofire15DownloadRequestC8response5queue0D10Serializer17completionHandlerACXDSo012OS_dispatch_E0CSg_xyAA0B8ResponseVy16SerializedObjectQzGctAA0bkF8ProtocolRzlFyycfU_yycfU_AA0bkF0VyypG_Tg5Tm + 132
21 Alamofire 0x105319d08 $s9Alamofire15DownloadRequestC8response5queue0D10Serializer17completionHandlerACXDSo012OS_dispatch_E0CSg_xyAA0B8ResponseVy16SerializedObjectQzGctAA0bkF8ProtocolRzlFyycfU_yycfU_AA0bkF0VyypG_Tg5TATm + 36
22 Alamofire 0x1052fb3b0 $sIeg_IeyB_TR + 28
23 libdispatch.dylib 0x1b2e9a9a8 _dispatch_call_block_and_release + 24
24 libdispatch.dylib 0x1b2e9b524 _dispatch_client_callout + 16
25 libdispatch.dylib 0x1b2e8165c _dispatch_root_queue_drain + 640
26 libdispatch.dylib 0x1b2e81cd0 _dispatch_worker_thread2 + 112
27 libsystem_pthread.dylib 0x1b2eecb38 _pthread_wqthread + 212
28 libsystem_pthread.dylib 0x1b2eef740 start_wqthread + 8
com.google.fira.worker
com.google.fira.worker
0 libsqlite3.dylib 0x1b4df32a8 sqlite3_exec + 26552
1 libsqlite3.dylib 0x1b4dee810 sqlite3_exec + 7456
2 libsqlite3.dylib 0x1b4ded6fc sqlite3_exec + 3084
3 libsqlite3.dylib 0x1b4decc3c sqlite3_exec + 332
4 MyApp 0x104e1d0cc -[APMSqliteStore beginTransaction] + 4377645260
5 MyApp 0x104e1cf18 -[APMSqliteStore performTransactionWithError:block:] + 4377644824
6 MyApp 0x104dd9444 -[APMDatabase performTransaction:] + 4377367620
7 MyApp 0x104df2a5c -[APMMeasurement writeEventOnWorkerQueue:] + 4377471580
8 MyApp 0x104df2280 -[APMMeasurement handleEventOnWorkerQueue:] + 4377469568
9 MyApp 0x104df1500 __27-[APMMeasurement logEvent:]_block_invoke + 4377466112
10 MyApp 0x104e06f50 __51-[APMScheduler scheduleOnWorkerQueueBlockID:block:]_block_invoke + 4377554768
11 libdispatch.dylib 0x1b2e9a9a8 _dispatch_call_block_and_release + 24
12 libdispatch.dylib 0x1b2e9b524 _dispatch_client_callout + 16
13 libdispatch.dylib 0x1b2e78b3c _dispatch_lane_serial_drain$VARIANT$armv81 + 564
14 libdispatch.dylib 0x1b2e7954c _dispatch_lane_invoke$VARIANT$armv81 + 396
15 libdispatch.dylib 0x1b2e8284c _dispatch_workloop_worker_thread + 580
16 libsystem_pthread.dylib 0x1b2eecb74 _pthread_wqthread + 272
17 libsystem_pthread.dylib 0x1b2eef740 start_wqthread + 8
(Just a guess)
This reeks of threading issues (you can get odd threading cashes if you try and access/manipulate the same object from different threads, and looking at your code you have escaping closures on escaping closures all over the place), looking through your crash log maybe it has something to do with the UserManager seeing: this UserManager._cachedSavedUsers.didset twice and UserManager._cachedActiveUser.didset too, always followed by some writes.
Even shows up on the thread labeled com.twitter.crashlytics.ios.MachExceptionServer but that could be for any reason, just suspicious given all this other stuff too and that crashlytics is your crash reporting tool..
App will definitely crash (intermittently) if there's some encoding / property manipulation happening on this user manager / an app-wide cache and its not being accessed in a thread safe way

iOS Crash SIGABRT happens sometimes

I've got an app in the Appstore which sometimes crashes. I havent been able to reproduce the bug.
The crash I get in Fabric.
Thread : Crashed: com.apple.root.default-qos
0 libsystem_kernel.dylib 0x0000000197b1b270 __pthread_kill + 8
1 libsystem_pthread.dylib 0x0000000197bb9228 pthread_kill + 112
2 libsystem_c.dylib 0x0000000197a92b18 abort + 112
3 libsystem_malloc.dylib 0x0000000197b563e4 _nano_malloc_check_clear
4 libsystem_malloc.dylib 0x0000000197b56550 _nano_malloc_check_clear + 364
5 libsystem_malloc.dylib 0x0000000197b55064 nano_malloc + 44
6 libsystem_malloc.dylib 0x0000000197b453e4 malloc_zone_malloc + 116
7 CoreFoundation 0x0000000186cb179c __CFBasicHashRehash + 264
8 CoreFoundation 0x0000000186cb2f8c __CFBasicHashAddValue + 100
9 CoreFoundation 0x0000000186b60454 CFDictionarySetValue + 252
10 ImageIO 0x0000000187e3fab0 initImagePng + 2800
11 ImageIO 0x0000000187e3e804 makeImagePlus + 1056
12 ImageIO 0x0000000187e3df30 CGImageSourceCreateImageAtIndex + 184
13 UIKit 0x000000018b57cd94 _UIImageRefFromData + 296
14 UIKit 0x000000018b6e156c -[UIImage(UIImagePrivate) _initWithData:preserveScale:cache:] + 112
15 UIKit 0x000000018b57cc3c +[UIImage imageWithData:] + 60
16 APP 0x000000010007b4f4 __28+[XTTeamLogo logo:callback:]_block_invoke (XTTeamLogo.m:94)
17 libdispatch.dylib 0x00000001979d93ac _dispatch_call_block_and_release + 24
18 libdispatch.dylib 0x00000001979d936c _dispatch_client_callout + 16
19 libdispatch.dylib 0x00000001979e540c _dispatch_root_queue_drain + 1152
20 libdispatch.dylib 0x00000001979e675c _dispatch_worker_thread3 + 108
21 libsystem_pthread.dylib 0x0000000197bb52e4 _pthread_wqthread + 816
So number 16 is one of my code which gives me a hint to check line number 94 in XTTeamLogo. Which contains this code:
__block XTTeamLogo *logo;
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_async(queue, ^(void) {
...SERVER REQUEST...
if (!localizedError) {
NSData *binary = [[[result getMessageByPath:#"DocumentData"] getPropertyByPath:#"Data"] binary];
if (binary) {
->(94) logo = [[XTTeamLogo alloc] initWithImage:[UIImage imageWithData:binary] fromCache:NO];
[[XTDisk sharedInstance] write:logo fileName:kPersistents];
[[XTCache sharedInstance] setObject:logo forKey:kPersistents];
}
}
... ERROR HANDLING ETC...
dispatch_async(dispatch_get_main_queue(), ^(void){
callback(logo, localizedError);
});
});
I assume from your comment "It is serverside resized..." that binary was loaded from the server.
What happens if your variable binary is not really your binary image data, but a String (i.e. which was received from a hotel network login page or other network foobar)?
Just try to check if XTTeamLogo can handle it
NSString* testString = #"dummy test string data. maybe it must be longer";
NSData* binary = [testString dataUsingEncoding:NSUTF8StringEncoding];
If this it is, you should check the mime-type of your network response before assuming that you have received your image data.

EXC_BAD_ACCESS when allocating an NSMutableArray

This is a bit of a weird one.
In my code, I have this line:
NSMutableArray *unresolvedPlayers = [NSMutableArray arrayWithCapacity:3];
This seems like a perfectly valid line. I crashed on this line with this stack trace (I have replaced my app name with xxxxxxxxx):
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Subtype: KERN_INVALID_ADDRESS at 0xc158f710
Triggered by Thread: 7
Thread 0 name: Dispatch queue: com.apple.main-thread
Thread 0:
0 libsystem_kernel.dylib 0x3870d648 syscall_thread_switch + 8
1 libsystem_platform.dylib 0x3879a79a _os_lock_handoff_lock_slow + 74
2 libsystem_malloc.dylib 0x38748ece szone_malloc_should_clear + 50
3 libsystem_malloc.dylib 0x3874c444 malloc_zone_calloc + 92
4 libsystem_malloc.dylib 0x3874c3d2 calloc + 46
5 libobjc.A.dylib 0x380c8414 class_createInstance + 36
6 CoreFoundation 0x2a5773d0 __CFAllocateObject2 + 8
7 CoreFoundation 0x2a48c86a +[__NSArrayM __new:::::] + 38
8 CoreFoundation 0x2a48fd7c -[__NSPlaceholderArray initWithCapacity:] + 100
9 CoreFoundation 0x2a497e88 +[NSMutableArray arrayWithCapacity:] + 36
10 xxxxxxxxxx 0x001730f4 -[HostManager setHost:timestamp:] (HostManager.m:703)
11 xxxxxxxxxx 0x0016ff10 -[HostManager initSessionFromInvitation:] (HostManager.m:46)
12 xxxxxxxxxx 0x000ea68e -[NetworkController updateWithMatch:] (NetworkController.m:894)
13 xxxxxxxxxx 0x000ea418 __72-[NetworkController invitePlayersToMatch:playerGroup:completionHandler:]_block_invoke544 (NetworkController.m:844)
14 GameCenterFoundation 0x31263936 __72-[GKMatchmaker invitePlayersWithRequest:serverHosted:completionHandler:]_block_invoke601 + 42
15 libdispatch.dylib 0x38620420 _dispatch_call_block_and_release + 8
16 libdispatch.dylib 0x3862040c _dispatch_client_callout + 20
17 libdispatch.dylib 0x3862b1b0 _dispatch_main_queue_callback_4CF$VARIANT$mp + 708
18 CoreFoundation 0x2a53762c __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 4
19 CoreFoundation 0x2a535d4c __CFRunLoopRun + 1508
20 CoreFoundation 0x2a482b2c CFRunLoopRunSpecific + 472
21 CoreFoundation 0x2a48293e CFRunLoopRunInMode + 102
22 GraphicsServices 0x3183904c GSEventRunModal + 132
23 UIKit 0x2da786ec UIApplicationMain + 1436
24 xxxxxxxxxx 0x000503b2 main (main.m:16)
25 libdyld.dylib 0x3865baac start + 0
How is it possible that my memory has gotten corrupted up to this point that allocating a new NSMutableArray would cause this to happen? I'm not even sure where to start with debugging this one. I am not sure this is easily reproducible.
As a side note, it happened when inviting nearby players to a realtime GameCenter match.
EDIT: I just realized this is crashing on Thread 7. This is what Thread 7 looks like:
Thread 7 name: Dispatch queue: com.apple.root.default-qos
Thread 7 Crashed:
0 libobjc.A.dylib 0x380cbf66 objc_msgSend + 6
1 GameCenterFoundation 0x31285efc -[GKMatchmaker(Nearby) inviteAnyNearbyPlayersWithRequest:] + 960
2 GameCenterFoundation 0x312636a8 __72-[GKMatchmaker invitePlayersWithRequest:serverHosted:completionHandler:]_block_invoke + 256
3 GameCenterFoundation 0x3129ae92 __39-[GKDispatchGroup notifyOnQueue:block:]_block_invoke44 + 10
4 libdispatch.dylib 0x38620420 _dispatch_call_block_and_release + 8
5 libdispatch.dylib 0x3862c2d6 _dispatch_root_queue_drain + 846
6 libdispatch.dylib 0x3862d1f6 _dispatch_worker_thread3 + 102
7 libsystem_pthread.dylib 0x3879de22 _pthread_wqthread + 666
8 libsystem_pthread.dylib 0x3879db74 start_wqthread + 4
So, this is probably a bug with GameCenter.
Crash in objc_msgSend can indicate that message destination object is deallocated already. Try to enable zombie objects and keep your eyes on logs.

iOS app crashing with "failed to launch in time"

One of my beta testers reported that my app was crashing repeatedly on her phone, of course when I went over to look at it there weren't any problems. But I pulled the crash log and am trying to figure out how to read these things. Two of them looked pretty similar (one is posted below). I just need someone to hold my hand a little bit when it comes to staring at these. I initially was suspecting memory issues but then someone said that memory leaks don't cause crashes unless you flood yourself, and this log doesn't mention anything about memory. Can anyone give me any hints on what might have happened?
Date/Time: 2012-12-19 10:09:05.852 -0700
OS Version: iOS 6.0.1 (10A523)
Report Version: 104
Exception Type: 00000020
Exception Codes: 0x000000008badf00d
Highlighted Thread: 0
Application Specific Information:
com.graphiteGames.Capture-This failed to launch in time
Elapsed total CPU time (seconds): 2.730 (user 2.730, system 0.000), 14% CPU
Elapsed application CPU time (seconds): 0.930, 5% CPU
Thread 0 name: Dispatch queue: com.apple.main-thread
Thread 0:
0 libsystem_kernel.dylib 0x33fc40fc __psynch_mutexwait + 24
1 libsystem_c.dylib 0x35438124 pthread_mutex_lock + 388
2 Capture This 0x000a1a7a -[PFObject objectForKey:] (PFObject.m:1572)
3 Capture This 0x00092c06 -[RootTableView tableView:cellForRowAtIndexPath:] (RootTableView.m:228)
4 UIKit 0x37f49540 -[UITableView(UITableViewInternal) _createPreparedCellForGlobalRow:withIndexPath:] + 408
5 UIKit 0x37f2e306 -[UITableView(_UITableViewPrivate) _updateVisibleCellsNow:] + 1306
6 UIKit 0x37f457c2 -[UITableView layoutSubviews] + 202
7 UIKit 0x37f017fe -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 254
8 QuartzCore 0x30db5d5e -[CALayer layoutSublayers] + 210
9 QuartzCore 0x30db58fc CA::Layer::layout_if_needed(CA::Transaction*) + 456
10 QuartzCore 0x30de47a2 -[CALayer layoutIfNeeded] + 138
11 UIKit 0x37fab0c4 -[UIViewController window:setupWithInterfaceOrientation:] + 204
12 UIKit 0x37faa2b0 -[UIWindow _setRotatableClient:toOrientation:updateStatusBar:duration:force:isRotating:] + 3616
13 UIKit 0x37fa9482 -[UIWindow _setRotatableClient:toOrientation:updateStatusBar:duration:force:] + 42
14 UIKit 0x37fa940c -[UIWindow _setRotatableViewOrientation:duration:force:] + 64
15 UIKit 0x380df17c __57-[UIWindow _updateToInterfaceOrientation:duration:force:]_block_invoke_0 + 100
16 UIKit 0x37f67676 -[UIWindow _updateToInterfaceOrientation:duration:force:] + 214
17 UIKit 0x37f673b8 -[UIWindow setAutorotates:forceUpdateInterfaceOrientation:] + 688
18 UIKit 0x37f66d26 -[UIViewController _tryBecomeRootViewControllerInWindow:] + 154
19 UIKit 0x37f5de9e -[UIWindow addRootViewControllerViewIfPossible] + 366
20 UIKit 0x37f59ae0 -[UIWindow _setHidden:forced:] + 360
21 UIKit 0x37f9b1c4 -[UIWindow makeKeyAndVisible] + 56
22 UIKit 0x37f5e832 -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1662
23 UIKit 0x37f5683e -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 694
24 UIKit 0x37efec34 -[UIApplication handleEvent:withNewEvent:] + 1000
25 UIKit 0x37efe6c8 -[UIApplication sendEvent:] + 68
26 UIKit 0x37efe116 _UIApplicationHandleEvent + 6150
27 GraphicsServices 0x34b1e5a0 _PurpleEventCallback + 588
28 GraphicsServices 0x34b1e1ce PurpleEventCallback + 30
29 CoreFoundation 0x35e34170 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 32
30 CoreFoundation 0x35e34112 __CFRunLoopDoSource1 + 134
31 CoreFoundation 0x35e32f94 __CFRunLoopRun + 1380
32 CoreFoundation 0x35da5eb8 CFRunLoopRunSpecific + 352
33 CoreFoundation 0x35da5d44 CFRunLoopRunInMode + 100
34 UIKit 0x37f55478 -[UIApplication _run] + 664
35 UIKit 0x37f522f4 UIApplicationMain + 1116
36 Capture This 0x0008b8ba main (main.m:16)
37 libdyld.dylib 0x34a94b1c start + 0
Thread 1 name: Dispatch queue: com.apple.libdispatch-manager
Thread 1:
0 libsystem_kernel.dylib 0x33fb4648 kevent64 + 24
1 libdispatch.dylib 0x34a7d4ec _dispatch_mgr_invoke + 792
2 libdispatch.dylib 0x34a6fdf4 _dispatch_mgr_thread$VARIANT$up + 32
Thread 2 name: Dispatch queue: com.apple.root.default-priority
Thread 2:
0 libsystem_kernel.dylib 0x33fc408c __psynch_cvwait + 24
1 libsystem_c.dylib 0x35440d2a _pthread_cond_wait + 642
2 libsystem_c.dylib 0x3544af14 pthread_cond_wait + 36
3 Foundation 0x3592aa4c -[__NSOperationInternal waitUntilFinished] + 144
4 Capture This 0x000e4710 -[PFNetworkCommandRunner runInOperation:callback:] (PFNetworkCommandRunner.m:84)
5 Capture This 0x000e4f1e -[PFRetryingCommandRunner runInOperation:callback:] (PFRetryingCommandRunner.m:52)
6 Capture This 0x000e5cba -[PFOperation runInThisThread:] (PFOperation.m:32)
7 Capture This 0x0009dbb2 -[PFObject(Private) fetchWithLocking:error:] (PFObject.m:942)
8 Capture This 0x000ae44e -[PFUser fetchWithLocking:error:] (PFUser.m:1001)
9 Capture This 0x000a1520 __39-[PFObject fetchInBackgroundWithBlock:]_block_invoke_0 (PFObject.m:1500)
10 Capture This 0x000d3db6 __25-[PFBackgroundTask start]_block_invoke_0 (PFBackgroundTask.m:59)
11 libdispatch.dylib 0x34a6e11c _dispatch_call_block_and_release + 8
12 libdispatch.dylib 0x34a7c254 _dispatch_root_queue_drain + 256
13 libdispatch.dylib 0x34a7c3b4 _dispatch_worker_thread2 + 80
14 libsystem_c.dylib 0x3543da0e _pthread_wqthread + 358
15 libsystem_c.dylib 0x3543d8a0 start_wqthread + 4
Thread 3 name: WebThread
Thread 3:
0 libsystem_kernel.dylib 0x33fb3eb4 mach_msg_trap + 20
1 libsystem_kernel.dylib 0x33fb4048 mach_msg + 36
2 CoreFoundation 0x35e34040 __CFRunLoopServiceMachPort + 124
3 CoreFoundation 0x35e32d9e __CFRunLoopRun + 878
4 CoreFoundation 0x35da5eb8 CFRunLoopRunSpecific + 352
5 CoreFoundation 0x35da5d44 CFRunLoopRunInMode + 100
6 WebCore 0x31a8aa40 _ZL12RunWebThreadPv + 440
7 libsystem_c.dylib 0x3544830e _pthread_start + 306
8 libsystem_c.dylib 0x354481d4 thread_start + 4
Thread 4:
0 libsystem_kernel.dylib 0x33fb3eb4 mach_msg_trap + 20
1 libsystem_kernel.dylib 0x33fb4048 mach_msg + 36
2 CoreFoundation 0x35e34040 __CFRunLoopServiceMachPort + 124
3 CoreFoundation 0x35e32d9e __CFRunLoopRun + 878
4 CoreFoundation 0x35da5eb8 CFRunLoopRunSpecific + 352
5 CoreFoundation 0x35da5d44 CFRunLoopRunInMode + 100
6 Foundation 0x358df78a -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 250
7 Foundation 0x35983058 -[NSRunLoop(NSRunLoop) run] + 76
8 Capture This 0x000d7c9a +[PFNetworkingUtils networkThreadMain] (PFNetworkingUtils.m:32)
9 Foundation 0x3598c678 __NSThread__main__ + 968
10 libsystem_c.dylib 0x3544830e _pthread_start + 306
11 libsystem_c.dylib 0x354481d4 thread_start + 4
Thread 5:
0 libsystem_kernel.dylib 0x33fc4d98 __workq_kernreturn + 8
1 libsystem_c.dylib 0x3543dcf6 _pthread_workq_return + 14
2 libsystem_c.dylib 0x3543da12 _pthread_wqthread + 362
3 libsystem_c.dylib 0x3543d8a0 start_wqthread + 4
Thread 6:
0 libsystem_kernel.dylib 0x33fc408c __psynch_cvwait + 24
1 libsystem_c.dylib 0x35440d2a _pthread_cond_wait + 642
2 libsystem_c.dylib 0x3544af14 pthread_cond_wait + 36
3 Foundation 0x35908cca -[NSCondition wait] + 190
4 Capture This 0x000c89a8 -[PFCommandCache runLoop] (PFCommandCache.m:491)
5 Foundation 0x3598c678 __NSThread__main__ + 968
6 libsystem_c.dylib 0x3544830e _pthread_start + 306
7 libsystem_c.dylib 0x354481d4 thread_start + 4
Thread 7:
0 libsystem_kernel.dylib 0x33fb3eb4 mach_msg_trap + 20
1 libsystem_kernel.dylib 0x33fb4048 mach_msg + 36
2 CoreFoundation 0x35e34040 __CFRunLoopServiceMachPort + 124
3 CoreFoundation 0x35e32d9e __CFRunLoopRun + 878
4 CoreFoundation 0x35da5eb8 CFRunLoopRunSpecific + 352
5 CoreFoundation 0x35da5d44 CFRunLoopRunInMode + 100
6 Foundation 0x358df78a -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 250
7 Foundation 0x35983058 -[NSRunLoop(NSRunLoop) run] + 76
8 Capture This 0x000eb5f0 +[PF_AFURLConnectionOperation networkRequestThreadEntryPoint:] (PF_AFURLConnectionOperation.m:151)
9 Foundation 0x3598c678 __NSThread__main__ + 968
10 libsystem_c.dylib 0x3544830e _pthread_start + 306
11 libsystem_c.dylib 0x354481d4 thread_start + 4
Thread 8 name: com.apple.NSURLConnectionLoader
Thread 8:
0 libsystem_kernel.dylib 0x33fb3eb4 mach_msg_trap + 20
1 libsystem_kernel.dylib 0x33fb4048 mach_msg + 36
2 CoreFoundation 0x35e34040 __CFRunLoopServiceMachPort + 124
3 CoreFoundation 0x35e32d9e __CFRunLoopRun + 878
4 CoreFoundation 0x35da5eb8 CFRunLoopRunSpecific + 352
5 CoreFoundation 0x35da5d44 CFRunLoopRunInMode + 100
6 Foundation 0x35908bc8 +[NSURLConnection(Loader) _resourceLoadLoop:] + 304
7 Foundation 0x3598c678 __NSThread__main__ + 968
8 libsystem_c.dylib 0x3544830e _pthread_start + 306
9 libsystem_c.dylib 0x354481d4 thread_start + 4
Thread 9 name: com.apple.CFSocket.private
Thread 9:
0 libsystem_kernel.dylib 0x33fc4594 __select + 20
1 CoreFoundation 0x35e381f2 __CFSocketManager + 674
2 libsystem_c.dylib 0x3544830e _pthread_start + 306
3 libsystem_c.dylib 0x354481d4 thread_start + 4
Unknown thread crashed with unknown flavor: 5, state_count: 1
And the app did finish launching method as requested:
(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[Parse setApplicationId:#"key"
clientKey:#"key"];
[PFFacebookUtils initializeWithApplicationId:#"id"];
[application registerForRemoteNotificationTypes:UIRemoteNotificationTypeBadge|
UIRemoteNotificationTypeAlert|
UIRemoteNotificationTypeSound];
//--set background and camera images
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if (![defaults objectForKey:BACKGROUND_IMAGE]){
[[NSUserDefaults standardUserDefaults] setObject:#"background0.png" forKey:BACKGROUND_IMAGE];
}
if (![defaults objectForKey:CAMERA_BUTTON]){
[defaults setObject:#"cameraButton0.png" forKey:CAMERA_BUTTON];
}
if (![defaults objectForKey:PURCHASED_CAMERAS]){
NSMutableArray *cameras = [[NSMutableArray alloc] init];
[cameras addObject:#"cameraButton0.png"];
[defaults setObject:cameras forKey:PURCHASED_CAMERAS];
}
if (![defaults objectForKey:PURCHASED_BACKGROUNDS]){
NSMutableArray *back = [[NSMutableArray alloc] init];
[back addObject:#"background0.png"];
[defaults setObject:back forKey:PURCHASED_BACKGROUNDS];
}
if ([PFUser currentUser]){
[[PFUser currentUser] refreshInBackgroundWithBlock:^(PFObject *object, NSError *error) {
if (error){
[[[UIAlertView alloc] initWithTitle:#"Couldn't refresh user data" message:#"Please try again later" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles: nil] show];
}
[Utilities refreshCurrentUser];
}];
}
[[UIApplication sharedApplication] cancelAllLocalNotifications];
return YES;
}
From what I understand, iOS has a watchdog checking for applications running at all times. When the application doesn't respond for more than 20 seconds, the application is automatically killed. Not sure if this is what's happening here, but it might be the case.
I'd start looking at processes running at application startup. Some people might encounter that kind of problem when they have a lot of applications loaded and running in the background, slowing down processing, which could appear as the application not responding.

Resources