From c38319ef0001d986c8210b9f5996ab1bf7029534 Mon Sep 17 00:00:00 2001 From: Max Schwarz Date: Thu, 4 Apr 2019 12:28:25 +0200 Subject: [PATCH] GL: Use Corrade::Containers::Pointer for Context _state The old raw pointer could cause a segfault if the context is never created, since the destructor unconditionally deleted _state. --- src/Magnum/GL/Context.cpp | 7 ++----- src/Magnum/GL/Context.h | 3 ++- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/Magnum/GL/Context.cpp b/src/Magnum/GL/Context.cpp index 4a653030f..4bd9ae3b9 100644 --- a/src/Magnum/GL/Context.cpp +++ b/src/Magnum/GL/Context.cpp @@ -495,20 +495,17 @@ Context::Context(Context&& other): _version{other._version}, _extensionRequiredVersion{Containers::NoInit}, _extensionStatus{other._extensionStatus}, _supportedExtensions{std::move(other._supportedExtensions)}, - _state{other._state}, + _state{std::move(other._state)}, _detectedDrivers{std::move(other._detectedDrivers)} { /* StaticArray is deliberately non-copyable */ for(std::size_t i = 0; i != Implementation::ExtensionCount; ++i) _extensionRequiredVersion[i] = other._extensionRequiredVersion[i]; - other._state = nullptr; if(currentContext == &other) currentContext = this; } Context::~Context() { - delete _state; - if(currentContext == this) currentContext = nullptr; } @@ -731,7 +728,7 @@ bool Context::tryCreate() { } } - _state = new Implementation::State{*this, output}; + _state.emplace(*this, output); /* Print a list of used workarounds */ if(!_driverWorkarounds.empty()) { diff --git a/src/Magnum/GL/Context.h b/src/Magnum/GL/Context.h index 4f0a9ae8e..206673e1c 100644 --- a/src/Magnum/GL/Context.h +++ b/src/Magnum/GL/Context.h @@ -33,6 +33,7 @@ #include #include #include +#include #include #include "Magnum/Magnum.h" @@ -708,7 +709,7 @@ class MAGNUM_GL_EXPORT Context { Math::BoolVector _extensionStatus; std::vector _supportedExtensions; - Implementation::State* _state; + Containers::Pointer _state; Containers::Optional _detectedDrivers;