GlennChiu / GC3DFlipTransitionStyleSegue

iBooks-style 3D flip transition animation rendered in OpenGL ES 2.0 and wrapped in a UIStoryboardSegue subclass
512 stars 65 forks source link

Crash with MapKit #5

Closed MSch closed 11 years ago

MSch commented 11 years ago

If the destinationViewController has a MKMapView on it the App crashes both on the simulator and device.

Here's an example, just press run it and press the button: https://github.com/MSch/GC3DFlipBug

GlennChiu commented 11 years ago

Ok that's strange. Will take a look at that.

MSch commented 11 years ago

Thanks! I tried looking into it but I know zero OpenGL. All I figured out was that it seems it's enough to have show the GLKView to trigger the crash. :/

GlennChiu commented 11 years ago

Your example was of great help. Thanks for that.

So this issue is an iOS 6 MKMapView issue. It also renders its view in OpenGL and seems to hold a reference to the current EAGLContext of this class (which we can assume is a bug...).

So nullifying the EAGLContext of GLKView seems to do the trick. Replace the -teardownGL method with this code:

- (void)tearDownGL
{
    [EAGLContext setCurrentContext:self->_context];

    glDeleteBuffers(1, &self->_vertexBuffer);
    glDeleteVertexArraysOES(1, &self->_vertexArray);

    GLKView *view = (GLKView *)self.view;
    view.context = nil;

    [EAGLContext setCurrentContext:nil];

    self->_context = nil;
    self->_effect = nil;
    self->_snapshotSource = nil;
}

Please let me know if it worked.

MSch commented 11 years ago

Yep that worked! Thanks a million!

So I'm guessing this means view.context = nil stops the GLKView from tearing down its EAGLContext so that MapKit can continue to use it?

GlennChiu commented 11 years ago

I think that MKMapView used a GLKView with a reference to the EAGLContext of this class, while it actually should have used its own EAGLContext (a class can't share a EAGLContext unless it is explicit set to be shared).

I'm still not sure whether it's a bug inside MKMapView or this is always happens with multiple instances of GLKView.