iOS crash only when NOT running via XCode. Concidence? - ios

My app was crashing only when not running using XCode debugger. It was hard to track because I can't debug but I finally figured it out. It was because of calling release on some object not owned by me. Before I corrected it I searched and found 2 related questions here (links below)
iOS App Crashes when running by itself on device, does not crash when running through Xcode using debugger, or in simulator
iPhone crash only when device not connected to xcode, how to understand the crash log?
None of the above question has answered why no crash when running via debugger.So my question is why it happens ? I know reasons for debug/release specific crashes but this is crazy. Is it just by chance although it happened more than 10 times.

What you describe is not atypical of obscure memory-related bugs. You might also want to use debug-malloc at such times. Although that is not guaranteed to find everything. The reason (and it's been happening probably as long as there've been source-level debuggers) is that memory is laid out at least somewhat differently in debuggable code, and when running under the debugger. So the error results in a different piece of memory being (harmlessly) corrupted when under the debugger. When not under the debugger the location corrupted is actually something that your code cares about, and it crashes.
The same could happen in reverse, but you'd never know - if it crashes when run debuggable, you'd find it before switching to running outside the debugging environment.

Reiterating #jyoung's answer since I didn't see it the first time I glanced through:
Try running with Zombie Objects turned off.
In debug mode if you have it turned on it is handling memory allocation differently. Try running it without.
Go to Edit Scheme... > Run > Diagnostics. Then make sure zombie objects is turned off:
Then run through your code path again.

I had this same issue while working on a project modularised with Xcode Frameworks. Even after removing all the logic in AppDelegate and only returning true inside application:didFinishLaunchingWithOptions, I was still getting the crash. Then I switched to my project settings, in the Frameworks, Libraries, and Embedded Content section and changed the embed option for the frameworks I added to Embed & Sign. This was what fixed the issue for me. I hope someone finds this helpful.

I was having this problem as well and was fortunate to figure out the cause quickly, hopefully by posting here I can save someone else some wasted time. To clarify, my app would run with no issues when launched directly from XCode, but would crash immediately when launched manually on the iPad.
The app in question is written in Obj-C but relies on some 3rd party code written in Swift. The Swift code is included in the app as an embedded framework. I had to set "Embedded Content Contains Swift Code" to Yes in the Build Settings for the app (under Build Options), then the problem went away.

I experienced this symptom when I made a NSString, sent a UTF8String from it to another object, and assigned it to a char pointer. Well, it turns out that I forgot to retain the original NSString, which wouldn't have mattered anyway, since I also failed to realize that the UTF8String method (which is presumably an object that gives access to the pointer itself) operates in the autorelease pool. That is, retaining the NSString itself did not fix the problem.
I suppose this appeared to work just fine when attached under the debugger only because I had zombies enabled, so the pointer I had was still valid. I should see if this is the reason it worked; if so, this is a good reason to test with and without NSZombie enabled.
At any rate, this was probably poor design to begin with, and a pretty obvious newbie memory management mistake once I found it. Luckily the console in the Organizer window gave me some hints on where to start looking, and debugging ultimately showed me where my pointer's value was changing. Hope this helps anyone who finds the way here.

I had this issue when accessing SQLite databases from outside the [[NSBundle mainBundle] resourcePath] directory, which caused iCloud errors.
I discovered the error only by installing a Console app onto my iPhone which logged the errors.
Once I accessed the databases from the correct directory, the errors disappeared and the application booted correctly.

Related

Swift sometimes calls wrong method

