From 6d2cbb0a403b9faada81a756afa111e35618500b Mon Sep 17 00:00:00 2001 From: Fabian Guerra Soto Date: Tue, 27 Feb 2018 12:04:20 -0500 Subject: [ios, macos] Fix a memory leak when creating an EAGLContext in MGLMapSnapshotter. (#11193) --- platform/darwin/src/headless_backend_eagl.mm | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/platform/darwin/src/headless_backend_eagl.mm b/platform/darwin/src/headless_backend_eagl.mm index 1daaeaf54c..f291c0805a 100644 --- a/platform/darwin/src/headless_backend_eagl.mm +++ b/platform/darwin/src/headless_backend_eagl.mm @@ -7,9 +7,13 @@ namespace mbgl { struct EAGLImpl : public HeadlessBackend::Impl { - EAGLImpl(EAGLContext* glContext_) : glContext(glContext_) { - [reinterpret_cast(glContext) retain]; - reinterpret_cast(glContext).multiThreaded = YES; + EAGLImpl() { + glContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2]; + + if (glContext == nil) { + throw std::runtime_error("Error creating GL context object"); + } + glContext.multiThreaded = YES; } ~EAGLImpl() { @@ -45,12 +49,9 @@ bool HeadlessBackend::hasDisplay() { } void HeadlessBackend::createContext() { - EAGLContext* glContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2]; - if (glContext == nil) { - throw std::runtime_error("Error creating GL context object"); - } - - impl.reset(new EAGLImpl(glContext)); + impl.reset(); + impl = std::make_unique(); + } } // namespace mbgl -- cgit v1.2.1