问题
trying to give the user the option to choose between google maps (sdk) and apple maps (mapkit) in my app. the app is not using ARC. crash scenario (ios 6.0 / 6.1): 1. enter google maps (modal controller). 2. exit google maps (dismiss modal). 3. change in my app to apple maps (mapkit). 4. enter apple maps (modal controller).
the app crashes and i get: [EAGLContext setCurrentContext:]
the error won't occur if i don't release google maps in the dealloc, but it's probably will cause a memory leak. i retain the map in viewDidLoad and release the map in the dealloc.
can anyone help? thanks, Tomer
more detailed stack trace:
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:] ()
回答1:
Both the Google Maps SDK for iOS and MapKit using Apple Maps make use of OpenGL.
The Google Maps SDK for iOS has some issues which can cause it to crash if an unexpected OpenGL context is active:
http://code.google.com/p/gmaps-api-issues/issues/detail?id=4752
It seems that MapKit also has some issues with the OpenGL context:
iOS 6 app crashes in EAGLContext when displaying maps
You will probably have to use a bit of trial-and-error to see if you can figure out a way to stop the problem. Try clearing the current context before and/or after you perform operations on a map (such as when you release the Google Map):
[EAGLContext setCurrentContext:nil]
You can also try saving the previous context before performing an operation, and then restoring it again afterwards, for example:
EAGLContext* previousContext = [EAGLContext currentContext];
// Perform map operation here.
[EAGLContext setCurrentContext: previousContext];
When I was investigating the issues with the Google Maps SDK for iOS, I basically tried various combinations of these until I found something which worked. Good luck!
回答2:
I had the same issue with trying to switch between Apple and Google maps. After much experimentation, I too tracked it down to the interaction of releasing the Google map and crashing in MapKit. No usage of the [EAGLContext setCurrentContext:nil] call around other calls or after releasing the Google map as suggested would help. But, in my case, it always redrew the full Apple map, with annotations and overlays, and then crashed within the same [EAGLContext setCurrentContext:] call.
Based on that knowledge, I was able to solve my problem (or so it seems) by adding the [EAGLContext setCurrentContext:nil] call within the MapKit protocol method mapViewDidFinishLoadingMap.
- (void)mapViewDidFinishLoadingMap:(MKMapView *)mapView
{
[EAGLContext setCurrentContext:nil];
}
I am now able to happily switch back and forth.
Oh, and I am not using ARC on this project.
回答3:
This could be related to not using ARC. In the getting started section they always mention to ensure that use ARC is on.
回答4:
This appears to have been fixed in Google Maps iOS API 1.3.0, so there's no need to set the EAGLContext to nil.
来源:https://stackoverflow.com/questions/15052952/google-maps-sdk-mapkit-in-the-same-app-cause-crash