简体   繁体   English

iOS仅在未通过XCode运行时崩溃。 Concidence?

[英]iOS crash only when NOT running via XCode. Concidence?

My app was crashing only when not running using XCode debugger. 我的应用程序仅在未使用XCode调试器运行时崩溃。 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. 这是因为在某些不属于我的对象上调用release。 Before I corrected it I searched and found 2 related questions here (links below) 在我更正之前,我搜索并在此处找到了2个相关问题(链接如下)

iOS App Crashes when running by itself on device, does not crash when running through Xcode using debugger, or in simulator iOS应用程序在设备上单独运行时崩溃,在使用调试器运行Xcode时或在模拟器中不会崩溃

iPhone crash only when device not connected to xcode, how to understand the crash log? iPhone崩溃只在设备没有连接到xcode时,如何理解崩溃日志?

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. 它是偶然的,虽然它发生了10次以上。

What you describe is not atypical of obscure memory-related bugs. 你所描述的并不是不明显的与内存相关的错误。 You might also want to use debug-malloc at such times. 您可能还希望在此时使用debug-malloc。 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. 反过来也可能发生同样的情况,但你永远都不会知道 - 如果在运行debuggable时崩溃,你会在切换到在调试环境之外运行之前找到它。

Reiterating @jyoung's answer since I didn't see it the first time I glanced through: 重申@ jyoung的回答,因为我第一次看到它时没有看到它:

Try running with Zombie Objects turned off. 尝试关闭Zombie Objects运行。

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 issue when accessing SQLite databases from outside the [[NSBundle mainBundle] resourcePath] directory, which caused iCloud errors. 从[[NSBundle mainBundle] resourcePath]目录外部访问SQLite数据库时遇到此问题,导致iCloud错误。

I discovered the error only by installing a Console app onto my iPhone which logged the errors. 我发现错误只是在我的iPhone上安装了一个控制台应用程序,它记录了错误。

Once I accessed the databases from the correct directory, the errors disappeared and the application booted correctly. 从正确的目录访问数据库后,错误消失,应用程序正确启动。

I experienced this symptom when I made a NSString, sent a UTF8String from it to another object, and assigned it to a char pointer. 当我创建一个NSString,从它发送一个UTF8String到另一个对象,并将它分配给一个char指针时,我遇到了这种症状。 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. 好吧,事实证明我忘了保留原来的NSString,这无论如何都不重要,因为我也没有意识到UTF8String方法(可能是一个允许访问指针本身的对象)在自动释放中运行池。 That is, retaining the NSString itself did not fix the problem. 也就是说,保留NSString本身并没有解决问题。

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. 如果是这样,这是使用和不启用NSZombie进行测试的一个很好的理由。

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. 幸运的是,Organizer窗口中的控制台给了我一些关于从哪里开始查看的提示,并且调试最终显示了我的指针值的变化。 Hope this helps anyone who finds the way here. 希望这有助于任何在这里找到方向的人。

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. 为了澄清一下,我的应用程序在从XCode直接启动时没有任何问题,但在iPad上手动启动时会立即崩溃。

The app in question is written in Obj-C but relies on some 3rd party code written in Swift. 有问题的应用程序是用Obj-C编写的,但依赖于用Swift编写的一些第三方代码。 The Swift code is included in the app as an embedded framework. Swift代码作为嵌入式框架包含在应用程序中。 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. 我必须在应用程序的构建设置中将“嵌入式内容包含Swift代码”设置为“是”(在“构建选项”下),然后问题就消失了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在iOS应用程序中使用GCMathParser? Xcode。 - Use GCMathParser in iOS application? Xcode. UILabel导致应用程序在添加到视图时崩溃(仅限Xcode 6和iOS 8) - UILabel causes app to crash when added to view (Xcode 6 and iOS 8 only) 备用NSUserDedaults。 Xcode。 的iOS - Alternative NSUserDedaults. Xcode. iOS 最新的 Xcode 中缺少 iOS 14.7 模拟器。 如何获得? - iOS 14.7 Simulator is missing in latest Xcode. How to get it? XCode中。 如何自动构建和“上传到App Store”的iOS项目 - XCode. How to automatically build and “Upload to App Store” iOS project 在ios7 xcode中设置相机焦点。 OpenCV的 - Setting the cameras focus in ios7 xcode. opencv iOS:配置SVN时Xcode崩溃 - iOS : Xcode Crash when configure SVN 使用一个版本的Xcode构建iOS时发生崩溃,而使用另一版本的Xcode则没有崩溃 - iOS crash when built with one version of Xcode, no crash with another version Swift和Xcode。 添加到TabBarController时,所有UIViewControllers都变为黑色 - Swift and Xcode. All UIViewControllers become black when added to TabBarController iOS-仅在直接在模拟器上运行,但在调试或通过Xcode运行时,应用程序才能正常运行 - iOS - Application crashes only when running directly on simulator but working fine while debugging or running through Xcode
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM