Subversion Repository Public Repository

Divide-Framework

This repository has no backups
This repository's network speed is throttled to 100KB/sec

Diff Revisions 801 vs 806 for /trunk/Source Code/Platform/Video/OpenGL/SDLWindowWrapper.cpp

Diff revisions: vs.
  @@ -397,20 +397,25 @@
397 397 void GL_API::syncToThread(const std::thread::id& threadID) {
398 398 ACKNOWLEDGE_UNUSED(threadID);
399 399 if (glbinding::getCurrentContext() == 0) {
400 - // This also makes the context current
401 - assert(GLUtil::_glSecondaryContext == nullptr && "GL_API::syncToThread: double init context for current thread!");
402 - bool ctxFound = g_ContextPool.getAvailableContext(GLUtil::_glSecondaryContext);
403 - assert(ctxFound && "GL_API::syncToThread: context not found for current thread!");
404 - ACKNOWLEDGE_UNUSED(ctxFound);
405 - SDL_GL_MakeCurrent(_mainRenderWindow->getRawWindow(), GLUtil::_glSecondaryContext);
406 - glbinding::Binding::initialize(false);
407 - // Enable OpenGL debug callbacks for this context as well
408 - if (Config::ENABLE_GPU_VALIDATION) {
409 - glEnable(GL_DEBUG_OUTPUT);
410 - glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS);
411 - // Debug callback in a separate thread requires a flag to distinguish it
412 - // from the main thread's callbacks
413 - glDebugMessageCallback((GLDEBUGPROC)GLUtil::DebugCallback, GLUtil::_glSecondaryContext);
400 + // Double check so that we don't run into a race condition!
401 + UpgradableReadLock r_lock(GLUtil::_glSecondaryContextMutex);
402 + if (glbinding::getCurrentContext() == 0) {
403 + UpgradeToWriteLock w_lock(r_lock);
404 + // This also makes the context current
405 + assert(GLUtil::_glSecondaryContext == nullptr && "GL_API::syncToThread: double init context for current thread!");
406 + bool ctxFound = g_ContextPool.getAvailableContext(GLUtil::_glSecondaryContext);
407 + assert(ctxFound && "GL_API::syncToThread: context not found for current thread!");
408 + ACKNOWLEDGE_UNUSED(ctxFound);
409 + SDL_GL_MakeCurrent(_mainRenderWindow->getRawWindow(), GLUtil::_glSecondaryContext);
410 + glbinding::Binding::initialize(false);
411 + // Enable OpenGL debug callbacks for this context as well
412 + if (Config::ENABLE_GPU_VALIDATION) {
413 + glEnable(GL_DEBUG_OUTPUT);
414 + glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS);
415 + // Debug callback in a separate thread requires a flag to distinguish it
416 + // from the main thread's callbacks
417 + glDebugMessageCallback((GLDEBUGPROC)GLUtil::DebugCallback, GLUtil::_glSecondaryContext);
418 + }
414 419 }
415 420 }
416 421 }