| Index: ui/gl/gl_surface_ozone.cc
|
| diff --git a/ui/gl/gl_surface_ozone.cc b/ui/gl/gl_surface_ozone.cc
|
| index 4815405d210b126b329919f5d8fc843966e9c3e1..da80397654374248b9305f0701a7c0ba0de7eaa5 100644
|
| --- a/ui/gl/gl_surface_ozone.cc
|
| +++ b/ui/gl/gl_surface_ozone.cc
|
| @@ -578,8 +578,16 @@ void GLSurfaceOzoneSurfacelessSurfaceImpl::Destroy() {
|
| if (!context_)
|
| return;
|
| scoped_refptr<gfx::GLContext> previous_context = gfx::GLContext::GetCurrent();
|
| - scoped_refptr<gfx::GLSurface> previous_surface = gfx::GLSurface::GetCurrent();
|
| - context_->MakeCurrent(this);
|
| + scoped_refptr<gfx::GLSurface> previous_surface;
|
| +
|
| + bool was_current = previous_context && previous_context->IsCurrent(nullptr) &&
|
| + gfx::GLSurface::GetCurrent() == this;
|
| + if (!was_current) {
|
| + // Only take a reference to previous surface if it's not |this|
|
| + // because otherwise we can take a self reference from our own dtor.
|
| + previous_surface = gfx::GLSurface::GetCurrent();
|
| + context_->MakeCurrent(this);
|
| + }
|
|
|
| glBindFramebufferEXT(GL_FRAMEBUFFER, 0);
|
| if (fbo_) {
|
| @@ -594,7 +602,7 @@ void GLSurfaceOzoneSurfacelessSurfaceImpl::Destroy() {
|
| image->Destroy(true);
|
| }
|
|
|
| - if (previous_context.get()) {
|
| + if (!was_current) {
|
| previous_context->MakeCurrent(previous_surface.get());
|
| } else {
|
| context_->ReleaseCurrent(this);
|
|
|