diff --git a/src/SFML/Window/Context.cpp b/src/SFML/Window/Context.cpp index 1db2e33e1..d10c48c3d 100644 --- a/src/SFML/Window/Context.cpp +++ b/src/SFML/Window/Context.cpp @@ -32,7 +32,7 @@ namespace { - // This per-thread variable holds the current context for each thread + // This per-thread variable holds the last activated sf::Context for each thread sf::ThreadLocalPtr currentContext(NULL); } @@ -76,7 +76,11 @@ const ContextSettings& Context::getSettings() const //////////////////////////////////////////////////////////// const Context* Context::getActiveContext() { - return currentContext; + // We have to check that the last activated sf::Context is still active (a RenderTarget activation may have deactivated it) + if (currentContext && currentContext->m_context == priv::GlContext::getActiveContext()) + return currentContext; + else + return NULL; } diff --git a/src/SFML/Window/GlContext.cpp b/src/SFML/Window/GlContext.cpp index cb33c441c..62dad263c 100644 --- a/src/SFML/Window/GlContext.cpp +++ b/src/SFML/Window/GlContext.cpp @@ -549,6 +549,13 @@ GlFunctionPointer GlContext::getFunction(const char* name) } +//////////////////////////////////////////////////////////// +const GlContext* GlContext::getActiveContext() +{ + return currentContext; +} + + //////////////////////////////////////////////////////////// Uint64 GlContext::getActiveContextId() { diff --git a/src/SFML/Window/GlContext.hpp b/src/SFML/Window/GlContext.hpp index 816a68b4e..5ca8134f0 100644 --- a/src/SFML/Window/GlContext.hpp +++ b/src/SFML/Window/GlContext.hpp @@ -157,6 +157,14 @@ public: //////////////////////////////////////////////////////////// static GlFunctionPointer getFunction(const char* name); + //////////////////////////////////////////////////////////// + /// \brief Get the currently active context + /// + /// \return The currently active context or NULL if none is active + /// + //////////////////////////////////////////////////////////// + static const GlContext* getActiveContext(); + //////////////////////////////////////////////////////////// /// \brief Get the currently active context's ID ///