Browse Source

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.
pull/332/head
Max Schwarz 7 years ago committed by Vladimír Vondruš
parent
commit
c38319ef00
  1. 7
      src/Magnum/GL/Context.cpp
  2. 3
      src/Magnum/GL/Context.h

7
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()) {

3
src/Magnum/GL/Context.h

@ -33,6 +33,7 @@
#include <vector>
#include <Corrade/Containers/EnumSet.h>
#include <Corrade/Containers/Optional.h>
#include <Corrade/Containers/Pointer.h>
#include <Corrade/Containers/StaticArray.h>
#include "Magnum/Magnum.h"
@ -708,7 +709,7 @@ class MAGNUM_GL_EXPORT Context {
Math::BoolVector<Implementation::ExtensionCount> _extensionStatus;
std::vector<Extension> _supportedExtensions;
Implementation::State* _state;
Containers::Pointer<Implementation::State> _state;
Containers::Optional<DetectedDrivers> _detectedDrivers;

Loading…
Cancel
Save