summaryrefslogtreecommitdiffstats
path: root/ui/gl
diff options
context:
space:
mode:
authorccameron@chromium.org <ccameron@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-04-08 21:36:44 +0000
committerccameron@chromium.org <ccameron@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-04-08 21:36:44 +0000
commite147f06074d429085a71e089a04363d19471ecf2 (patch)
tree14436959eb09194dda8f5e59f844ca4bff4c5711 /ui/gl
parentf5f704af64fcbbf5700fc5a69f92267dbafde8fa (diff)
downloadchromium_src-e147f06074d429085a71e089a04363d19471ecf2.zip
chromium_src-e147f06074d429085a71e089a04363d19471ecf2.tar.gz
chromium_src-e147f06074d429085a71e089a04363d19471ecf2.tar.bz2
Do not retain zombie CGL contexts
There are reports of failures when releasing the previous_context_ in ScopedCGLSetCurrentContext's destructor. The exact reason is unknown, but test applications have shown that it is possible for the current context to have a reference count of zero (in which case, the retain before setting the new context current does nothing, and the release after the new context is not current anymore may crash). If the previous context has a zero reference count, do not retain and release it, rather, set the context to NULL after the call completes. BUG=358473 Review URL: https://codereview.chromium.org/224723021 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@262510 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/gl')
-rw-r--r--ui/gl/scoped_cgl.cc10
1 files changed, 8 insertions, 2 deletions
diff --git a/ui/gl/scoped_cgl.cc b/ui/gl/scoped_cgl.cc
index 9fef385..18eb980 100644
--- a/ui/gl/scoped_cgl.cc
+++ b/ui/gl/scoped_cgl.cc
@@ -7,8 +7,14 @@
namespace gfx {
-ScopedCGLSetCurrentContext::ScopedCGLSetCurrentContext(CGLContextObj context)
- : previous_context_(CGLGetCurrentContext(), base::scoped_policy::RETAIN) {
+ScopedCGLSetCurrentContext::ScopedCGLSetCurrentContext(CGLContextObj context) {
+ CGLContextObj previous_context = CGLGetCurrentContext();
+ // It is possible for the previous context to have a zero reference count,
+ // because making a context current does not increment the reference count.
+ // In that case, do not restore the previous context.
+ if (previous_context && CGLGetContextRetainCount(previous_context)) {
+ previous_context_.reset(previous_context, base::scoped_policy::RETAIN);
+ }
CGLError error = CGLSetCurrentContext(context);
DCHECK_EQ(error, kCGLNoError) << "CGLSetCurrentContext should never fail";
}