Application crash on addOperation ( OSAtomicCompareAndSwap32 ) - iphone

any one have any idea why application crash on this place
In code I am doing something like this
RequestOperation* requestOperation = [[[RequestOperation alloc]initWithItem:item delegate:self] autorelease];
[operationQueue addOperation:requestOperation];
Error Code
OS Version: iPhone OS 4.2.1
Report Version: 104
Exception Type: SIGBUS
Exception Codes: BUS_ADRALN at 0x7c
Crashed Thread: 0
Thread 0 Crashed:
0 libSystem.B.dylib 0x000053e4 OSAtomicCompareAndSwap32 + 0
1 Foundation 0x00023235 ____addOperations_block_invoke_1 + 37
2 Foundation 0x00022d91 __addOperations + 229
3 Foundation 0x00022cab -[NSOperationQueue addOperation:] + 11

BUS_ADRALN means that there is an address alignment problem.
I would check if the NSOperation object that is passed to [NSOperationQueue addOperation:] is valid.

Related

-[NSConcreteTask waitUntilExit] results in KERN_PROTECTION_FAILURE

I'm getting an error like the following (censored and trimmed to protect proprietary info):
Process: MyExecutable [7150]
Path: /Applications/Company Name/Parent App.app/Contents/PlugIns/MyExecutable
Identifier: MyExecutable
Version: 0
Code Type: X86-64 (Native)
Parent Process: ??? [1]
Responsible: MyExecutable [7150]
User ID: 1129915948
Date/Time: 2018-03-27 11:42:12.401 -0400
OS Version: Mac OS X 10.12.6 (16G1212)
Report Version: 12
Anonymous UUID: 013E2942-CED9-22FA-438A-E3D0BA89EB5C
Time Awake Since Boot: 6200 seconds
System Integrity Protection: enabled
Crashed Thread: 0 Dispatch queue: com.apple.main-thread
Exception Type: EXC_BAD_ACCESS (SIGBUS)
Exception Codes: KERN_PROTECTION_FAILURE at 0x00007fa9bc632b10
Exception Note: EXC_CORPSE_NOTIFY
Termination Signal: Bus error: 10
Termination Reason: Namespace SIGNAL, Code 0xa
Terminating Process: exc handler [0]
VM Regions Near 0x7fa9bc632b10:
MALLOC_TINY 00007fa9bc400000-00007fa9bc600000 [ 2048K] rw-/rwx SM=PRV
--> MALLOC_TINY 00007fa9bc600000-00007fa9bc700000 [ 1024K] rw-/rwx SM=COW
MALLOC_TINY 00007fa9bc700000-00007fa9bc800000 [ 1024K] rw-/rwx SM=PRV
Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0 ??? 0x00007fa9bc632b10 0 + 140366986816272
1 com.apple.Foundation 0x00007fffa3225051 -[NSConcreteTask waitUntilExit] + 213
2 MyExecutable 0x000000010dcfeb86 _TTSf4gs_gs_g___TF8MyExecutableP33_446BC8CF8CAA764CF050D96869CE3A5A18mySwiftFunctionFTSS7purposeSS18callbackFCSo7ProcessT__T_ + 1254
3 MyExecutable 0x000000010dcfdbb7 _TZFC8MyExecutable12MyClassP33_446BC8CF8CAA764CF050D96869CE3A5A31someSwiftFunctionfT_T_ + 215
4 MyExecutable 0x000000010dcfd985 _TZFC8MyExecutable12MyClass40someSwiftFunctionfT_T_ + 21
5 MyExecutable 0x000000010dcd8e0f main + 241
6 libdyld.dylib 0x00007fffb6ef3235 start + 1
The code in question attempts to run a terminal command by using Process (AKA NSTask in Objective-C; implemented by NSConcreteTask). It's prepared like this:
process.launchPath = "/bin/bash"
process.arguments = ["-c", bashCommand]
process.terminationHandler = callback
process.launch()
process.waitUntilExit()
It runs fine until the call to waitUntilExit. When that runs, the app crashes immediately with an output similar to that above.
For various reasons, I can't run a debugger to test this, but I can print log lines to the console. Why would it crash this hard? I even see a bus error in there for crying out loud...
Synchronous waitUntilExit() and asynchronous completion handler don't work very well together.
If you use the asynchronous completion handler waiting for exit is actually pointless.
Just delete the line
process.waitUntilExit()

How to use CFDictionarySetValue in swift?

