diff --git a/src/Magnum/Audio/Context.cpp b/src/Magnum/Audio/Context.cpp index 6df502584..b6f9dcd89 100644 --- a/src/Magnum/Audio/Context.cpp +++ b/src/Magnum/Audio/Context.cpp @@ -104,8 +104,6 @@ const char* alcErrorString(const ALenum error) { } -Context* Context::_current = nullptr; - std::vector Context::deviceSpecifierStrings() { std::vector list; const char* const devices = alcGetString(nullptr, ALC_DEVICE_SPECIFIER); @@ -115,11 +113,17 @@ std::vector Context::deviceSpecifierStrings() { return list; } -bool Context::hasCurrent() { return _current; } +namespace { + /* Unlike GL, this isn't thread-local. Would need to implement + ALC_EXT_thread_local_context first */ + Context* currentContext = nullptr; +} + +bool Context::hasCurrent() { return currentContext; } Context& Context::current() { - CORRADE_ASSERT(_current, "Audio::Context::current(): no current context", *_current); - return *_current; + CORRADE_ASSERT(currentContext, "Audio::Context::current(): no current context", *currentContext); + return *currentContext; } Context::Context(Int argc, const char** argv): Context(Configuration{}, argc, argv) {} @@ -145,7 +149,7 @@ void Context::create(const Configuration& configuration) { } bool Context::tryCreate(const Configuration& configuration) { - CORRADE_ASSERT(!_current, "Audio::Context: context already created", false); + CORRADE_ASSERT(!currentContext, "Audio::Context: context already created", false); /* Open the device */ const ALCchar* const deviceSpecifier = configuration.deviceSpecifier().empty() ? alcGetString(nullptr, ALC_DEFAULT_DEVICE_SPECIFIER) : configuration.deviceSpecifier().data(); @@ -204,7 +208,7 @@ bool Context::tryCreate(const Configuration& configuration) { } alcMakeContextCurrent(_context); - _current = this; + currentContext = this; /* Add all extensions to a map for faster lookup */ std::unordered_map extensionMap; @@ -262,13 +266,13 @@ bool Context::tryCreate(const Configuration& configuration) { Context::Context(Context&& other) noexcept: _device{other._device}, _context{other._context}, _extensionStatus{std::move(other._extensionStatus)}, _supportedExtensions{std::move(other._supportedExtensions)} { other._device = nullptr; other._context = nullptr; - if(_current == &other) _current = this; + if(currentContext == &other) currentContext = this; } Context::~Context() { if(_context) alcDestroyContext(_context); if(_device) alcCloseDevice(_device); - if(_current == this) _current = nullptr; + if(currentContext == this) currentContext = nullptr; } std::vector Context::extensionStrings() const { diff --git a/src/Magnum/Audio/Context.h b/src/Magnum/Audio/Context.h index 075a3a8a0..d5badbe2f 100644 --- a/src/Magnum/Audio/Context.h +++ b/src/Magnum/Audio/Context.h @@ -407,8 +407,6 @@ class MAGNUM_AUDIO_EXPORT Context { } private: - MAGNUM_AUDIO_LOCAL static Context* _current; - bool _displayInitializationLog; ALCdevice* _device;