diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm index b1ecf1c41..e36f0299e 100644 --- a/platform/ios/src/MGLMapView.mm +++ b/platform/ios/src/MGLMapView.mm @@ -5093,16 +5093,28 @@ public: void activate() override { + if (activationCount++) + { + return; + } + [EAGLContext setCurrentContext:nativeView.context]; } void deactivate() override { + if (--activationCount) + { + return; + } + [EAGLContext setCurrentContext:nil]; } private: __weak MGLMapView *nativeView = nullptr; + + NSUInteger activationCount = 0; }; @end diff --git a/platform/macos/src/MGLMapView.mm b/platform/macos/src/MGLMapView.mm index 50b77bc81..ba0704826 100644 --- a/platform/macos/src/MGLMapView.mm +++ b/platform/macos/src/MGLMapView.mm @@ -2611,11 +2611,19 @@ public: } void activate() override { + if (activationCount++) { + return; + } + MGLOpenGLLayer *layer = (MGLOpenGLLayer *)nativeView.layer; [layer.openGLContext makeCurrentContext]; } void deactivate() override { + if (--activationCount) { + return; + } + [NSOpenGLContext clearCurrentContext]; } @@ -2661,6 +2669,9 @@ private: /// The current framebuffer of the NSOpenGLLayer we are painting to. GLint fbo = 0; + + /// The reference counted count of activation calls + NSUInteger activationCount = 0; }; @end