Currently, I am converting the hardware decoding Obj-C code to Swift version. (Xcode 8, Swift 3).
I don't know how to set up a dictionary to set up an output option on the screen, also, I don't know how to use it.
The following code works fine in Obj-C project:
// set some values of the sample buffer's attachments
CFArrayRef attachments = CMSampleBufferGetSampleAttachmentsArray(sampleBuffer, YES);
CFMutableDictionaryRef dict = (CFMutableDictionaryRef)CFArrayGetValueAtIndex(attachments, 0);
CFDictionarySetValue(dict, kCMSampleAttachmentKey_DisplayImmediately, kCFBooleanTrue);
I tried the following Swift code, but there was a runtime error:
// i got run-time error
let attachments = CMSampleBufferGetSampleAttachmentsArray(sampleBuffer!, true)
let dict = unsafeBitCast(attachments, to: CFMutableDictionary.self)
CFDictionarySetValue(dict, unsafeBitCast(kCMSampleAttachmentKey_DisplayImmediately, to: UnsafeRawPointer.self), unsafeBitCast(kCFBooleanTrue, to: UnsafeRawPointer.self))
Is it wrong to convert the CFString to UnsafeRawPointer? or Is it wrong to use the CFDictionarySetValue method?
this is my error log.
2016-11-24 16:50:44.458 MyApp[35288:3519253] -[__NSSingleObjectArrayI __setObject:forKey:]: unrecognized selector sent to instance 0x6000002045a0
2016-11-24 16:50:44.466 MyApp[35288:3519253] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSSingleObjectArrayI __setObject:forKey:]: unrecognized selector sent to instance 0x6000002045a0'
*** First throw call stack:
(
0 CoreFoundation 0x000000010b02734b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x000000010a0e421e objc_exception_throw + 48
2 CoreFoundation 0x000000010b096f34 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
3 CoreFoundation 0x000000010afacc15 ___forwarding___ + 1013
4 CoreFoundation 0x000000010afac798 _CF_forwarding_prep_0 + 120
5 MyApp 0x000000010937ac7a _TFC14MyApp16ViewerController21receivedRawVideoFramefT5frameGSaVs5UInt8_4withVs5Int32_T_ + 4890
6 MyApp 0x000000010937d8e2 _TFC14MyApp16ViewerController12MainCallBackfTVs5Int3212callbackCodeS1_8argumentGSqSv_7argSizeS1__T_ + 4242
7 MyApp 0x000000010937daed _TToFC14MyApp16ViewerController12MainCallBackfTVs5Int3212callbackCodeS1_8argumentGSqSv_7argSizeS1__T_ + 61
8 MyApp 0x000000010937dd56 _TTDFC14MyApp16ViewerController12MainCallBackfTVs5Int3212callbackCodeS1_8argumentGSqSv_7argSizeS1__T_ + 70
9 MyApp 0x000000010937dcfe _TTWC14MyApp16ViewerControllerS_18IJCallbackProtocolS_FS1_12MainCallBackfTVs5Int3212callbackCodeS2_8argumentGSqSv_7argSizeS2__T_ + 62
10 MyApp 0x00000001093b22b2 _TFC14MyApp11AppDelegate19MainCallBack_StreamfTVs5Int32S1_GSqSv_S1__T_ + 258
11 MyApp 0x00000001093d26d3 _TFZFC14MyApp19IJStreamCoreWrapper6AttachFTSv2ipSS4portSi_T_U_FTVs5Int32S1_GSqSv_S1_GSqSv__T_ + 355
12 MyApp 0x00000001093d2719 _TToFZFC14MyApp19IJStreamCoreWrapper6AttachFTSv2ipSS4portSi_T_U_FTVs5Int32S1_GSqSv_S1_GSqSv__T_ + 9
13 MyApp 0x00000001093ee176 _ZL8CallbackPN14CStreamManager9Session_TEiPvi + 70
14 MyApp 0x00000001093f09d3 _Z25StreamManagerThread_VideoPv + 3155
15 libsystem_pthread.dylib 0x000000010e494aab _pthread_body + 180
16 libsystem_pthread.dylib 0x000000010e4949f7 _pthread_body + 0
17 libsystem_pthread.dylib 0x000000010e494221 thread_start + 13
)
libc++abi.dylib: terminating with uncaught exception of type NSException
I was only able to get this working with the following:
let attachments = CMSampleBufferGetSampleAttachmentsArray(buf!, createIfNecessary: true)
let dict = unsafeBitCast(CFArrayGetValueAtIndex(attachments, 0), to: CFMutableDictionary.self)
CFDictionarySetValue(dict,
unsafeBitCast(kCMSampleAttachmentKey_DisplayImmediately, to: UnsafeRawPointer.self),
unsafeBitCast(kCFBooleanTrue, to: UnsafeRawPointer.self))
I tried #Alexander's suggestion, and although it compiles and executes, the underlying CFDictionary is not mutated and the desired result is not achieved.
// let attachments = CMSampleBufferGetSampleAttachmentsArray(buf!, createIfNecessary: true) as! Array<Dictionary<String, Any>>
// var dict = attachments[0]
// dict[kCMSampleAttachmentKey_DisplayImmediately as String] = true
In the first code snippet, you have a call to CFArrayGetValueAtIndex, which returns a dictionary that you pass to CFDictionarySetValue.
In the second code snippet, you don't call CFArrayGetValueAtIndex. You just pass the array to CFDictionarySetValue. Since an array is not a dictionary, you get a fatal error.
When you convert code to Swift, it's much best to understand the semantic of the program, and rewrite Swift code that matches. Don't try to just convert the syntax bit by bit.
CMSampleBufferGetSampleAttachmentsArray returns you a reference to a CFArray of CFDictionary instances. Casting this CFArrayRef to CFMutableDictionaryRef has the effect of just making a reference to the first instance.
It's best to just use Swift's native types. I can't provide an exact implementation because I'm not to sure of the types in play, but here's a start
//TODO: give me a better name
let array = CMSampleBufferGetSampleAttachmentsArray(sampleBuffer!, true) as [[String: Bool]] //TODO:
//TODO: give me a better name
var firstDict = array[0]
firstDict[kCMSampleAttachmentKey_DisplayImmediately as String] = true

