Google Maps SDK& Mapkit在同一个应用程序中导致崩溃

时间:2013-02-24 14:56:39

标签: ios mapkit google-maps-sdk-ios

尝试让用户在我的应用中选择谷歌地图(sdk)和苹果地图(mapkit)。 该应用程序没有使用ARC。 崩溃场景(ios 6.0 / 6.1): 1.进入谷歌地图(模态控制器)。 2.退出谷歌地图(解雇模态)。 3.将我的应用程序更改为apple maps(mapkit)。 4.输入apple maps(模态控制器)。

应用程序崩溃,我得到:     [EAGLContext setCurrentContext:]

如果我不在dealloc中释放谷歌地图,则不会发生错误,但它可能会导致内存泄漏。 我在viewDidLoad中保留地图并在dealloc中释放地图。

任何人都可以帮忙吗? 谢谢, Tomer的

更详细的堆栈跟踪:

1   0x0a041324 in -[VGLGPU init] ()
2   0x0a041032 in __24+[VGLGPU sharedInstance]_block_invoke_0 ()
3   0x03b52014 in _dispatch_client_callout ()
4   0x03b4409f in dispatch_once_f ()
5   0x03b44061 in dispatch_once ()
6   0x0a040fef in +[VGLGPU sharedInstance] ()
7   0x09fab26b in -[VKMainLoop updateLinkState] ()
8   0x09fabb02 in -[VKMainLoop removeCanvas:] ()
9   0x09f9f2aa in -[VKScreenCanvas _updateDisplayStatus:] ()
10  0x09f9f3fb in -[VKScreenCanvas setNeedsDisplay] ()
11  0x027bc03d in -[UIView initWithFrame:] ()
12  0x09f75658 in -[VGLScreenCanvas initWithFrame:context:] ()
15  0x09f907e7 in -[VKMapCanvas initWithFrame:shouldRasterize:] ()
16  0x09f8982e in -[VKMapView initWithFrame:andGlobe:shouldRasterize:] ()
17  0x0267d1a1 in -[MKMapView _commonInitAndEnableLoading:fromIB:] ()
18  0x0267da9c in -[MKMapView initWithCoder:] ()
19  0x02aa8a02 in UINibDecoderDecodeObjectForValue ()
47  0x028671a7 in -[UIViewController presentModalViewController:animated:] ()

4 个答案:

答案 0 :(得分:7)

适用于iOS的Google Maps SDK和使用Apple Maps的MapKit均可使用OpenGL。

Google Maps SDK for iOS存在一些问题,如果意外的OpenGL上下文处于活动状态,可能会导致其崩溃:

http://code.google.com/p/gmaps-api-issues/issues/detail?id=4752

MapKit似乎也存在OpenGL上下文的一些问题:

iOS 6 app crashes in EAGLContext when displaying maps

您可能需要使用一些反复试验才能确定是否可以找到解决问题的方法。尝试在地图上执行操作之前和/或之后清除当前上下文(例如,当您发布Google地图时):

[EAGLContext setCurrentContext:nil]

您还可以在执行操作之前尝试保存上一个上下文,然后再重新恢复,例如:

EAGLContext* previousContext = [EAGLContext currentContext];

// Perform map operation here.

[EAGLContext setCurrentContext: previousContext];

当我使用Google Maps SDK for iOS调查问题时,我基本上尝试了各种组合,直到找到了有效的方法。祝你好运!

答案 1 :(得分:4)

尝试在Apple和Google地图之间切换时遇到了同样的问题。经过多次实验,我也将其跟踪到发布Google地图和在MapKit中崩溃的相互作用。不使用[EAGLContext setCurrentContext:nil]调用其他调用或在发布谷歌地图后建议会有所帮助。但是,在我的情况下,它总是重新绘制完整的Apple地图,带有注释和叠加,然后在相同的[EAGLContext setCurrentContext:]调用中崩溃。

基于这些知识,我能够通过在MapKit协议方法mapViewDidFinishLoadingMap中添加[EAGLContext setCurrentContext:nil]调用来解决我的问题(或者看起来似乎如此)。

- (void)mapViewDidFinishLoadingMap:(MKMapView *)mapView
{
    [EAGLContext setCurrentContext:nil];
}

我现在能够快乐地来回切换。

哦,我在这个项目上没有使用ARC。

答案 2 :(得分:0)

这可能与不使用ARC有关。在入门部分,他们总是提到确保使用ARC。

答案 3 :(得分:0)

这似乎已在Google Maps iOS API 1.3.0中修复,因此无需将EAGLContext设置为nil。