diff --git a/content/canvas/src/nsCanvasRenderingContext2D.cpp b/content/canvas/src/nsCanvasRenderingContext2D.cpp index b423d197b6d..57c5704fd4d 100644 --- a/content/canvas/src/nsCanvasRenderingContext2D.cpp +++ b/content/canvas/src/nsCanvasRenderingContext2D.cpp @@ -720,6 +720,14 @@ nsCanvasRenderingContext2D::Render(nsIRenderingContext *rc) { nsresult rv = NS_OK; + if (!mSurface || !mCairo || + cairo_surface_status(mSurface) != CAIRO_STATUS_SUCCESS || + cairo_status(mCairo) != CAIRO_STATUS_SUCCESS) + return NS_ERROR_FAILURE; + + if (!mThebesSurface) + return NS_ERROR_FAILURE; + gfxContext* ctx = (gfxContext*) rc->GetNativeGraphicData(nsIRenderingContext::NATIVE_THEBES_CONTEXT); nsRefPtr pat = new gfxPattern(mThebesSurface); @@ -748,14 +756,12 @@ nsCanvasRenderingContext2D::GetInputStream(const nsACString& aMimeType, const nsAString& aEncoderOptions, nsIInputStream **aStream) { + if (!mSurface || cairo_surface_status(mSurface) != CAIRO_STATUS_SUCCESS) + return NS_ERROR_FAILURE; + nsCString conid(NS_LITERAL_CSTRING("@mozilla.org/image/encoder;2?type=")); conid += aMimeType; - if (cairo_status(mCairo)) { - fprintf (stderr, "Cairo error! %d %s\n", cairo_status(mCairo), cairo_status_to_string(cairo_status(mCairo))); - fflush (stderr); - } - nsCOMPtr encoder = do_CreateInstance(conid.get()); if (!encoder) return NS_ERROR_FAILURE; diff --git a/content/html/content/src/nsHTMLCanvasElement.cpp b/content/html/content/src/nsHTMLCanvasElement.cpp index 54ee6032acd..e1e870d7223 100644 --- a/content/html/content/src/nsHTMLCanvasElement.cpp +++ b/content/html/content/src/nsHTMLCanvasElement.cpp @@ -455,10 +455,16 @@ nsHTMLCanvasElement::GetContext(const nsAString& aContextId, return NS_ERROR_INVALID_ARG; rv = mCurrentContext->SetCanvasElement(this); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_FAILED(rv)) { + mCurrentContext = nsnull; + return rv; + } rv = UpdateContext(); - NS_ENSURE_SUCCESS(rv, rv); + if (NS_FAILED(rv)) { + mCurrentContext = nsnull; + return rv; + } mCurrentContextId.Assign(aContextId); } else if (!mCurrentContextId.Equals(aContextId)) {