MAMP 3.4 immediately crashes upon launch

Fresh install. OSX 10.10.5. I found a post several years old that mentioned a solution of making sure 127.0.0.1 (null) was not in /etc/hosts. No effect.
Here's a dump of the error:
Process: MAMP [2867]
Path: /Applications/MAMP/MAMP.app/Contents/MacOS/MAMP
Identifier: de.appsolute.MAMP
Version: 3.4 (3.4)
Code Type: X86-64 (Native)
Parent Process: ??? [1]
Responsible: MAMP [2867]
User ID: 962435817
Date/Time: 2015-11-09 11:29:13.754 -0500
OS Version: Mac OS X 10.10.5 (14F1021)
Report Version: 11
Anonymous UUID: C3B21FD3-E569-950C-7452-43A3D5CEDC99
Time Awake Since Boot: 1300 seconds
Crashed Thread: 0 Dispatch queue: com.apple.main-thread
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x0000000000000000
VM Regions Near 0:
-->
__TEXT 0000000100000000-0000000100015000 [ 84K] r-x/rwx SM=COW /Applications/MAMP/MAMP.app/Contents/MacOS/MAMP
Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0 de.appsolute.MAMP 0x0000000100006a6b 0x100000000 + 27243
1 de.appsolute.MAMP 0x0000000100006d7a 0x100000000 + 28026
2 de.appsolute.MAMP 0x0000000100008b84 0x100000000 + 35716
3 de.appsolute.MAMP 0x000000010000313d 0x100000000 + 12605
4 com.apple.CoreFoundation 0x00007fff887be45c

Exception Type: EXC_BAD_ACCESS (SIGBUS) Exception Codes: รง at 0x3ec3b04c Crashed Thread: 0

HI got the this crash report on device log and I am using the ad hoc build.
I didn't find where it was crashed "0 ??? 0x3ec3b04c 0 + 1053012044"
Exception Type: EXC_BAD_ACCESS (SIGBUS)
Exception Codes: KERN_PROTECTION_FAILURE at 0x3ec3b04c
Crashed Thread: 0
Thread 0 name: Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
<b>0 ??? 0x3ec3b04c 0 + 1053012044 </b>
<b>1 libgcc_s.1.dylib 0x303d29c0 _Unwind_SjLj_Unregister + 24 </b>
<b>2 ??? 0x00000018 0 + 24</b>
</pre>
Probably, your application tried to access released variable. While debugging you can use NSZombie to detect such variable before receiving EXC_BAD_ACCESS.

Core data fails in 'validateForInsert'

