I have a problem in my iPhone app when trying to instantiate an ARSCNView again, after destroying it.
In my ViewController I programmatically create an ARSCNView for motion capture interaction:
func addARSceneView() {
arSceneView = ARSCNView(frame: self.view.frame)
arSceneView.loops = true
arSceneView.session.delegate = self
self.view.addSubview(arSceneView)
arSceneView.session.run(ARBodyTrackingConfiguration())
}
When the user leaves this part of the app, I tear it down like this:
func removeARSceneView() {
arSceneView.session.pause()
arSceneView.pause(self)
arSceneView.session.delegate = nil
arSceneView.removeFromSuperview()
arSceneView = nil
}
Later, when I try to instantiate an ARSCNView for the second time using the first function above, it crashes with an EXC_BAD_ACCESS in the constructor:
I also tried to use a view from a xib which contains an ARSCNView but the same problem occurs, in that case in the init(coder) function of that view.
I found nothing on this problem, I guess usually developers only create an ARSCNView once.
TLDR: Turn "Metal API Validation" on in your scheme.
I found the culprit, after creating a sample project with only the ARSCNView, which did not have this problem. I started by stripping everything away from my original project until it was as barebones as the sample. That did not solve it, so I compared every little setting of the two, and behold: in the "Run" scheme of the original project, under "Diagnostics", I had "Metal – API Validation" ticked off. I don't remember when and why I did that; I assume it was some attempt to improve performance at one point. However, enabling this checkbox solved the problem completely.
Please note that this error message is pretty low level, so it crops up for different reasons in different scenarios. If you have a scenario that isn't mentioned in one of the answers below, please consider adding your situation as well, so maybe this could be a central answer for various situations that raise this error message.
Edit Nov 10, 2015 Also note, I marked my own answer as the answer, but that was before anyone else had posted. I guess none should really be marked as the answer, because as we've now seen below... this error doesn't have just one answer because it's so low level.
I'm running
iOS 9.0 Simulator
XCode 7.0
Everything was working fine yesterday.
Today, after a bunch of work on rotation related stuff, I started getting this error in my console output when I run the app in the Simulator and I rotate it.
_BSMachError: (os/kern) invalid capability (20)
_BSMachError: (os/kern) invalid name (15)
- I've cleared my build folder,
- I've cleaned the derived data folder,
- I've reset the simulator.
I was working with
UIViewController viewWillLayoutSubviews
UIViewController viewWillTransitionToSize:...
I was also checking various 'Drawing' settings on the Attributes Inspector in IB.
I also made a utility category on UIView where I created a bunch of methods that create CGRect's and helps me assign frames to views.
Based on the https://forums.developer.apple.com/thread/15683:
Change "Localization native development region" in info.plist to United States instead of en.
Updated: Then you can revert these changes back.
I also ran into the _BSMachError console errors while deep linking into the Settings app on iOS 9 from a UIAlertController action. A dispatch_async solved my problem:
[aAlertVC addAction:[UIAlertAction actionWithTitle:#"Settings" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
dispatch_async(dispatch_get_main_queue(), ^{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
});
}]];
Ok, I haven't pinned it down completely, but this will get you 99% of the way there.
I'm using a third party map control from ESRI, and something about it doesn't like one of these drawing settings in the Attributes Inspector. I haven't tried each setting individually to see which setting it is, but when I turned all of them off (in the red box), everything worked like a charm, and I quit getting the error message above in the console. If and when I get time to nail it down to the precise setting or combination of settings, i'll update the answer.
It's crazy but for me the solution was just to remove all breakpoints in the file where the error occured.
As for the cause? I think I accidentally hit a shortcut key to create a breakpoint in the current line. Because that was unintended I hit the same shortcut key again to delete it.
Oh my dear XCode...
I was getting the same errors...
_BSMachError: (os/kern) invalid capability (20)
_BSMachError: (os/kern) invalid name (15)
I was calling openURL() from a UIAlertAction
alert.addAction(UIAlertAction(title: actionTitle, style: .Default) {
UIApplication.shared.openURL(url)
}
Deferring execution of the block until the next run loop fixed it...
alert.addAction(UIAlertAction(title: actionTitle, style: .Default) {
OperationQueue.main.addOperation {UIApplication.shared.openURL(url)}
}
I was getting the following when supplying new data:
> _BSMachError: (os/kern) invalid capability (20)
> _BSMachError: (os/kern) invalid name (15)
The error occurred when a button was used to supply new data. An NSTimer was used to refresh and update data upon returning from a performSegueWithIdentifier action. The timer was being activated and then invalidated immediately after use at return time. The MSMachError stopped when the timer was removed and - (void)viewWillAppear:(BOOL)animated and (void)viewDidAppear:(BOOL)animated were employed to perform the same function. This error started with upgrade to Xcode 7.
I got this issue fixed by changing value of Localization native development region key to United Kingdom [or any Specific region] from its default value en present in info.plist of your project.
Select Project Navigator
Locate info.plist file present in ProjectNameTests folder.
Change value of Localization native development region key to any specific region for eg. United Kingdom
I also ran into the same problem in an NSOperation running on a background thread and I was still getting this error because a UIAlertController was still removing itself as another UI transaction was trying to take place. Modifying my code to this fixed the issue.
defer {
dispatch_async( dispatch_get_main_queue(),{
completion()
})
}
A lot of people don't know about defer -It lets the current scope complete and then runs after. Kinda neat.
I did face the same error invalid capability (20) & invalid name (15). I tried the solutions as mentioned by others such as:
Localisation native development region key in info.plist
Changing drawing settings in the Attributes Inspector
Even altered ATS Exception Dictionary in info.plist
But none of those solutions solved my problem.
Actually, I was trying to share some document but generating document would take some time and wanted to display an UIActivityIndicatorView to the user till the time document loads.
The solution for my error was:
//Create a alertView add UIActivityIndicatorView to it and present it in ViewController
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
//Call method 1 todo background process like getting data
dispatch_sync(dispatch_get_main_queue(), ^{
//Call method 2 to update the UI
[alert dismissViewControllerAnimated:YES completion:^(void){
//My mistake was: I was calling method 2 over here to update the UI
return;
}];
});
});
Changing localization string from en to United States fixed this for me. However, make sure you clean after you change Info.plist. I've noticed that updates don't work when you just build after making plist changes.
In my case it was Little Snitch, it was blocking urls automatically.
I could reproduce the error for me:
If a make changes to one of the Views within a View that I am actually closing already (popViewControllerAnimated) I receive the error.
I am having a UINavigationButton action that makes an asynchronous task (POSTRequest).
Before performing this request I set the customView of that button to an progress indicator.
When coming back from the asynchronous call I dispatch to the main thread and reset the customView of that button.
After that I am closing the view (popViewControllerAnimated).
This is the CORRECT code where the error does not appear:
/* right way, working without BSMachError */
#IBAction func sendRequest(sender: UIBarButtonItem) {
/* setting the progress indicator as customView of the self.saveButton */
self.showActivityIndicatory(self.saveButton)
/* asynchronous REST call */
UserDataManager.sharedInstance.requestFeedback(request, onCompletion: { error in
dispatch_async(dispatch_get_main_queue(),{
/* resetting the saveButton again to default by setting customView to nil */
self.saveButton.customView = nil
/* closing the view */
self.navigationController!.popViewControllerAnimated(true)
})
})
}
What caused the error was switching lines: closing the view and then setting the customView to nil:
/* WRONG way, causing BSMachError */
#IBAction func sendRequest(sender: UIBarButtonItem) {
/* setting the progress indicator as customView of the self.saveButton */
self.showActivityIndicatory(self.saveButton)
/* asynchronous REST call */
UserDataManager.sharedInstance.requestFeedback(request, onCompletion: { error in
dispatch_async(dispatch_get_main_queue(),{
/* closing the view */
self.navigationController!.popViewControllerAnimated(true)
/* resetting the saveButton again to default by setting customView to nil */
self.saveButton.customView = nil
})
})
}
This error started popping up after I added some observers:
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(self.keyboardWillHideOrShow(_:)), name:UIKeyboardWillShowNotification, object: nil)
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(self.keyboardWillHideOrShow(_:)), name:UIKeyboardWillHideNotification, object: nil)
The problem went away when I specified the class name instead of self:
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(MyClass.keyboardWillHideOrShow(_:)), name:UIKeyboardWillShowNotification, object: nil)
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(MyClass.keyboardWillHideOrShow(_:)), name:UIKeyboardWillHideNotification, object: nil)
I had the same error and none of the above applied to my problem. The problem appeared when I registered my view controller as an observer to a device orientation change, so the views could be resized and the drawings in the view could be made according to the new size of the view.
I had an outlet of a viewGraph which was a subclass of UIView in which I drew some graphics.In landscape mode the size of the viewGraph is larger than in portrait mode. So when the device changes its orientation the speedGraph needed to be redrawn.
The problem was, that I added several subviews to the speedGraph view, that contained graphics. These subviews needed to be laid out anew in the speedGraph view and then be redrawn. After the device changed its orientation I called viewDidAppear again to make the speedGraph view and all its subviews to be laid out anew and redraw themselves. Calling setNeedsDisplay for speedGraph doesn't work with orientation changes and subviews in a view.
What did I do wrong that caused the error to appear. In viewDidAppear I call a method which does some calculations and adds the subviews to the speedGraph view. The problem was that these subviews were created in the method and were added to the speedGraph view in this method. After leaving the method, the references to these subviews are, of course, deleted, but the subviews in the speedGraph view remain, since they are added. When the device changes, the subviews are created again and added to the speedGraph view, that already has these subviews, but can't find the references to these subviews anymore. The array of subviews of speedGraph view gets longer and longer with (i think) dangling subviews.
I solved the problem by defining the subviews that will be added to the speedGraph view as a class property and then do what needed to be done with the views inside this method. With this change the problem was gone.
Since we can post all situations returning the same error here, I felt free to post mine :). I got the Error when I changed privacy settings in the background. My app opened the settings app so the user can grant it permission to its photolibrary, when the permission switch is set, the app crashes with the mensioned error:
_BSMachError: (os/kern) invalid capability (20)
_BSMachError: (os/kern) invalid name (15)
This appears to be a forced restart of your app by the OS, because the user changed what your app can acces. So in my case it is an action of the OS who caused the error.
I got the same error message, because I assign a object property like #property (assign, nonatomic) NSNumber *aVariable;, fixed by changing to strong.
For what it's worth - it seems that a lot of situations throw this error. In my case, I had posted an alert when the user was dismissing a data entry form and data was in the form. I was able to eliminate the error by programmatically resigning the first responder from all applicable fields before unwinding the view controller.
I saw this when I pressed the Home button while a UIAlertController was displayed, which was dismissed when I relaunched the app. I added code to dismiss the UIAlertController in the appDelegate:
func applicationWillResignActive(application: UIApplication) {
window?.rootViewController?.dismissViewControllerAnimated(false, completion: nil)
}
and the error message disappeared.
I had this error when dismissing a popover via delegate. In the delegateMethod I triggered some GUI-Stuff.
Putting the GUI-Stuff in the completionBlock of dismissViewControllerAnimated fixed it.
[myPopoverView dismissViewControllerAnimated:YES completion:^{ //GUI-Stuff}];
I am a newb at this so take this for what it is worth.
What fixed this for me was changing the Simulated Metrics > Size > to iPad Full Screen. All of my views EXCEPT for the one that threw this error we set to iPad Full Screen. When I changed it, the error went away...
The reason some developers doesn't get the error came back after changing from "Unites States" to "en" (or) other region, is that there is discrepancy between "Property list" and "Source code" views. It's probably Xcode bug. Whenever there is mismatch between these two views will throw this error, whatever it is "en" or "English". If you changed to "en" or "United States" for both views to be the same, will fix the issue.
I got this error from:
var promptsArr = StartRegAlerts() //Instance of the class
etc
func textFieldDidBeginEditing(textField: UITextField) {
switch textField.tag {
case 0:
alert(promptsArr.prompts["Name"]!)
case 1:
alert(promptsArr.prompts["CellPhone"]!)
case 4:
alert2(promptsArr.prompts["NUMBERCORRECT"]!)
//alert(promptsArr.prompts["Wait4Pin"]!)
default: break
}
It only occurred for case 0 but not the other cases:
As a work around for now I commented out case 0 and that stopped the error.
I then changed calling promptsArr.prompts by:
creating a new dictionary prompt and:
override func viewDidAppear(animated: Bool) {
prompt = promptsArr.prompts //
}
and then used prompt in my alert calls. That fixed the problem.
So it appears that it is a timing issue.
with Xcode 8.1 and iOs 10 I also faced
_BSMachError: (os/kern) invalid capability (20)
_BSMachError: (os/kern) invalid name (15)
trying to override UiTraiCollection var to change at runtime the iPad’size classes to have two different interface layouts in Portraid and Landscape. It worked without any crash but generate our errors.
This was the "maliciuos" code:
override public var traitCollection: UITraitCollection {
if UIDevice.currentDevice().userInterfaceIdiom == .Pad && UIDevice.currentDevice().orientation.isPortrait.boolValue {
return UITraitCollection(traitsFromCollections:[UITraitCollection(horizontalSizeClass: .Compact), UITraitCollection(verticalSizeClass: .Regular)])
}
return super.traitCollection
}
The errors gone using override func viewWillTransition as alternative to detect interface rotation.
I hope this will be useful to someone
In my case the cause of the error was due to resizing. Built in IB. Anything that can change the size of a text field or similar for example changing line length can lead to this error I believe. In my case I simply had to adjust the text field size to cover all possibilities so it doesn't need to resize the box and conflict with something else.
I have been working on this app for months now and from as far back as I can remember I have never had an issue with segues. The code is unchanged in terms of calling performSegueWithIdentifier but since my recent update to Xcode 7 and iOS 9 I have not been able to tack this issue.
I have tried:
Deleting button and creating new button w/ segue link
Using a direct segue from button to view, without the use of performSegueWithIdentifier
Connecting button to new blank viewController
When I press the button, no initial load functions are called on the destination VC (Ex: ViewDidLoad, ViewWillAppear, etc). When I connect it to a blank view, the segue works fine with the same code in place.
Since the code never stops, or breaks, and just seems to "freeze" in place while still running on Xcode I can't seem to even narrow this down to whats causing the issue. I have a similar segue that is also called from another button on the same ViewController that has no issues whatsoever.
Any thoughts on the matter are greatly appreciated!
EDIT: I have narrowed the issue down to the UITextView's causing the problem. Once the Text Views were removed the page loads fine via segue. I wonder what changed between iOS 8 and iOS 9 in terms of UITextView as I will have to remove the text views and completely re add new text views.
So basically the segue was freezing because of the UITextView's I was using in the destinationViewController. The following fixed the issue:
Delete all UITextView's
Add new UITextView's
you must leave the default lorem imposed text and change this programmatically in the viewDidLoad()
This was the fix for me, and from the research I have done on the issue it seems this is a bug in iOS 9 and Xcode 7.
Cheers!
NOTE: Removing the text in the UITextView (or making it longer then ~12 characters) is sufficient to work around it, no need to delete and recreate them. This is fixed in Xcode 7.1.1 and later.
I ran into the same issue and the fixes in this post (Xcode 7 crash: [NSLocalizableString length] 30000) solved the issue for me.
The first is to enable a localisation other than the base for the storyboard (see https://stackoverflow.com/a/32688815/3718974)
The second is to turn off the base localisation (see https://stackoverflow.com/a/32719247/3718974)
I think I have the same problem: I have a UITabelView with cells created from a nib file, when a user tap a cell this method is called:
and when I have the following method prepareForSegue:: the application crashes:
if I delete the line 129 Everything is ok , the method prepareForSegue:: open the right view and the label contactName is shown with its default text.
If I modify the method as follows prepareForSegue:: get exactly what you expect, without having any type of error:
let me know if you also get the same result
Any one who is facing this issue, i solved it by turning off the "Optimize rendering for windows scale" option in Debug of simulator window. I already had tried all of the above answers but could not solve the issue.
In the method in the first viewController where you activate the segue, do you have beginIgnoringInteractionEvents anywhere? If so the screen you segue to will be frozen and will ignore interaction events like you describe. If this is the case you can fix this by adding an endIgnoringInteractionEvents method before your segue method:
UIApplication.sharedApplication().endIgnoringInteractionEvents()
self.performSegueWithIdentifier("editItemToMyGearSegue", sender: self)
I realize this is an old topic, but appears to be still relevant. I was facing the same problem in Xcode 9, iOS11. My UITextViews are embedded inside UITableViewCells. Same symptoms as described here. The tricks with default text and placeholders did nothing for me, but I solved it by turning off the scrolling indicators for the text view in the xib. They were on by default, I guess, though unused.
Edit: this is probably an important detail... the views that were hanging all had an image NSTextAttachment in the attributed string of the text view. I think the image was wider than the available table cell content. With scrolling turned off, they appear to downscale.
I have the following situation: I do a check when user touches screen, to check if it matches some bounds if menuButton.frame.contains(coordinates) {
Then, I try to push a segue like this performSegueWithIdentifier(menuButton.whichButton(menuButton.tag), sender: self) My problem is that the first time the segue performs, it has a huge delay (about 3-4 sec). Afterwards, everything runs as it should. I did check for main thread and I am in the main thread. Can you please help me?
I found the answer, as strange as it may appear, it was related with the fonts. I added some fonts, selected them in interface builder, but of course I didn't check the target membership. So the system was looking for them, I think, before reverting to default font, thus creating the lag. I hope it helps someone at some point.
Have you tried to run on a device or only in the simulator? Just to make sure...
You can try this too:
dispatch_async(dispatch_get_main_queue(),{
self.performSegueWithIdentifier(mysegueIdentifier, self)
})
I am using a UISwitch to call a subview to screen in my app. However, the switch only works about 60% of the time. To test my code I hooked the switch to another IBAction to write the state of the switch to the console. Both functions are not responding to the state of the switch at certain times, i.e., both functions are ignoring the state of the switch simultaneously some of the time. Has anybody else experienced this behaviour with UISwitches in iOS7?
- (IBAction)showHideSomeSubView:(UISwitch *)sender {
if (_mySwitch.on) {
[self.view addSubview:someSubView];
}
else {
[someSubVew removeFromSuperview];
}}
Edit:
The same switch is connected to the following action:
- (IBAction)switchToggled:(UISwitch *)sender {
sender = _mySwitch;
if ([sender isOn]) {
NSLog(#"On");
} else {
NSLog(#"Off");
}}
Both actions respond in the same way to the switch.
I confirm that weird behaviour with you!!!!
Just drag the little circle of the switch around and around, you will see the action called multiple times (in my case up to 403 :D )
I am really not sure that is what Apple engineers intended to do, because I have not found any documentation about this new behaviour, BTW, if you find one, please let me know too.
Thank you very much
I'm using several UISwitches in an iOS 7 app, I have had no problem at all responding to the Value Changed action. The switch consistently reports its value correctly. You should unhook the switch from its action in IB and then reconnect, making sure you are connecting the Value Changed action.
Yes, with a UISwitch in the iOS 7 iPad simulator, I am seeing 1-12 callbacks to my equivalent of your switchToggled: method. On the last callback, the value has in fact changed. On the previous callbacks, it hasn't. What I am doing is caching whether or not the switch is on. Then in the switchToggled: method, I check whether or not the value has in fact changed. If it hasn't, I ignore the callback. This seems to make things behave correctly for the user.
The problem does also happen on the device, though apparently less often. The same work-around seems to work there.