I noticed strange behaviour during working with Swift projects. I can't explain it other than Swift sometimes calls wrong method. It is very rare and even adding blank lines to the code could lead that this error is gone.
Let me explain in screenshots what I mean, next I use CoreData example of SwiftDDP project that can be found on Github, but such issues I was able to see in my own projects.
Here we at Todos.swift:74 where you can see breakpoint, I expect that next call should be getId() method of MeteorClient class because it was already instantiated:
After Step Into as you can see the ping() of the same instance is called:
The next two steps into lead to EXC_BAD_ACCESS exception:
In my project I saw this issue fairly often before I stopped using singletons, so it could be related to Swift static memory usage or I don't understand something that is not surprising as I have little experience with multithreading and memory management.
My environment is:
AppCode OC-145.184.11
Xcode Version 7.2.1 (7C1002)
iOS 9.2 SDK
Apple Swift version 2.1.1 (swiftlang-700.1.101.15 clang-700.1.81)
NOTE: Here I use AppCode but the same behavior I was able see in Xcode, and even more if the same issue that reproduces in Xcode could not reproduce in AppCode and vice versa.
Would be thankful if someone can explain this strange behaviour to me.
Thanks!
This just happened on my team, using Swift 2.2. It's really incredibly strange. It's not a threading issue or an async problem, it was a very cut & dry use case. We called one instance method and another one above it got called. I deleted the method that was getting called, and then the one above THAT got called instead. Then I moved the method I was actually calling to a different location in the file, and it looked like multiple properties were getting called.
This is disturbing and worrisome, as now you feel you can't trust your code to run properly.
But we did "solve" it. We moved the method up to the code that was actually getting triggered, and after a little trial & error the right method got called. Not yet sure if this will manifest itself for other methods.
It'd be nice to be able to provide a simple project where this is happening, but it seems highly unlikely that it's possible, and I can't share a snap shot of my code base with Apple. It must be a perfect storm of something to cause a bug with Swift's run time.
I had a similar issue, I think. Couldn't see that the wrong function was being called, but breakpoints on the function that was being called were never hit, and I couldn't step into the function from where it was being called. I added a new function (I called it wtf) with the same parameter list and implementation, and that one worked as expected, so it must have been a weird linking issue in the Swift compiler.
Update: super-cleaning appeared to work (see below), but it doesn't. Looks like I'm leaving my wtf function in.
After super-cleaning the project, it looks like everything's working as expected again:
clean (cmd + shift + k)
clean build dir (cmd + opt + shift + k)
quit XCode
delete derived data (rm -rf ~/Library/Developer/Xcode/DerivedData/*)
FYI, in my case, the function I call is in a generic base class, called from a generic subclass, triggered by a specialized sub-sub-class. As we all know, the generics are still very buggy in the Swift compiler, so that's probably why I encountered this.
Do you have multiple threads running? Maybe a network thread?
I thought I had this issue too but then it turned out my one thread was doing something and because the other thread crashed it stopped the other thread at a random point. I only noticed this thread so it seemed like it crashed at a random #IBAction function.
When I switched to iPhone 6 simulator instead of iPhone 7, it seems to be working correctly now!
Our app was rejected from review because of a mysterious crash. After debugging I found that it was having this same issue - but only for the Release scheme!
So I went through every setting in Build Settings one by one to see if switching it to that of another scheme would fix the issue: changing ENABLE_TESTABILITY to true fixed it......

Xcode 7 crash every time I try to print something in the debugger console

I've searched around and can't find anything on this.
Using Swift 2 and Xcode Version 7.0.1 (7A1001). Every time I execute something in the debugger console, Xcode crashes.
The project is not very big, and has less than 10 third party frameworks.
I can't think of much more information that's relevant, but I'm sure there's more, so please do ask me if there's anything I should add to my question that would help.
I've of course cleaned build and derived data.
It's driving me insane. Thanks!
UPDATE 16/11/12
Submitted rdar://23559366.
How are you maintaining your third party frameworks? Via Carthage?
If so then this is probably your issue: https://github.com/Carthage/Carthage/issues/924
This is an issue if the location of the /Carthage/Build/iOS folder is in a different location to where it was produced (i.e if it was compiled on a different machine and the absolute file path has changed).
A temporary fix would be to run carthage build --no-use-binaries on your machine to rebuild the symbols using the current absolute file path working around the bug.
But if you wasn't using carthage then its probably not your issue so sorry
I had similar problem with Xcode whenever I hit breakpoint.
In case you see this screen right before your Xcode crashes - you are lucky and my fix might save you. All you need to do is open this window and in the Project Navigator, select any file that you want, so that instead of that white blank view you would get your code. After this you are most likely will be able to successfully stop your app at your breakpoint and perform the debug.
I am not sure why this happens, but I suspect that the reason is Debug View Hierarchy mode, which you might have triggered prior to setting you breakpoint and trying to stop at it. At least this is when it happens to me.
I have similar problem earlier.
If you try to print non-optional variable and unfortunately it holds nil value then it breaks/crash. so that make sure declare all possible variables as "Optional type".

Crashing on simulator, not on device

My app crashes (randomly by the way) when running on the device, the crash is not reproduce-able 100% of the time. But it only seems to occur on the device, not in the simulator.
When I run in the simulator with NSZombies I never see problems. Could someone shed some light into my points below.
Device has limited memory, maybe it's crashing because of this.
What would be considered a big memory allocation that would cause a crash?
Would memory leaks/big allocation cause a memory corruption?
All my crashes are always EXC_BAD_ACCESS but like I said, never happens on simulator so I can't run zombies. (or is there another way?)
Note I have also simulated low memory warnings on the simulator to see if that's causing issues.
This is driving me nuts. Any help would be appreciated.
I know where it crashes but I need to know which other classes released this object.
Override -[release] -[autorelease] and -[retain] for your object (or you could do this for NSObject if you didn't know which object), then log them, set breakpoints.
If you identify which object is being released at each point, add timestamps/ object IDs/retaincount to the log statement, then you might be able to throw all of the data into a spreadsheet and then to get the same sort of data that Instruments would give you.
Shame you have to build for 3.0. Almost nobody uses 3.x anymore, and ARC (while not a silver bullet for all issues) is way better than non-ARC.
Also here's a tip: delete the app from your simulator and reinstall it. I had an issue where some of my bundle resources were missing in my project but the Simulator was hanging onto them between builds. If you tried to load a .xib that is no longer in your project, I could see it crashing...

Wintermute iOS App Gets "EXC_BAD_ACCESS"

I am currently attempting to port a game I've developed in the Wintermute Lite engine to iOS platforms. My game will compile just fine in XCode (albeit using the armv6 architecture) and will run perfectly on the iOS simulator; however, when I try to deploy it to an iPad, the first thread will halt in XCode with the error "EXC_BAD_ACCESS (code=1, adress=0xfffffff6)", pointing to a non-specific line of assembly code.
First of all, if you guys have any ideas right off the bat as to what might be causing this, I would greatly appreciate some help. The thing is, I'm more than willing to debug this myself, but being a complete noob with Objective-C as well as XCode, I'm not sure how to trace this specific error back to the line of code that's causing it (I apologize if this is a really basic question but I've already attempted to find a command to get the line of code associated with the error, but with no success).
I realize that this is scant on details, but as I said, I'm not sure how to pinpoint the piece of code that's causing this error using XCode, otherwise I'd just debug this myself. If there's any extra information I can provide, let me know.
Thanks in advance for any help!
I got it working. After a lot of messing around with XCode, I realized that I incorrectly configured the project file provided by Wintermute. As far as I can tell, it had something to do with the fact that the project was originally set to build for "iOS Universal" and I changed it to "iPad 5.0," which somehow caused the project to break upon deployment.
Anyway, I started over with a new XCode project file and got it to compile perfectly! Sorry for the bother.
The problem is the fact that it isnt ment to run on iOS. The reason it runs on he simulator is that it is building for a Intel chip set, not ARM. Even though you set it to armv6 it doesn't mean that the code will run on a non-intel device.

XCode 4.2 on OSX 10.7.1 (Lion) Crashing/Locking Up all the time. Anyone Know how to fix?

This should not create any Issues with the NDA as I am not asking anyone to reveal any functionality of the application, I have asked on the Developer Forums, but They dont have the user base or the response speed of StackOverflow.
I have been working with XCode for a while now. And other then these issues, I REALLY LIKE the new xcode. I will (when these issues are resolved) recommend this application to all iOS/OSX developers.
Anyhow.
I am currently developing iOS applications. And am Running this setup on Mac OSX 10.7.1 (Lion)
Issue 1:
If I use the Interface builder it will first of all stay open even after I navigate away from it and it is no longer visible or to my knowledge "running". After a while it will consume more then 4 gigs of active memory. I will have the activity monitor open and Will eventually have less than 20megs left of free memory. I upgraded my MacMini to 8 Gigs of memory and at this point it will get down to about 200 Megs of memory left and will eventually release the memory that IB had held onto. If I do not open IB in XCode 4 it tends to use a lot less memory. (adding 8 gigs of memory makes this memory leak a lot less of a problem)
Issue 2: (MOST ANNOYING, HOPING FOR A FIX TO THIS ONE MOST)
This one only currently happens on one of the Three machines I code on. And what happens is while programming if I [Run] the app it will work for a while. Then at some point through the process it will begin to Lock Up when I press Run or Command-R. If I save the code file and run. It will not lock up. However if I forget to save, It will not only lock up. But will force me to terminate the XCode app, and Subsequently Recode everything that I had edited since the last save and the Application Run. This is by far the most annoying bug I have encountered this far.
Issue 3:
This bug happens more and more often the longer the application and operating system has been running. Running into the iPad will give me a number of Errors including "Unable to Connect to Debugger" or "Finished Successfully" among others. But the important part of this issue is that the application will never get sent to the iOS device. It will compile and say it finished. But there will be a error in the output pane.
I hope others have encountered these errors and Hopefully there is a quick fix with config files or something that will make development a lot more convenient. Thanks to anyone for resolution to any of these issues.....
EDIT
I finally received an email from apple support. I have emailed them off a Capture from XCode 4 and will hopefully hear something from them. Or maybe they will just release a new beta. Either way I hope to get this resolved asap.
For issue #2 you might want to try auto-saving your code before runs. See XCODE auto save code when build and run? instructions. Not sure if these instructions will work for 4.2 but you get the idea.
I had issues with my Xcode 4.2 install crashing initially. Re-running the installer over the already installed Xcode 4.2 fixed them. Obviously I don't know what the underlying issue with the install was, but although the first install reported installation was successful, obviously it wasn't. Perhaps worth trying.
When a newer version of Xcode 4.2 becomes available to you (cough), you might want to see whether installing that one fixes the problem. Perhaps given the issues, you should try uninstalling the previous version first rather than installing over the top?
Do you use multiple windows? They are anathema to Xcode 4. If you persist in your heresy, it may corrupt some files, and slow itself down. You will see a lot of beachballing, and it will be in some sort of GC.
You can work around this by deleting a workspace-specific file hidden inside your project. (I will have to look up which one, if this describes your case.)
With the new Beta GM Release they have seemingly fixed the issue with the Hanging.
Thanks for the Answers. Ill +1 anyone who helped but ultimately it was apple that fixed the issue.... For now

Resources