diff options
author | Fabian Guerra <fabian.guerra@mapbox.com> | 2018-02-13 14:43:53 -0500 |
---|---|---|
committer | Fabian Guerra <fabian.guerra@mapbox.com> | 2018-02-13 14:43:53 -0500 |
commit | 736fc8e4f870d44a7aba4d2d9ec1378d63228e53 (patch) | |
tree | fe697618f79ab761f926f947ae55a0a883d82db3 | |
parent | 3a0c87b1b4d4f2789a2ca5e995a79a7bad4f761f (diff) | |
download | qtlocation-mapboxgl-upstream/fabian-fix-memory-leak-11117.tar.gz |
[ios, macos] Fix a memory leak when creating an EAGLContext in MGLMapSnapshotter.upstream/fabian-fix-memory-leak-11117
-rw-r--r-- | platform/darwin/src/headless_backend_eagl.mm | 19 |
1 files 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<EAGLContext*>(glContext) retain]; - reinterpret_cast<EAGLContext*>(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<EAGLImpl>(); + } } // namespace mbgl |