Skip to content

Commit

Permalink
Fixed crash on AMD hardware due to a race condition inside the driver. (
Browse files Browse the repository at this point in the history
  • Loading branch information
binary1248 committed Feb 19, 2015
1 parent bcd63c8 commit 64d28db
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/SFML/Window/GlContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@

namespace
{
// AMD drivers have issues with internal synchronization
// We need to make sure that no operating system context
// or pixel format operations are performed simultaneously
sf::Mutex mutex;

// This per-thread variable holds the current context for each thread
sf::ThreadLocalPtr<sf::priv::GlContext> currentContext(NULL);

Expand Down Expand Up @@ -153,6 +158,8 @@ namespace priv
////////////////////////////////////////////////////////////
void GlContext::globalInit()
{
Lock lock(mutex);

// Create the shared context
sharedContext = new ContextType(NULL);
sharedContext->initialize();
Expand All @@ -167,6 +174,8 @@ void GlContext::globalInit()
////////////////////////////////////////////////////////////
void GlContext::globalCleanup()
{
Lock lock(mutex);

// Destroy the shared context
delete sharedContext;
sharedContext = NULL;
Expand All @@ -191,9 +200,10 @@ void GlContext::ensureContext()
////////////////////////////////////////////////////////////
GlContext* GlContext::create()
{
Lock lock(mutex);

GlContext* context = new ContextType(sharedContext, ContextSettings(0, 0, 0, 2, 1, sharedContext->getSettings().attributeFlags & ~sf::ContextSettings::Core), 1, 1);
context->initialize();

return context;
}

Expand All @@ -204,6 +214,8 @@ GlContext* GlContext::create(const ContextSettings& settings, const WindowImpl*
// Make sure that there's an active context (context creation may need extensions, and thus a valid context)
ensureContext();

Lock lock(mutex);

// Check if we need to re-create the shared context with debugging enabled
if ((settings.attributeFlags & ContextSettings::Debug) && !(sharedContext->getSettings().attributeFlags & ContextSettings::Debug))
{
Expand Down Expand Up @@ -239,6 +251,8 @@ GlContext* GlContext::create(const ContextSettings& settings, unsigned int width
// Make sure that there's an active context (context creation may need extensions, and thus a valid context)
ensureContext();

Lock lock(mutex);

// Check if we need to re-create the shared context with debugging enabled
if ((settings.attributeFlags & ContextSettings::Debug) && !(sharedContext->getSettings().attributeFlags && ContextSettings::Debug))
{
Expand Down Expand Up @@ -273,6 +287,8 @@ void* GlContext::getFunction(const char* name)
{
#if !defined(SFML_OPENGL_ES)

Lock lock(mutex);

return ContextType::getFunction(name);

#else
Expand Down Expand Up @@ -306,6 +322,8 @@ bool GlContext::setActive(bool active)
{
if (this != currentContext)
{
Lock lock(mutex);

// Activate the context
if (makeCurrent())
{
Expand Down

0 comments on commit 64d28db

Please sign in to comment.