I'm trying to integrate some third-party SceneKit code into my app, and I'm experiencing a mysterious crash. Oddly, the crash gives no error or log in Xcode, and the stack trace is just "UIApplicationMain". No helpful info there.
The code works in the third-party app where I got it and I've copied it wholesale, so I know it must be some delegate call or some framework that I haven't included, etc. But this is my first experience with SceneKit so I'm having trouble closing in on what it could be.
The crash happens during an event where the user taps on the screen and a new 3D object is added to the scene. I've breakpointed all the associated methods, and the crash seems to be happening in the in-between time, presumably the internal SceneKit functionality, so I can't pinpoint it.
My Crashlytics report, though, did pick up some info, which I have included here:
Thread : Crashed: com.apple.main-thread
0 libobjc.A.dylib 0x00981ea8 _objc_empty_cache
1 SceneKit 0x015e0273 __28-[SCNPhysicsBody _setOwner:]_block_invoke + 214
2 SceneKit 0x016b05b5 C3DTransactionFlush + 2014
3 CoreFoundation 0x00bff86e __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 30
4 CoreFoundation 0x00bff7b0 __CFRunLoopDoObservers + 400
5 CoreFoundation 0x00bf51ea __CFRunLoopRun + 1226
6 CoreFoundation 0x00bf4a5b CFRunLoopRunSpecific + 443
7 CoreFoundation 0x00bf488b CFRunLoopRunInMode + 123
8 GraphicsServices 0x043042c9 GSEventRunModal + 192
9 GraphicsServices 0x04304106 GSEventRun + 104
10 UIKit 0x01b99106 UIApplicationMain + 1526
11 SW LiveSheet 0x0007888a main (main.m:14)
12 libdyld.dylib 0x04e61ac9 start + 1
A search of my project finds no examples of SCNPhysicsBody _setOwner:, so I'm assuming that is an internal SceneKit method?
Does anyone know what might be causing a crash like this? I'll include any methods that might be relevant (if you tell me what they might be), but the series of methods to create the object is very long, so it didn't seem productive to blindly copy it all here. Plus, as I said, the crash seems to be happening "between the methods" anyway.
Does anyone recognize this error? Or are there any common "getting started with SceneKit" mistakes that I might be making, that could lead to this? I know the code works because it works in the other project, it's just a matter of what got lost in translation. Also, the scene does load successfully before the tap begins the process of adding the new object.
Can anyone point me in the right direction? Even just an idea of where to investigate would be appreciated.
Thanks for helping out a SceneKit newbie!
Weirdly, the answer ended up being just running the app on a device. I never could figure out what was wrong in the Simulator, but as soon as I tried running it on a device, it worked without changing anything!
Frustrating, to try to hunt down a solution for such a weird thing, but hopefully this will help anyone who experiences something similar.
If you're doing something with SceneKit and you're getting a bizarre error like this, try running it on a device before you tear too much of your hair out.
Related
I'm running corona SDK with a chartboost plugin, and I'm experiencing crashes about 20% of the time at startup, when I try to initialize the plugin (which I can't edit, I don't have the source).
Here's the symbolicated crash report: http://pastebin.com/id1AsjmN
I've been reading up a little on how to make sense of these crash reports, and from what I understand, these two frames in the main thread:
9 CoreFoundation 0x295d9008 +[NSException raise:format:arguments:] + 100
10 Foundation 0x2a2d8bc4 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 88
Are the most critical to understanding my problem. How can I understand what these lines mean? The "object:file:lineNumber:description:" and "raise:format:arguments:" business seems almost cruel, because I feel like those should be filled in with information that would help me -- what class, and line number we're talking about. Am I right? Are these placeholders in the error message? What am I not grokking here? Is there ANY way of knowing where this error came from?
It's not symbolicated crash log. To be more precise, partially symbolicated.
9 CoreFoundation 0x295d9008 +[NSException raise:format:arguments:] + 100
10 Foundation 0x2a2d8bc4 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 88
11 UIKit 0x2d00946e -[UINib initWithNibName:directory:bundle:] + 158
12 UIKit 0x2d00955c +[UINib nibWithNibName:bundle:] + 56
13 splashboardd 0x000bee8c 0xbc000 + 11916
Somewhere in your splashboard code something is called (0x000bee8c 0xbc000 + 11916 - not symbolicated). This calls +[UINib nibWithName:bundle:], which calls -[UINib initWithNibName:directory:bundle:], which causes your crash.
Google for How to symbolicate crash log and when you'll succeed, 0xbc000 + 11916 will be replaced with class name, method name, line number, ... That's the place where the problem is. Also that's the reason why you should keep debug symbols for your app as well. To be able to symbolicate it.
Also sometimes there's useful info in console as well. Additional messages, which can help you with debugging.
I'm new to xcode and this forum, so sorry for my unprofessional language.
I have a problem with the iOS simulator crashing when I'm trying to run an app. It does not always happen, when I've just started working on a project everything's fine. But then suddenly after I just change something minor in the code the iOS simulator crashes as soon as it starts (compiling works). Xcode then takes me to the debugging page and also shows a lot of output in the bottom-right-corner-window (which I don't know what it's called). I don't get anything of the output, it says something about NSencryption. Once the iOS simulator has started crashing it will crash every time it starts running that project/app. Even if I undo my changes I did when it stopped working and even if I erase all of my code and everything looks like a new project, IT JUST WON'T RUN.
Tried to call Apple support to solve this problem, but they said I should post a question in a forum, hope you can help me as I am really getting tired of this, I can't build anything.
Btw I've tried to reset the iOS simulator but the same problem continues to occur.
Here is the output I get from the 'console': Btw, please tell me if any of this code is sensible and I will remove it.
2015-03-26 17:39:52.727 Testing123[19815:4331412] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<Testing123.ViewController 0x7f93ea8272c0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key addFive.'
*** First throw call stack:
(
0 CoreFoundation 0x00000001026e1a75 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x0000000104239bb7 objc_exception_throw + 45
2 CoreFoundation 0x00000001026e16b9 -[NSException raise] + 9
3 Foundation 0x0000000102afcd43 -[NSObject(NSKeyValueCoding) setValue:forKey:] + 259
4 CoreFoundation 0x000000010262b5e0 -[NSArray makeObjectsPerformSelector:] + 224
5 UIKit 0x000000010323b4ed -[UINib instantiateWithOwner:options:] + 1506
6 UIKit 0x0000000103099a88 -[UIViewController _loadViewFromNibNamed:bundle:] + 242
7 UIKit 0x000000010309a078 -[UIViewController loadView] + 109
8 UIKit 0x000000010309a2e9 -[UIViewController loadViewIfRequired] + 75
9 UIKit 0x000000010309a77e -[UIViewController view] + 27
10 UIKit 0x0000000102fb9509 -[UIWindow addRootViewControllerViewIfPossible] + 58
11 UIKit 0x0000000102fb98a1 -[UIWindow _setHidden:forced:] + 247
12 UIKit 0x0000000102fc5f8c -[UIWindow makeKeyAndVisible] + 42
13 UIKit 0x0000000102f700c2 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 2732
14 UIKit 0x0000000102f72e3e -[UIApplication _runWithMainScene:transitionContext:completion:] + 1349
15 UIKit 0x0000000102f71d35 -[UIApplication workspaceDidEndTransaction:] + 179
16 FrontBoardServices 0x0000000105deb243 __31-[FBSSerialQueue performAsync:]_block_invoke + 16
17 CoreFoundation 0x0000000102616c7c __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12
18 CoreFoundation 0x000000010260c9c5 __CFRunLoopDoBlocks + 341
19 CoreFoundation 0x000000010260c785 __CFRunLoopRun + 2389
20 CoreFoundation 0x000000010260bbc6 CFRunLoopRunSpecific + 470
21 UIKit 0x0000000102f717a2 -[UIApplication _run] + 413
22 UIKit 0x0000000102f74580 UIApplicationMain + 1282
23 Testing123 0x00000001025051ee top_level_code + 78
24 Testing123 0x000000010250522a main + 42
25 libdyld.dylib 0x0000000104a15145 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
This is the code that gives me this error:
` import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}`
Here is the project
You haven't given many details, but here's how to start resolving your problem.
The bottom of your Xcode app has a debugger window. In that window, messages from the app will display. When your app crashes, it will print out a stack trace which shows what happened just prior to the crash.
When posting here, you'll want to include that in your post. Within that crash log, the top portion will tell you what the problem was--typical issues are nil values or calling something outside a range. Looking further down in the crash log, you'll usually see system stuff (UIKit, etc.). Look at the most recent method called in the class YOU created. Then, find that method in your code and add a breakpoint next to it. The breakpoint will stop execution of your code when it gets to that spot. At the top of the debugger window in the bottom portion of your screen, you'll see a few buttons. One of them is "step over". When you hit your breakpoint, use the "step over" button to execute your code one line at a time. When you get to your problem, it'll crash.
You'll also want to Google the error the debug console spits out. 9 times out of 10, someone's encountered the issue you're encountering and you'll be able to proceed towards resolution of your problem. If that doesn't get the problem solved, you'll want to post here with details and the problematic methods.
Another thing I'd recommend doing is learning how to use GitHub. When I started learning this (and I still AM learning it), git seemed like overkill, but in hindsight it would have been a good idea to learn how to use git from the start. You'll be able to create branches to work on features in your software and merge them to a "master" when you've got new features working. When I was starting, I would get fairly far along, I'd make a minor change and I'd break a bunch of stuff--that will still happen with Git, but you'll have a version of the software that functions. Using Git, you'll be able to always have a stable version that works and you can add features without worrying about blowing up your entire project.
Good luck!
Update for new info:
Your starting point would be Googling this: Terminating app due to uncaught exception 'NSUnknownKeyException', reason: ViewController setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key.
Also, the import UIKit should be #import UIKit. I suspect this post will steer you in the right direction.
What does this mean? "'NSUnknownKeyException', reason: … this class is not key value coding-compliant for the key X"
Solution:
You have a ViewController.swift file, but your storyboard file is
1) incorrectly named and
2) doesn't have any scenes on it.
Here's what you need to do:
1) rename the storyboard file "Main.storyboard"
2) add a View Controller scene on storyboard, as you currently have no scenes on your storyboard. You do this by dragging & dropping View Controller from the lower right-hand portion of the screen.
3) When your ViewController scene is highlighted, at the top right-hand portion of your screen you should see some buttons. One of them is called "Attributes Inspector". Make sure "Is Initial View Controller" is checked. One button over to the left is "Identity Inspector". Make sure class is set to ViewController.
I'll say it again. If you want to learn iOS, I'd recommend learning GitHub first. Additionally, Stanford University has a free iOS course taught by a guy who worked closely with Steve Jobs which you'll probably find helpful. If it's "too much" starting out, I'd suggest picking up a Big Nerd Ranch book or looking at Ray Wenderlich's website.
The pertinent part of the error message is:
"[<Testing123.ViewController 0x7f93ea8272c0> setValue:forUndefinedKey:]: this class is not key value coding-compliantfor the key addFive.'
Look for where you are using addFive. That is not defined for the instance yu are using it with.
We are seeing a strange crash in our map based iOS app that I cannot figure out. Basically as some point the following lines of code repeat over and over, more than 100 times in crash log:
6 VectorKit 0x000000019050c6f8 __86-[VKMapCameraController _animateToPosition:pitch:yaw:duration:timingCurve:completion:]_block_invoke347 + 40
7 VectorKit 0x0000000190485a30 -[VKAnimation _stopAnimation:] + 140
8 VectorKit 0x0000000190488b20 -[VKMapCameraController setYaw:animated:] + 100
9 MapKit 0x000000018540263c -[MKMapView snapToNorth:] + 148
before finally calling:
0 CoreFoundation 0x0000000183251e38 _CFArrayReplaceValues + 152
1 CoreFoundation 0x000000018332876c __CFRepositionTimerInMode + 108
2 CoreFoundation 0x000000018332876c __CFRepositionTimerInMode + 108
3 CoreFoundation 0x0000000183272630 CFRunLoopTimerSetNextFireDate + 580
4 MapKit 0x00000001853e8588 -[MKMapView _didChangeRegionMidstream:] + 196
5 MapKit 0x0000000185404e90 -[MKMapView mapLayer:didChangeRegionAnimated:] + 60
where _CGArrayReplaceValues crashes with a EXC_BAD_ACCESS KERN_PROTECTION_FAILURE at 0x000000016fccbef0 error.
I'd like to point out we never directly call any of the methods in this crash report, in fact VectorKit is completely private Apple framework. The only thing we ever do in the app remotely related is call basic setRegion:animated: methods, usually after a user taps an annotation to center on said annotation. It is also worth pointing out this only happens on iOS 8. Not a single iOS 7 crash has been reported.
Here is a link for full crash report: http://crashes.to/s/f09eb96c753
Any help is appreciated. Thank you.
Try enabling NSZombieEnabled. Once enabled, when an object reaches a retain count of 0, instead of being deallocated it'll morph itself into an NSZombie instance. When a zombie receives a message it will log a warning rather than crashing or behaving in an unpredictable way.
To be quite honest i'm not really sure why this is only crashing on iOS 8 and not iOS 7 but a EXC_BAD_ACCESS signal is the result of passing an invalid pointer to a system call, so you might be dereferencing a null pointer somewhere.
If the above NSZombieEnabled doesn't uncover the issue then try using the Static Analyzer.
I am getting a crash in the app with the following stack trace-
Thread : Crashed: com.apple.main-thread
0 libobjc.A.dylib 0x39dfa66a objc_release + 9
1 libobjc.A.dylib 0x39dfb0d7 (anonymous namespace)::AutoreleasePoolPage::pop(void*) + 358
2 CoreFoundation 0x2f4a6c69 _CFAutoreleasePoolPop + 16
3 CoreFoundation 0x2f53c1cb __CFRunLoopRun + 1306
4 CoreFoundation 0x2f4a6f0f CFRunLoopRunSpecific + 522
5 CoreFoundation 0x2f4a6cf3 CFRunLoopRunInMode + 106
6 GraphicsServices 0x343ff663 GSEventRunModal + 138
7 UIKit 0x31df216d UIApplicationMain + 1136
8 Batted 0x0009db07 main (main.m:16)
The crash occurs when zombies are not enabled in the Scheme's diagnostics options. However, when I enabled it the crash doesn't occur.
I have read some of the other Q&A regarding this, and all of them seem to advice that once this behavior is seen, enable the zombies and run the Zombie Profile Instruments on the Simulator.
I tried that, but Instruments doesn't seem to indicate anything wrong and the app works.
Any clue to what else can be done here to root-cause this issue?
I am using XCode 5.1 with iOS 7.1 in Simulator.
UPDATE 1
Found the offending code causing the problem but I am still not sure why it is causing the problem.
I am using CoreData, and in subclass of the NSManagedObject, I have -
- (void)willTurnIntoFault;
{
[super willTurnIntoFault];
if ([self observationInfo])
{
BNLogInfo(#"%# has observers:\n%#", [self objectID], [self observationInfo]);
}
}
In the above code, [self observationInfo] is the offending line.
When the app starts up, I loop over some of the NSManagedObjects in an enumeration block and set some property on it, which in turn fires the willTurnIntoFault method. Once the enumeration block completes, the crash happens.
The mystery is that the crash doesn't happen inside this method, but without this method subclassed everything runs fine.
The Q&As say to enable zombies (or run under the Zombies instrument) because a zombie often causes this sort of error.
But it's not the only cause.
Your program is corrupting the heap. Most likely it's overwriting the isa pointer (the class pointer) in some object that's in the autorelease pool, so when the run loop drains the autorelease pool, objc_release tries to dereference the bogus isa pointer and crashes.
Enabling zombies can mask an error like this because, with zombies, the runtime never actually frees objects. This means you end up with lots of parts of the heap that don't get used (unless you try to send a message to a zombie), so they never cause trouble if you corrupt them.
These sorts of crashes can be very difficult to debug, but there's a tool called “guard malloc” that sometimes helps. From the menu bar, choose Product > Scheme > Edit Scheme. Click the Run action in the list on the left. Then click the Diagnostics tab. Turn on the “Enable Guard Malloc” option. Then try to reproduce the crash. Guard malloc will detect certain types of heap corruption immediately and stop the program on the corrupting instruction.
I am stuck with the following crash report:
Date/Time: 2013-09-12 22:39:54 +0000
OS Version: iPhone OS 6.1.3 (10B329)
Report Version: 104
Exception Type: SIGSEGV
Exception Codes: SEGV_ACCERR at 0xa0000008
Crashed Thread: 0
Thread 0 Crashed:
0 libobjc.A.dylib 0x39a3c564 _cache_getImp + 4
1 libobjc.A.dylib 0x39a3e1d7 class_respondsToSelector + 31
2 CoreFoundation 0x31b96605 objectIsKindOfClass + 37
3 CoreFoundation 0x31b9635d __handleUncaughtException + 69
4 libobjc.A.dylib 0x39a41a65 _objc_terminate() + 129
5 libc++abi.dylib 0x3948e07b safe_handler_caller(void (*)()) + 79
6 libc++abi.dylib 0x3948e114 std::terminate() + 20
7 libc++abi.dylib 0x3948f599 __cxa_current_exception_type + 1
8 libobjc.A.dylib 0x39a419d1 objc_exception_rethrow + 13
9 CoreFoundation 0x31adcf21 CFRunLoopRunSpecific + 457
10 CoreFoundation 0x31adcd49 CFRunLoopRunInMode + 105
11 GraphicsServices 0x356a82eb GSEventRunModal + 75
12 UIKit 0x339f2301 UIApplicationMain + 1121
13 Our App 0x0003bc27 main (main.m:15)
After different attempts to fix the bug causing this error I keep receiving this crashlog again and again from PLCrashReporter (from our adhoc builds from the beta testers). The different exception codes vary from SIGSEGV/SEGV_ACCERR to SIGBUS/BUS_ADRALN to EXC_BAD_ACCESS/KERN_INVALID_ADDRESS
I am using the rapidjson library on iOS (armv7 and armv7s) with the padding fix as described here (#8) and I use the objective-c runtime functions to add method implementation on runtime (using class_addMethod).
Our codebase exists of mostly Objective-C code with some Obj-C++ and some C code. Memory Management is done by ARC except for the Obj-C++ and C parts which is handled manually. I looked into every malloc/free call and I extensively used libgmalloc to determine memory issues but there is nothing which does not seem correct to me.
I cannot reproduce this crashlogs myself, not in debug or release mode, but our beta testers keep sending me this crashlog once in a while (1 in about 50 runs). As our product (hopefully) will run on many iOS devices soon, this is not something we can left broken.
After reading a lot of memory management articles I suspect this issue is caused by bad memory alignment. Therefore I suspect rapidjson to be the cause of this bug. My lack of knowledge about memory alignment on iOS / armv7 does not allow me to fix this crashlog. Can someone explain me more about this subject on iOS? Or am I looking in the wrong place and is this another memory issue?
I hope someone can point me in the right direction.
If more info is needed I am happy to provide it.
Note: I am not looking for answers as using JSONKit or another library to replace rapidjson. Thanks :)
This issue was previously addressed here: https://devforums.apple.com/message/807860
In short, the original Objective-C exception has been released (eg, by an autorelease pool) prior to it being dereferenced in the uncaught exception handler. As such, __handleUncaughtException() dereferences a now-dead pointer, and you see the crash in your exception handler.
First, the address 0xa0000008 does not look misaligned, and SEGV_ACCERR does not mean an alignment problem, but a memory access permission problem (from sys/signal.h):
#define SEGV_ACCERR 2 /* [XSI] invalid permission for mapped object */
Considering you are using class_addMethod() and the crash is in _cache_getImp(), which is part of retrieving a method, my largely unfounded suspicion would be that you passed some invalid pointers to class_addMethod(), or overwrote that information later on.
Something to check would be whether you are using either globals or malloc()ed memory, because the runtime functions do not make copies for you.
Second, the crash you are seeing is secondary, you are crashing while running the top-level exception handler that is already terminating (_objc_terminate()) your program from an earlier exception, but in this case it's not a Unix signal, but an Objective-C exception: objc_exception_rethrow().
So you probably need to figure out that primary error first, for example from logs of the exception (just a backtrace isn't enough in many cases).