diff --git a/gfx/thebes/GLContext.cpp b/gfx/thebes/GLContext.cpp index 7d7e00955f8..d02c1c87628 100644 --- a/gfx/thebes/GLContext.cpp +++ b/gfx/thebes/GLContext.cpp @@ -44,6 +44,8 @@ #include "prlink.h" +#include "nsThreadUtils.h" + #include "gfxImageSurface.h" #include "GLContext.h" #include "GLContextProvider.h" @@ -436,12 +438,19 @@ GLContext::CreateTextureImage(const nsIntSize& aSize, BasicTextureImage::~BasicTextureImage() { - nsRefPtr ctx = mGLContext->GetSharedContext(); - if (!ctx) { - ctx = mGLContext; + GLContext *ctx = mGLContext; + if (ctx->IsDestroyed() || !NS_IsMainThread()) { + ctx = ctx->GetSharedContext(); + } + + // If we have a context, then we need to delete the texture; + // if we don't have a context (either real or shared), + // then they went away when the contex was deleted, because it + // was the only one that had access to it. + if (ctx && !ctx->IsDestroyed()) { + mGLContext->MakeCurrent(); + mGLContext->fDeleteTextures(1, &mTexture); } - ctx->MakeCurrent(); - ctx->fDeleteTextures(1, &mTexture); } gfxContext* diff --git a/gfx/thebes/GLContext.h b/gfx/thebes/GLContext.h index dc5a2f18e9a..44f36f637f0 100644 --- a/gfx/thebes/GLContext.h +++ b/gfx/thebes/GLContext.h @@ -393,6 +393,11 @@ public: // the GL function pointers! void THEBES_API MarkDestroyed(); + PRBool IsDestroyed() { + // MarkDestroyed will mark all these as null. + return fUseProgram == nsnull; + } + enum NativeDataType { NativeGLContext, NativeImageSurface,