IOS Simulator keeps crashing? - xcode

Whenever I try to Run the IOS Simulator, it keeps crashing. I work on Xcode 5.0.2. On the main.m file it says
Thread 1:SIGABRT. Heres is the line where the SIGABRT appeared.
return UIApplicationMain(argc, argv, nil, NSStringFromClass([xyzAppDelegate class]));
heres what was going on in the main.m
#import <UIKit/UIKit.h>
#import "xyzAppDelegate.h"
int main(int argc, char * argv[])
{
#autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([xyzAppDelegate class]));
}
}
xyzAppDelegate.h
#import <UIKit/UIKit.h>
#interface xyzAppDelegate : UIResponder <UIApplicationDelegate>
#property (strong, nonatomic) UIWindow *window;
#end
xyzAppDelegate.m
#import "xyzAppDelegate.h"
#implementation xyzAppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
- (void)applicationWillResignActive:(UIApplication *)application
{
}
- (void)applicationDidEnterBackground:(UIApplication *)application
{
}
- (void)applicationWillEnterForeground:(UIApplication *)application
{
}
- (void)applicationDidBecomeActive:(UIApplication *)application
{
}
- (void)applicationWillTerminate:(UIApplication *)application
{
}
#end
Here is what it shows on the debug area
2014-02-13 00:06:47.933 ToDoList[707:70b] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle </Users/garibaldi/Library/Application Support/iPhone Simulator/7.0.3/Applications/8B1ABBAB-D173-4A8E-80AC-8DEA44C5EDE8/ToDoList.app> (loaded)' with name 'Main''
*** First throw call stack:
(
0 CoreFoundation 0x0174c5e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x014bb8b6 objc_exception_throw + 44
2 CoreFoundation 0x0174c3bb +[NSException raise:format:] + 139
3 UIKit 0x004ca39c -[UINib instantiateWithOwner:options:] + 951
4 UIKit 0x004cc2fb -[NSBundle(UINSBundleAdditions) loadNibNamed:owner:options:] + 165
5 UIKit 0x002293bb -[UIApplication _loadMainNibFileNamed:bundle:] + 58
6 UIKit 0x002296e9 -[UIApplication _loadMainInterfaceFile] + 245
7 UIKit 0x0022828f -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 543
8 UIKit 0x0023c87c -[UIApplication handleEvent:withNewEvent:] + 3447
9 UIKit 0x0023cde9 -[UIApplication sendEvent:] + 85
10 UIKit 0x0022a025 _UIApplicationHandleEvent + 736
11 GraphicsServices 0x036df2f6 _PurpleEventCallback + 776
12 GraphicsServices 0x036dee01 PurpleEventCallback + 46
13 CoreFoundation 0x016c7d65 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 53
14 CoreFoundation 0x016c7a9b __CFRunLoopDoSource1 + 523
15 CoreFoundation 0x016f277c __CFRunLoopRun + 2156
16 CoreFoundation 0x016f1ac3 CFRunLoopRunSpecific + 467
17 CoreFoundation 0x016f18db CFRunLoopRunInMode + 123
18 UIKit 0x00227add -[UIApplication _run] + 840
19 UIKit 0x00229d3b UIApplicationMain + 1225
20 ToDoList 0x0000219d main + 141
21 libdyld.dylib 0x01d7670d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
I tried following Apple's First Tutorial. Sorry if I'm not clear enough, I'm still kinda new here.

Try resetting the simulator.
I'm sorry I cannot yet upload images, but:
(If simulator is not running)
In XCode, go to XCode menu (one left of 'File') on top, 'Open Developer Tool' > 'iOS Simulator'.
In the simulator, click on the 'iOS Simulator menu' > 'Rest Content And Settings...'

Try resetting the simulator (as in #bauerMusic's answer) and then restart your Mac. That consistently fixes a similar issue I have.

Related

Error when running my ios sumilator : Exception '*** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]

I have just done some configs in Xcode and appdelegate.m for RNFirebase, RNFBSDK, and google Sign-In. After following al the steps I have an error when running my ios simulator with react-native run ios.
I have tried to tweak the AppDelegate.m, I deleted my build folders and recompiled
My AppDelegate.m file looks like this
#import "AppDelegate.h"
#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>
#import <ReactNativeNavigation/ReactNativeNavigation.h>
#import <RNGoogleSignin/RNGoogleSignin.h>
#import <Firebase.h>
#import <FBSDKCoreKit/FBSDKCoreKit.h>
#implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Firebase configurations
[FIRApp configure];
// Facebook SDK
[[FBSDKApplicationDelegate sharedInstance] application:application
didFinishLaunchingWithOptions:launchOptions];
NSURL *jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:#"index" fallbackResource:nil];
[ReactNativeNavigation bootstrap:jsCodeLocation launchOptions:launchOptions];
return YES;
}
// RNGoogleSignin.h -> https://github.com/react-native-community/react-native-google-signin/blob/master/docs/ios-guide.md#modify-your-app-to-respond-to-the-url-scheme-optional
- (BOOL)application:(UIApplication *)application openURL:(nonnull NSURL *)url options:(nonnull NSDictionary<NSString *,id> *)options {
return [RNGoogleSignin application:application
openURL:url
sourceApplication:options[UIApplicationOpenURLOptionsSourceApplicationKey]
annotation:options[UIApplicationOpenURLOptionsAnnotationKey]];
}
// FACEBOOK SDK
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
BOOL handled = [[FBSDKApplicationDelegate sharedInstance] application:application
openURL:url
sourceApplication:options[UIApplicationOpenURLOptionsSourceApplicationKey]
annotation:options[UIApplicationOpenURLOptionsAnnotationKey]
];
// Add any custom logic here.
return handled;
}
- (void)applicationDidBecomeActive:(UIApplication *)application {
[FBSDKAppEvents activateApp];
}
- (BOOL)application:(UIApplication *)app
openURL:(NSURL *)url
options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options
{
if ([[FBSDKApplicationDelegate sharedInstance] application:app openURL:url options:options]) {
return YES;
}
if ([RCTLinkingManager application:app openURL:url options:options]) {
return YES;
}
return NO;
}
#end
this is the entire error popping on the simulator screen instead of the app launching:
Exception '*** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[0]' was thrown while invoking getImageForFont on target RNVectorIconsManager with params (
Entypo,
"\Uf241",
30,
4278190080,
35
)
callstack: (
0 CoreFoundation 0x0000000111f926fb __exceptionPreprocess + 331
1 libobjc.A.dylib 0x000000011097eac5 objc_exception_throw + 48
2 CoreFoundation 0x0000000111ee0ddc _CFThrowFormattedException + 194
3 CoreFoundation 0x0000000111ffec31 -[__NSPlaceholderDictionary initWithObjects:forKeys:count:] + 321
4 CoreFoundation 0x0000000111f8e3db +[NSDictionary dictionaryWithObjects:forKeys:count:] + 59
5 madilist_app 0x000000010d8339bf -[RNVectorIconsManager createAndSaveGlyphImage:withFont:withFilePath:withColor:] + 415
6 madilist_app 0x000000010d833d68 -[RNVectorIconsManager getImageForFont:withGlyph:withFontSize:withColor:callback:] + 360
7 CoreFoundation 0x0000000111f994cc __invoking___ + 140
8 CoreFoundation 0x0000000111f96a45 -[NSInvocation invoke] + 325
9 CoreFoundation 0x0000000111f96e96 -[NSInvocation invokeWithTarget:] + 54
10 madilist_app 0x000000010d528fba -[RCTModuleMethod invokeWithBridge:module:arguments:] + 2810
11 madilist_app 0x000000010d5db096 _ZN8facebook5reactL11invokeInnerEP9RCTBridgeP13RCTModuleDatajRKN5folly7dynamicE + 790
12 madilist_app 0x000000010d5daba3 _ZZN8facebook5react15RCTNativeModule6invokeEjON5folly7dynamicEiENK3$_0clEv + 131
13 madilist_app 0x000000010d5dab19 ___ZN8facebook5react15RCTNativeModule6invokeEjON5folly7dynamicEi_block_invoke + 25
14 libdispatch.dylib 0x000000011497accf _dispatch_call_block_and_release + 12
15 libdispatch.dylib 0x000000011497bd02 _dispatch_client_callout + 8
16 libdispatch.dylib 0x0000000114982720 _dispatch_lane_serial_drain + 705
17 libdispatch.dylib 0x0000000114983261 _dispatch_lane_invoke + 398
18 libdispatch.dylib 0x000000011498bfcb _dispatch_workloop_worker_thread + 645
19 libsystem_pthread.dylib 0x0000000114d5d611 _pthread_wqthread + 421
20 libsystem_pthread.dylib 0x0000000114d5d3fd start_wqthread + 13
)
RCTFatal
facebook::react::invokeInner(RCTBridge*, RCTModuleData*, unsigned int, folly::dynamic const&)
facebook::react::RCTNativeModule::invoke(unsigned int, folly::dynamic&&, int)::$_0::operator()() const
invocation function for block in facebook::react::RCTNativeModule::invoke(unsigned int, folly::dynamic&&, int)
_dispatch_call_block_and_release
_dispatch_client_callout
_dispatch_lane_serial_drain
_dispatch_lane_invoke
_dispatch_workloop_worker_thread
_pthread_wqthread
start_wqthread

