[ios, macos] Refcount view activations (#7208)
This adds a ref count to guard against calling activate after it has already been called. This can happen when a layer is added during certain map lifecycle methods like MapChangeWillStartRenderingFrame that also triggers activation. This also protects against issues related to a deactivation of the context happening in an inner scope while an outer scope is still expecting to be able to use the context.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user