xcode 将谷歌地图添加为子视图会导致 iOS 应用程序崩溃并使用 exc_bad
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31264537/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Adding google maps as subview crashes iOS app with exc_bad
提问by Yoav Schwartz
I have code that worked perfectly fine until around 3 days ago. I have tried going back to a much older commit that worked a 100% and still now it crashes with exc_bad. The crash only happens when running the app on the device, If I run the app on the simulator or use instruments to run the app on the device it runs perfectly fine. When I changed my google api key, it said "You might not have permission to use this api key" but no longer crashed.
直到大约 3 天前,我的代码都运行良好。我试过回到一个 100% 工作的更旧的提交,但现在它仍然因 exc_bad 崩溃。只有在设备上运行应用程序时才会发生崩溃,如果我在模拟器上运行应用程序或使用仪器在设备上运行应用程序,它运行得非常好。当我更改我的 google api 密钥时,它说“您可能没有使用此 api 密钥的权限”但不再崩溃。
The app only crashes when running the app on the device via xcode. When later running the same version on the device without being connected to xcode it works fine.
该应用程序仅在通过 xcode 在设备上运行该应用程序时崩溃。当稍后在设备上运行相同版本而不连接到 xcode 时,它工作正常。
I am not sure what information I can add here to help debug the problem. I have recently updated xcode to 6.4 and updated the OSX with the latest update.
我不确定我可以在此处添加哪些信息来帮助调试问题。我最近将 xcode 更新到 6.4,并使用最新更新更新了 OSX。
I am using google 1.10.1 sdk version, installed using CocoaPods
我使用的是 google 1.10.1 sdk 版本,使用 CocoaPods 安装
The code I use to add the map:
我用来添加地图的代码:
self.mapView = [GMSMapView mapWithFrame:self.view.bounds camera:camera];
self.mapView.myLocationEnabled = YES;
self.mapView.settings.myLocationButton = YES;
self.mapView.delegate = self;
[self.mapView addObserver:self
forKeyPath:@"myLocation"
options:NSKeyValueObservingOptionNew
context:NULL];
[self.view insertSubview:self.mapView atIndex:1];
The error itself varies between code=1, code=2, and code=257. I have tried adding the GMSMapView with storyboard instead of code. I have tried installing an older version of xcode and running again but it doesn't change anything.
错误本身在代码=1、代码=2 和代码=257 之间变化。我尝试使用故事板而不是代码添加 GMSMapView。我试过安装旧版本的 xcode 并再次运行,但它没有改变任何东西。
If I comment out the insert subview line, that app doesn't crash. I have tried running the zombie instrument tool but when I run using instruments the app works fine.
如果我注释掉插入子视图行,该应用程序不会崩溃。我试过运行僵尸仪器工具,但是当我使用仪器运行时,应用程序运行良好。
#0 0x0000000100c5dc34 in EAGLContext_renderbufferStorageFromDrawable(EAGLContext*, objc_selector*, unsigned long, id<EAGLDrawable>) ()
#1 0x00000001002404c0 in gmscore::renderer::ios::GLRenderTarget::CreateFramebuffer() ()
#2 0x00000001002403cc in gmscore::renderer::ios::GLRenderTarget::FrameStart() ()
#3 0x00000001002e7af4 in gmscore::renderer::EntityRenderer::Draw(bool) ()
#4 0x00000001002516f4 in -[GMSPhoenixRenderer drawIfNeeded] ()
#5 0x00000001002329a0 in -[GMSEntityRendererView draw] ()
#6 0x000000010028dc74 in -[GMSDisplayLink displayLinkFired:] ()
#7 0x0000000100c5ca9c in -[DYDisplayLinkInterposer forwardDisplayLinkCallback:] ()
#8 0x00000001887f629c in CA::Display::DisplayLinkItem::dispatch() ()
#9 0x00000001887f6134 in CA::Display::DisplayLink::dispatch_items(unsigned long long, unsigned long long, unsigned long long) ()
#10 0x00000001855d1470 in IODispatchCalloutFromCFMessage ()
#11 0x00000001843c2dc4 in __CFMachPortPerform ()
#12 0x00000001843d7a54 in __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ ()
#13 0x00000001843d79b4 in __CFRunLoopDoSource1 ()
#14 0x00000001843d5934 in __CFRunLoopRun ()
#15 0x00000001843012d4 in CFRunLoopRunSpecific ()
#16 0x000000018db1f6fc in GSEventRunModal ()
#17 0x0000000188ec6fac in UIApplicationMain ()
#18 0x000000010002d794 in main at /Users/yoavschwartz/Documents/donkey_republic_ios/DonkeyRepublic/DonkeyRepublic/main.m:14
#19 0x0000000196272a08 in start ()
This problem seemed to have solved itself when restarting computer/device and now popped again. I really don't understand what's going on.
重新启动计算机/设备时,此问题似乎已自行解决,现在又出现了。我真的不明白这是怎么回事。
回答by Dave Cole
EDIT:I've found the root of the problem and have a workaround:
编辑:我找到了问题的根源并有一个解决方法:
The problem seems to be triggered by OpenGL ES Frame Capture in XCode; I'm guessing this problem started when Apple added Metal to the mix as of XCode 6.4/iOS 8.3, perhaps somehow adversely affecting the entire frame capture debugging system.
该问题似乎是由 XCode 中的 OpenGL ES Frame Capture 触发的;我猜这个问题是在 Apple 将 Metal 添加到 XCode 6.4/iOS 8.3 的组合中时开始的,这可能会以某种方式对整个帧捕获调试系统产生不利影响。
The workaround:
解决方法:
- In XCode, go to Product > Scheme > Edit Scheme...
- Select the "Run" Tab on the left.
- Select the "Options" sub-tab on the top.
- Change "GPU Frame Capture" from "Automatically Enabled" or "OpenGL ES" to either "Metal" or "Disabled".
- 在 XCode 中,转到产品 > 方案 > 编辑方案...
- 选择左侧的“运行”选项卡。
- 选择顶部的“选项”子选项卡。
- 将“GPU Frame Capture”从“Automatically Enabled”或“OpenGL ES”更改为“Metal”或“Disabled”。
This disables OpenGL ES frame capture, which isn't great, but allows you to continue debugging your builds.
这会禁用 OpenGL ES 帧捕获,这不是很好,但允许您继续调试您的构建。
Not sure if this issue is Apple's or Google's but I'll be posting bug reports to both. Happy coding!
不确定这个问题是苹果的还是谷歌的,但我会向两者发布错误报告。快乐编码!
--
——
earlier post:
之前的帖子:
Some further info (would make this a comment but don't have the rep quite yet) as I'm experiencing this too; as best I can tell:
一些进一步的信息(将使其成为评论,但还没有代表),因为我也遇到了这种情况;尽我所能:
- The issue is apparent in XCode 6.4 as well as XCode 7 beta 3
- It presents itself in debug mode only, not running outside XCode.
- It doesn't manifest on iOS 8.1.2 but it does on iOS 8.3.
- It happens with both Google Maps 1.9.X (imported as a Framework file) as well as 1.10.X (imported as a CocoaPod, including the latest)
- I can't verify this completely yet but it hasn't shown up in XCode 6.3.2 for me; this might be because I can't compile for 8.3 in that version.
- 该问题在 XCode 6.4 和 XCode 7 beta 3 中很明显
- 它仅以调试模式显示自己,不在 XCode 之外运行。
- 它不会出现在 iOS 8.1.2 上,但会出现在 iOS 8.3 上。
- Google Maps 1.9.X(作为框架文件导入)和 1.10.X(作为 CocoaPod 导入,包括最新版本)都会发生这种情况
- 我还不能完全验证这一点,但它没有出现在我的 XCode 6.3.2 中;这可能是因为我无法在该版本中为 8.3 编译。
I'll likely miss the deadline for the swag bounty but I'm spending all day tomorrow digging deeper and will report back.
我可能会错过赃物赏金的最后期限,但我明天一整天都在挖掘更深的东西,并会回来报告。
回答by Julian E.
This happened to mee too when I was using the Google Maps SDK. I filed a bug report as after restarting Xcode and deleting the project and reinstalling it, it worked perfectly fine.
当我使用 Google Maps SDK 时,这也发生在我身上。我提交了一个错误报告,因为在重新启动 Xcode 并删除项目并重新安装它之后,它工作得很好。
This is not your problem, but simply a bug. If you install the build through test flight or the App Store it will work like a charm.
这不是你的问题,而只是一个错误。如果您通过试飞或 App Store 安装构建版本,它将像魅力一样工作。
For debugging, just keep restarting Xcode and if possible try to run it through Xcode 7. There's a chance they fixed this bug.
对于调试,只需继续重新启动 Xcode,如果可能,请尝试通过 Xcode 7 运行它。他们有机会修复此错误。
Hope that helps, Julian
希望有帮助,朱利安
回答by MarineHero
Yoav Schwartz, have you tried assigning the mapView.delegate only after insertSubview of the mapView into your view hierarchy?
Yoav Schwartz,您是否尝试过仅在 mapView 的 insertSubview 到您的视图层次结构之后才分配 mapView.delegate?
I am experiencing something similar and I suspect it to be a bug with Xcode 6.4 as Julian alludes to above.
我遇到了类似的事情,我怀疑这是 Xcode 6.4 的一个错误,正如朱利安在上面提到的那样。
James Pereira/@marinehero
詹姆斯佩雷拉/@marinehero