Swift + Parse: 'Can't use nil for keys or values on PFObject. Use NSNull for values.'

So I have a Swift application that I am working on (in Xcode 7.3).
It uses Parse and in it I have a function that is generating the error message stated in the title.
The code appears as follows;
#IBAction func callUber(sender: AnyObject) {
let riderRequest = PFObject(className:"riderRequest")
riderRequest["username"] = PFUser.currentUser()?.username
riderRequest["location "] = PFGeoPoint(latitude:latitude, longitude:longitude)
riderRequest.saveInBackgroundWithBlock {
(success: Bool, error: NSError?) -> Void in
if (success) {
self.callUberButton.setTitle("Cancel Uber", forState: UIControlState.Normal)
} else {
let alert = UIAlertController(title: "Could not call Uber", message: "Please try again", preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: nil))
self.presentViewController(alert, animated: true, completion: nil)
}
}
}
Now somewhere in this code nil is being applied to a value, and this causes the error message (or so I think). I have been looking around on SO for solutions to this problem, however I could not find any similar threads for this error message and Swift, only Objective-C.
I'm guessing that I have to introduce some sort of error handling or check where I make sure that the value of the object is not nil, however I cant seem to figure out where, or how to apply this.
The error is only triggered when I press the "callUber" button, and the full output from the debug console follows below.
2016-04-15 12:21:01.900 ParseStarterProject-Swift[8781:2591354] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Can't use nil for keys or values on PFObject. Use NSNull for values.'
*** First throw call stack:
(
0 CoreFoundation 0x000000010ca98d85 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000010eca0deb objc_exception_throw + 48
2 CoreFoundation 0x000000010ca98cbd +[NSException raise:format:] + 205
3 ParseStarterProject-Swift 0x000000010c1042a8 -[PFObject(Private) _setObject:forKey:onlyIfDifferent:] + 122
4 ParseStarterProject-Swift 0x000000010c107d01 -[PFObject setObject:forKey:] + 53
5 ParseStarterProject-Swift 0x000000010c107d46 -[PFObject setObject:forKeyedSubscript:] + 50
6 ParseStarterProject-Swift 0x000000010c0c847f _TFC25ParseStarterProject_Swift19RiderViewController8callUberfPs9AnyObject_T_ + 671
7 ParseStarterProject-Swift 0x000000010c0c89d6 _TToFC25ParseStarterProject_Swift19RiderViewController8callUberfPs9AnyObject_T_ + 54
8 UIKit 0x000000010d726a8d -[UIApplication sendAction:to:from:forEvent:] + 92
9 UIKit 0x000000010d899e67 -[UIControl sendAction:to:forEvent:] + 67
10 UIKit 0x000000010d89a143 -[UIControl _sendActionsForEvents:withEvent:] + 327
11 UIKit 0x000000010d899263 -[UIControl touchesEnded:withEvent:] + 601
12 UIKit 0x000000010d79999f -[UIWindow _sendTouchesForEvent:] + 835
13 UIKit 0x000000010d79a6d4 -[UIWindow sendEvent:] + 865
14 UIKit 0x000000010d745dc6 -[UIApplication sendEvent:] + 263
15 UIKit 0x000000011dfe0b15 -[UIApplicationAccessibility sendEvent:] + 77
16 UIKit 0x000000010d71f553 _UIApplicationHandleEventQueue + 6660
17 CoreFoundation 0x000000010c9be301 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
18 CoreFoundation 0x000000010c9b422c __CFRunLoopDoSources0 + 556
19 CoreFoundation 0x000000010c9b36e3 __CFRunLoopRun + 867
20 CoreFoundation 0x000000010c9b30f8 CFRunLoopRunSpecific + 488
21 GraphicsServices 0x0000000111eb0ad2 GSEventRunModal + 161
22 UIKit 0x000000010d724f09 UIApplicationMain + 171
23 ParseStarterProject-Swift 0x000000010c0cc712 main + 114
24 libdyld.dylib 0x000000010f7a792d start + 1
25 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
A couple of things that may be the issue:
Double check your class name is "riderRequest", I think "RiderRequest" could possibly be the actual name.
Second is to check all your key names are correct by going to the parse dashboard and having a look at your class
Last thing is to confirm that all your values for things like username and latitude and longitude are not nil before setting them.
Maybe try:
if let username = PFUser.currentUser()?.username && latitude != nil && longitude != nil {
riderRequest.setObject(username, forKey: "username")
riderRequest.setObject(PFGeoPoint(latitude: latitude, longitude: longitude), forKey: "location")
//then run the rest of the code as you have been
}

nearby places swift 2 error

I work on a ios application that requires to use nearby places api from google. It worked very well with swift but now , when i updated my xcode to xcode 7 and it changed from swift to swift 2 it doesn't work anymore. I am stuck with this , any help will be apreciated .
Here is the request for the api :
func fetchPlacesNearCoordinate(coordinate: CLLocationCoordinate2D, radius: Double, name : String){
var urlString = "https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=\(44.942149),\(26.02453)&radius=\(radius)&types=food"
urlString += "&key=\(apiServerKey)"
urlString = urlString.stringByAddingPercentEscapesUsingEncoding(NSUTF8StringEncoding)!
if placesTask.taskIdentifier > 0 && placesTask.state == .Running {
placesTask.cancel()
}
UIApplication.sharedApplication().networkActivityIndicatorVisible = true
do{
//******************Here's the line that displays error
placesTask = session.dataTaskWithURL(NSURL(string: urlString)!) {
(data, response, error) -> Void in
UIApplication.sharedApplication().networkActivityIndicatorVisible = false
//var placesArray = [GooglePlace]()
do {
if let json = try NSJSONSerialization.JSONObjectWithData(data!, options:[]) as? NSDictionary {
if let results = json["results"] as? NSArray {
for rawPlace:AnyObject in results {
print(rawPlace)
var placename = ""
if let name = rawPlace["name"] as? NSString {
placename = name as String
}
}
}
}
} catch {
//handle error
}
/*dispatch_async(dispatch_get_main_queue()) {
completion(placesArray)
}*/
}
}catch{
}
placesTask.resume()
}
And the errors i get :
2015-10-02 16:57:54.586 QR Code[4331:67414] -[NSURLSessionDataTask taskIdentifier]: unrecognized selector sent to instance 0x7fe791c3b840
2015-10-02 16:57:54.591 QR Code[4331:67414] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSURLSessionDataTask taskIdentifier]: unrecognized selector sent to instance 0x7fe791c3b840'
*** First throw call stack:(
0 CoreFoundation 0x0000000111a8ef65 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x0000000111506deb objc_exception_throw + 48
2 CoreFoundation 0x0000000111a9758d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x00000001119e4f7a ___forwarding___ + 970
4 CoreFoundation 0x00000001119e4b28 _CF_forwarding_prep_0 + 120
5 QR Code 0x000000010f57b3ff _TFC7QR_Code17MapViewController25fetchPlacesNearCoordinatefS0_FTVSC22CLLocationCoordinate2D6radiusSd4nameSS_T_ + 1215
6 QR Code 0x000000010f57bfd3 _TFC7QR_Code17MapViewController11viewDidLoadfS0_FT_T_ + 1555
7 QR Code 0x000000010f57c552 _TToFC7QR_Code17MapViewController11viewDidLoadfS0_FT_T_ + 34
8 UIKit 0x00000001122ae931 -[UIViewController loadViewIfRequired] + 1344
9 UIKit 0x00000001122b4923 -[UIViewController __viewWillAppear:] + 120
10 UIKit 0x00000001122e418a -[UINavigationController _startCustomTransition:] + 1177
11 UIKit 0x00000001122f37c7 -[UINavigationController _startDeferredTransitionIfNeeded:] + 712
12 UIKit 0x00000001122f467d -[UINavigationController __viewWillLayoutSubviews] + 57
13 UIKit 0x000000011248c63d -[UILayoutContainerView layoutSubviews] + 248
14 UIKit 0x00000001121d411c -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 710
15 QuartzCore 0x000000010fe7536a -[CALayer layoutSublayers] + 146
16 QuartzCore 0x000000010fe69bd0 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 366
17 QuartzCore 0x000000010fe69a4e _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
18 QuartzCore 0x000000010fe5e1d5 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 277
19 QuartzCore 0x000000010fe8b9f0 _ZN2CA11Transaction6commitEv + 508
20 UIKit 0x000000011211e1b6 _UIApplicationHandleEventQueue + 7183
21 CoreFoundation 0x00000001119bb0a1 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
22 CoreFoundation 0x00000001119b0fcc __CFRunLoopDoSources0 + 556
23 CoreFoundation 0x00000001119b0483 __CFRunLoopRun + 867
24 CoreFoundation 0x00000001119afe98 CFRunLoopRunSpecific + 488
25 GraphicsServices 0x0000000115770ad2 GSEventRunModal + 161
26 UIKit 0x0000000112123676 UIApplicationMain + 171
27 QR Code 0x000000010f5782bd main + 109
28 libdyld.dylib 0x0000000113dd192d start + 1)
libc++abi.dylib: terminating with uncaught exception of type NSException
Please do not call the Places API Web Services directly from a mobile device - it opens up the potential for external parties to steal your API key from your application. Please follow the Proxy Server pattern laid out in this tutorial by Ray Wenderlich's team.

