Fix sf::Context::getActiveContext to stop returning inactive contexts

sf::Context::getActiveContext could return an inactive context if
RenderTargets activation occured since the last sf::Context activation.
This is not what its documentation suggest, and was clearly an
unexpected behaviour.

This fix make the function return NULL if the current active context is
not managed by sf::Context (e.g. because it is a RenderTarget).
This commit is contained in:
Guillaume Bertholon 2021-04-14 12:34:34 +02:00 committed by Lukas Dürrenberger
parent ce992ee01f
commit f3a180bc09
3 changed files with 21 additions and 2 deletions

View File

@ -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<sf::Context> 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;
}

View File

@ -549,6 +549,13 @@ GlFunctionPointer GlContext::getFunction(const char* name)
}
////////////////////////////////////////////////////////////
const GlContext* GlContext::getActiveContext()
{
return currentContext;
}
////////////////////////////////////////////////////////////
Uint64 GlContext::getActiveContextId()
{

View File

@ -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
///