Return nullptr when sf::Context::getFunction is called on Windows without an active context

This converts termination in Debug and a SEGFAULT in Release builds
into defined behavior.
This commit is contained in:
Chris Thrasher 2024-04-02 18:09:10 -06:00
parent 49cf5058e5
commit d00ab43ea6
2 changed files with 5 additions and 2 deletions

View File

@ -131,6 +131,9 @@ public:
////////////////////////////////////////////////////////////
/// \brief Get the address of an OpenGL function
///
/// On Windows when not using OpenGL ES, a context must be
/// active for this function to succeed.
///
/// \param name Name of the function to get the address of
///
/// \return Address of the OpenGL function, 0 on failure

View File

@ -203,8 +203,8 @@ WglContext::~WglContext()
////////////////////////////////////////////////////////////
GlFunctionPointer WglContext::getFunction(const char* name)
{
assert(WglContextImpl::currentContext != nullptr &&
"Current WGL context cannot be null. Call WglContext::makeCurrent() to initialize it.");
if (WglContextImpl::currentContext == nullptr)
return nullptr;
// If we are using the generic GDI implementation, skip to loading directly from OpenGL32.dll since it doesn't support extensions
if (!WglContextImpl::currentContext->m_isGeneric)