parent/child MOC with async disc saving got freeze main queue on osx

I have currently try to implement scheme:
MOC1 (PrivateQueue) -parent-> MOC2 (MainQueue) -parent-> MOC3 (PrivateQueue), PSC to save
here is init code (MOC2 & MOC#:
_writeManagedObjectContext = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSPrivateQueueConcurrencyType];
_writeManagedObjectContext.persistentStoreCoordinator = coordinator;
_writeManagedObjectContext.undoManager = nil;
_mainManagedObjectContext = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSMainQueueConcurrencyType];
_mainManagedObjectContext.undoManager = nil;
_mainManagedObjectContext.parentContext = _writeManagedObjectContext;
Here is init MOC1:
_mocSSchild = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSPrivateQueueConcurrencyType];
_mocSSchild.undoManager = nil;
_mocSSchild.parentContext = delegateMain.mainManagedObjectContext;
Here is a save:
NSError *error = nil;
[self.mocSSchild obtainPermanentIDsForObjects:self.mocSSchild.insertedObjects.allObjects error:&error];
if (![self.mocSSchild save: &error]) {
NSLog(#"Failed to save to FIRST data store: %#", [error localizedDescription]);
NSArray* detailedErrors = [[error userInfo] objectForKey:NSDetailedErrorsKey];
if(detailedErrors != nil && [detailedErrors count] > 0)
{
for(NSError* detailedError in detailedErrors)
{
NSLog(#" DetailedError: %#", [detailedError userInfo]);
}
}
else
{
NSLog(#" %#", [error userInfo]);
}
}
AppDelegate *delegateMain = (AppDelegate *)[[NSApplication sharedApplication] delegate];
if ([delegateMain.mainManagedObjectContext hasChanges] && ![delegateMain.mainManagedObjectContext save: &error]) { NSLog(#"Failed to save to FIRST data store: %#", [error localizedDescription]);
NSArray* detailedErrors = [[error userInfo] objectForKey:NSDetailedErrorsKey];
if(detailedErrors != nil && [detailedErrors count] > 0)
{
for(NSError* detailedError in detailedErrors)
{
NSLog(#" DetailedError: %#", [detailedError userInfo]);
}
}
else
{
NSLog(#" %#", [error userInfo]);
}
}
if ([delegateMain.writeManagedObjectContext hasChanges] && ![delegateMain.writeManagedObjectContext save: &error]) { NSLog(#"Failed to save to FIRST data store: %#", [error localizedDescription]);
NSArray* detailedErrors = [[error userInfo] objectForKey:NSDetailedErrorsKey];
if(detailedErrors != nil && [detailedErrors count] > 0)
{
for(NSError* detailedError in detailedErrors)
{
NSLog(#" DetailedError: %#", [detailedError userInfo]);
}
}
else
{
NSLog(#" %#", [error userInfo]);
}
}
All fetch requests is placed in right block (and of course i never touch mainManagedObjectContext to execute fetch requests):
__block NSError *error = nil;
__block NSArray *findedResult = nil;
[self.mocSSchild performBlockAndWait:^{
findedResult = [self.mocSSchild executeFetchRequest:fetchRequest error:&error];
}];
After one save i have freezing in main queue (looks like core data try to execute fetch request on mainManagedObjectContext where i don't do requests):
Call graph:
2633 Thread_803320 DispatchQueue_173: NSManagedObjectContext Queue (serial)
+ 2633 start (in libdyld.dylib) + 1 [0x7fff8bb907e1]
+ 2633 main (in callsfreecall) + 34 [0x10992c202]
+ 2633 NSApplicationMain (in AppKit) + 869 [0x7fff8a49cbd6]
+ 2633 -[NSApplication run] (in AppKit) + 517 [0x7fff8a4f81a3]
+ 2633 -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] (in AppKit) + 128 [0x7fff8a500df2]
+ 2633 _DPSNextEvent (in AppKit) + 685 [0x7fff8a501533]
+ 2633 BlockUntilNextEventMatchingListInMode (in HIToolbox) + 62 [0x7fff8f356ae3]
+ 2633 ReceiveNextEventCommon (in HIToolbox) + 356 [0x7fff8f356c52]
+ 2633 RunCurrentEventLoopInMode (in HIToolbox) + 209 [0x7fff8f356eb4]
+ 2633 CFRunLoopRunSpecific (in CoreFoundation) + 290 [0x7fff9526c0e2]
+ 2633 __CFRunLoopRun (in CoreFoundation) + 1644 [0x7fff9526cb4c]
+ 2633 _dispatch_main_queue_callback_4CF (in libdispatch.dylib) + 275 [0x7fff8c4c20c8]
+ 2633 _dispatch_client_callout (in libdispatch.dylib) + 8 [0x7fff8c4bd0b6]
+ 2633 _dispatch_barrier_sync_f_slow_invoke (in libdispatch.dylib) + 77 [0x7fff8c4c2a2d]
+ 2633 __82-[NSManagedObjectContext(_NestedContextSupport) executeRequest:withContext:error:]_block_invoke_0 (in CoreData) + 533 [0x7fff93d8b6c5]
+ 2633 -[NSManagedObjectContext countForFetchRequest:error:] (in CoreData) + 1563 [0x7fff93d65ddb]
+ 2633 -[NSManagedObjectContext(_NSInternalAdditions) _countWithNoChangesForRequest:error:] (in CoreData) + 298 [0x7fff93d65f4a]
+ 2633 -[NSManagedObjectContext(_NestedContextSupport) executeRequest:withContext:error:] (in CoreData) + 354 [0x7fff93d576c2]
+ 2633 _perform (in CoreData) + 172 [0x7fff93d5787c]
+ 2633 _dispatch_barrier_sync_f_invoke (in libdispatch.dylib) + 39 [0x7fff8c4be723]
+ 2633 _dispatch_client_callout (in libdispatch.dylib) + 8 [0x7fff8c4bd0b6]
+ 2633 __82-[NSManagedObjectContext(_NestedContextSupport) executeRequest:withContext:error:]_block_invoke_0 (in CoreData) + 533 [0x7fff93d8b6c5]
+ 2633 -[NSManagedObjectContext countForFetchRequest:error:] (in CoreData) + 1563 [0x7fff93d65ddb]
+ 2633 -[NSManagedObjectContext(_NSInternalAdditions) _countWithNoChangesForRequest:error:] (in CoreData) + 298 [0x7fff93d65f4a]
+ 2633 -[NSPersistentStoreCoordinator executeRequest:withContext:error:] (in CoreData) + 1138 [0x7fff93d10ba2]
+ 2633 -[_PFLock lock] (in CoreData) + 24 [0x7fff93cfe548]
+ 2633 pthread_mutex_lock (in libsystem_c.dylib) + 536 [0x7fff92797dfd]
+ 2633 __psynch_mutexwait (in libsystem_kernel.dylib) + 10 [0x7fff938ca122]
First, you need to do something with errors when you receive them. Right now you are not doing anything, not logging them, not reacting to them, nothing. This is bad. When an error occurs you have no indication of it at all. You just go onto the next step.
Second, you are saving all of your MOCs on the same queue. Any activity against a private MOC must be performed inside of a block via the -performBlock: or -performBlockAndWait: methods.
Third, there is no indication what queue you are running on.
Your import MOC should be running inside of an operation or a block running async. The import MOC should be using thread confinement instead of being a private MOC. Once the import MOC has completed its work it should save itself and then indicate to the main queue that the main MOC should be saved.
The main MOC should only be saved on the main queue. When the main MOC has completed its save then it should fire off a save to the top level MOC via its -performBlock:.
Correct your issues with the error results and take a look at what queues you are doing the work on. If everything is on the main queue then parent/child MOCs is not going to solve your problem. You need to rethink what work is being performed where.
Update 1
First, you can detect the errors by listening to the results from the calls. If the call returns a BOOL then that is a pass/fail. If the call returns something else then if that something else is nil then that is a failure and the error will be present.
As for your code, no it is not correct. You have threading issues as I mentioned. You are touching a private MOC directly, that is incorrect. There are probably other errors but I cannot see them based on this code.
Your "writing" MOC should only be touched via a -performBlock: or -performBlockAndWait:. In this case you should be using a -performBlock:. You are touching it directly. That is bad.
Your main MOC should only be touched on the main queue or via a -performBlock:/-performBlockAndWait:. You appear to be touching it directly in this code.
You are accessing your appDelegate as a singleton. This is a bad code smell. Look up and start using dependency injection.
Your child moc is set up as a private when it should be a thread confined context and then it should only be accessed on the thread that created it which ideally should be in an NSOperation.
In short, there is a lot of core concepts that you are missing here. You need to understand how parent/child contexts work and you need to have a better understanding of queues and threads before you attempt to develop code like this.

Mind boggling QTMovie export crash

Hey guys... I'm at my wits end here. I've been focusing on this issue for the last 3 days it seems, and I'm still no closer to solving it. I've got a queue of videos that I'm converting one after the other in a background thread. Most of the time it works as expected, but every so often, I get a weird crash, always at the same point. I can't for the life of me figure out why it's happening. I've got garbage collection enabled. Here is my conversion code.
Here is the stack trace.
Edit: After a bit more debugging, I am back to the conclusion that maybe it is garbage collector related. If I place the following line just before the line that converts the video, I get a drastic increase in the amount of these errors that I see...
[[NSGarbageCollector defaultCollector] collectExhaustively];
NSInvalidArgumentException
-[NSPathStore2 objectForKey:]: unrecognized selector sent to instance 0x1073570
(
0 CoreFoundation 0x92fc16ba __raiseError + 410
1 libobjc.A.dylib 0x901b4509 objc_exception_throw + 56
2 CoreFoundation 0x9300e90b -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x92f67c36 ___forwarding___ + 950
4 CoreFoundation 0x92f67802 _CF_forwarding_prep_0 + 50
5 QTKit 0x903d3280 MovieProgressProc + 62
6 QuickTime 0x95a66062 convertFileProgress + 212
7 QuickTime3GPP 0x1e7bcaa2 Spit3GP2_Progress + 180
8 QuickTime3GPP 0x1e7c01d8 Spit3GP2_FromProceduresToDataRef + 3438
9 CarbonCore 0x90b0d054 _ZL38CallComponentFunctionCommonWithStoragePPcP19ComponentParametersPFlvEm + 54
10 QuickTime3GPP 0x1e7be33d Spit3GP2_ComponentDispatch + 129
11 CarbonCore 0x90b057c9 CallComponentDispatch + 29
12 QuickTime 0x95befb97 MovieExportFromProceduresToDataRef + 49
13 QuickTime3GPP 0x1e7bdf84 Spit3GP2_ToDataRef + 1987
14 CarbonCore 0x90b1865d callComponentStorage_4444444 + 63
15 CarbonCore 0x90b0d054 _ZL38CallComponentFunctionCommonWithStoragePPcP19ComponentParametersPFlvEm + 54
16 QuickTime3GPP 0x1e7be33d Spit3GP2_ComponentDispatch + 129
17 CarbonCore 0x90b057c9 CallComponentDispatch + 29
18 QuickTime 0x95befbe2 MovieExportToDataRef + 73
19 QuickTime 0x95a6e9bb ConvertMovieToDataRef_priv + 1690
20 QuickTime 0x95bdc591 ConvertMovieToDataRef + 71
21 QTKit 0x903e0954 -[QTMovie_QuickTime writeToDataReference:withAttributes:error:] + 2692
22 QTKit 0x903c5110 -[QTMovie_QuickTime writeToFile:withAttributes:error:] + 111
23 Mevee 0x0005871d -[ConversionQueue convertVideo:] + 509
24 Mevee 0x00058341 -[ConversionQueue startConvertingItems] + 145
25 Foundation 0x9520fbf0 -[NSThread main] + 45
26 Foundation 0x9520fba0 __NSThread__main__ + 1499
27 libSystem.B.dylib 0x9475a85d _pthread_start + 345
28 libSystem.B.dylib 0x9475a6e2 thread_start + 34
)
- (id) init
{
if(!(self = [super init])) return self;
convertingIndex = 0;
conversionPaths = [[NSMutableArray alloc] init];
[conversionPaths addObject:#"/Users/Morgan/Desktop/Convertable Media/Movies/2 Fast 2 Furious/2 Fast 2 Furious.mp4"];
[conversionPaths addObject:#"/Users/Morgan/Desktop/Convertable Media/Movies/101 Dalmations/101 Dalmations.mp4"];
[conversionPaths addObject:#"/Users/Morgan/Desktop/Convertable Media/Movies/300/300.mp4"];
[conversionPaths addObject:#"/Users/Morgan/Desktop/Convertable Media/Movies/1408/1408.mp4"];
[conversionPaths addObject:#"/Users/Morgan/Desktop/Convertable Media/Movies/A Few Good Men/A Few Good Men.mp4"];
[conversionPaths addObject:#"/Users/Morgan/Desktop/Convertable Media/Movies/A Goofy Movie/A Goofy Movie.mp4"];
[conversionPaths addObject:#"/Users/Morgan/Desktop/Convertable Media/Movies/A Single Man/A Single Man.mp4"];
[conversionPaths addObject:#"/Users/Morgan/Desktop/Convertable Media/Movies/A View to a Kill/A View to a Kill.mp4"];
[conversionPaths addObject:#"/Users/Morgan/Desktop/Convertable Media/Movies/Across the Universe/Across the Universe.mp4"];
backgroundThread = [[NSThread alloc] initWithTarget:self selector:#selector(startConvertingItems) object:nil];
[backgroundThread start];
return self;
}
- (void) startProcessingQueue
{
}
- (void) startConvertingItems
{
NSInteger iterations = 0;
while(iterations < 100)
{
NSString* nextPath = [conversionPaths objectAtIndex:convertingIndex];
NSLog(#"ITERATION %d", iterations);
[self convertVideo:nextPath];
convertingIndex += 1;
if(convertingIndex >= [conversionPaths count])
convertingIndex = 0;
iterations += 1;
}
}
- (void) openMovieOnMainThread:(NSString*)path
{
NSError* error = nil;
movie = [[QTMovie alloc] initWithFile:path error:&error];
if(movie == nil || error != nil || ![movie detachFromCurrentThread])
movie = nil;
}
- (void) closeMovieOnMainThread
{
//[movie attachToCurrentThread];
//[movie release];
}
- (BOOL) convertVideo: (NSString*)path
{
[self performSelectorOnMainThread:#selector(openMovieOnMainThread:) withObject:path waitUntilDone:YES];
if(movie == nil) {
NSLog(#"ERROR OPENING MOVIE");
return NO;
}
[QTMovie enterQTKitOnThreadDisablingThreadSafetyProtection];
[movie attachToCurrentThread];
[movie setDelegate:self];
NSString* tempItemPath = #"/Users/Morgan/Desktop/test.mp4";
NSDictionary *attrs = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:YES], QTMovieExport,
[NSNumber numberWithLong:'3gpp'], QTMovieExportType,
nil];
NSError* error = nil;
if(![movie writeToFile:tempItemPath withAttributes:attrs error:&error]) {
NSLog(#"ERROR CONVERTING MOVIE");
return NO;
}
[movie invalidate];
[movie detachFromCurrentThread];
[QTMovie exitQTKitOnThread];
[self performSelectorOnMainThread:#selector(closeMovieOnMainThread) withObject:nil waitUntilDone:YES];
return YES;
}
- (BOOL)movie:(QTMovie *)aMovie shouldContinueOperation:(NSString *)op withPhase:(QTMovieOperationPhase)phase atPercent:(NSNumber *)percent withAttributes:(NSDictionary *)attributes
{
switch (phase)
{
case QTMovieOperationBeginPhase:
NSLog(#"Conversion started");
break;
case QTMovieOperationUpdatePercentPhase:
NSLog(#"Conversion progress: %f", [percent floatValue]);
break;
case QTMovieOperationEndPhase:
NSLog(#"Conversion finished.");
break;
}
return YES;
}
Ahhh... I found out it was the stupid garbage collector. Reworked my app to work with reference counting rather than garbage collection, and smooth sailing. Has anyone else come across similar garbage collection bugs? I had a strong reference to a root object for my movie file, so I don't think that was the problem.

Resources