For a project I'm working on I'm using core data to store the application's data. The application loads XML from the internet and tries to store the objects generated from the parsed results in the data model. This used to work fine, until a few days ago. I changed the data model (added one property on an object), so I made a new version and ran mogenerator to generate new stub classes for the objects in the model. Most of it still works fine, but there are some odd errors in code that used to work perfectly.
During the parsing of the XML an object is created and values on it are filled in. One of the values is an URL for an image. In the data model this value may not be NIL, but in the XML it occasionaly is. I use validateForInsert on the item to check if I can commit it. This is the part that used to work fine, but now fails, complaining about the NIL value.
A bit of code from the parser:
...
currentItem = [[[MyItem alloc] initWithEntity:[self.dataModel entityByName:#"MyItem"] insertIntoManagedObjectContext:self.dataModel.managedObjectContext] autorelease];
currentItem.label = [attributeDict objectForKey:LABEL];
currentItem.paramString = [attributeDict objectForKey:QUERY_STRING];
[currentItem setSortOrderValue:[[currentRootItem items] count]];
[currentRootItem addItemsObject:currentItem];
} else if ([elementName isEqualToString:IMAGE]) {
currentItem.imageLocation = [attributeDict objectForKey:IMAGE_URL];
...
Then, when the document is parsed, I do the check:
...
{
NSArray *Items = [[myRootItem items] allObjects];
for (MyItem *item in Items) {
NSLog(#"%#", item);
NSLog(#"before");
NSLog(#"%d", [item validateForInsert:&validationError]);
NSLog(#"after");
if (![item validateForInsert:&validationError]) {
[[self.dataModel managedObjectContext] deleteObject:item];
}
}
}
...
This used to work just fine, but now it crashes in validateForInsert:
2011-03-30 13:38:32.951 xx[915:207] before
2011-03-30 13:38:33.130 xx[915:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFDictionary setObject:forKey:]: attempt to insert nil value (key: Property/imageLocation/Entity/Item)'
Stacktrace:
0 CoreFoundation 0x022fc5a9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x02450313 objc_exception_throw + 44
2 CoreFoundation 0x022b4ef8 +[NSException raise:format:arguments:] + 136
3 CoreFoundation 0x022b4e6a +[NSException raise:format:] + 58
4 CoreFoundation 0x022fae15 -[__NSCFDictionary setObject:forKey:] + 293
5 CoreData 0x013fa87c -[NSValidationErrorLocalizationPolicy _cachedObjectForKey:value:] + 172
6 CoreData 0x013fa629 -[NSValidationErrorLocalizationPolicy _localizedPropertyNameForProperty:entity:] + 201
7 CoreData 0x013fa4e7 -[NSValidationErrorLocalizationPolicy localizedPropertyNameForProperty:] + 71
8 CoreData 0x013a844e -[NSManagedObject(_NSInternalMethods) _substituteEntityAndProperty:inString:] + 142
9 CoreData 0x013a572e -[NSManagedObject(_NSInternalMethods) _generateErrorWithCode:andMessage:forKey:andValue:additionalDetail:] + 254
10 CoreData 0x013598f1 -[NSPropertyDescription(_NSInternalMethods) _nonPredicateValidateValue:forKey:inObject:error:] + 161
11 CoreData 0x01359485 -[NSAttributeDescription(_NSInternalMethods) _nonPredicateValidateValue:forKey:inObject:error:] + 85
12 CoreData 0x01358b22 -[NSManagedObject(_NSInternalMethods) _validateValue:forProperty:andKey:withIndex:error:] + 386
13 CoreData 0x01358847 -[NSManagedObject(_NSInternalMethods) _validatePropertiesWithError:] + 263
14 CoreData 0x013586e1 -[NSManagedObject(_NSInternalMethods) _validateForSave:] + 81
15 xx 0x001af8bf -[MyParser parserDidEndDocument:] + 1039
16 Foundation 0x00742717 _endDocument + 95
I can't figure out what went wrong. As far as I know making a new version of the data model went right (using XCode), setting it to the current version etc, all went right. I didn't have these problems the last time I did all this...
The only thing different is that now I upgraded to XCode 3.2.6, from 3.2.5 or 3.2.4, I don't remember.
My target is iPhone, and I'm using the 4.3 iOS SDK that came with this version of XCode.
I had this problem and I fixed it by checking my data length. If your model has a string field, you must validate that the String you're passing doesn't exceed the field length.
Well, to answer my own question...
The problem is not there in 3.2.5, nor is it there in 4.0.1. Looks like apple has some bugfixing to do on 3.2.6...