Bug 665218 - Keep the printing surface until the next BeginPage to avoid null-ptr crash [MacOSX only]. r=roc a=asa
authorMats Palmgren <matspal@gmail.com>
Tue, 02 Aug 2011 00:50:50 +0200
changeset 72728 822f8a8e65aa51cea84f09495186ffe53ea18af7
parent 72727 8966bdc465aaad39bc12b866ec53c0fb4ef8f634
child 72729 ff77eadd91426e68702edb20865726c513be9229
push id271
push usermpalmgren@mozilla.com
push dateMon, 01 Aug 2011 22:51:45 +0000
treeherdermozilla-aurora@822f8a8e65aa [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc, asa
bugs665218
milestone7.0a2
Bug 665218 - Keep the printing surface until the next BeginPage to avoid null-ptr crash [MacOSX only]. r=roc a=asa
gfx/src/nsDeviceContext.cpp
--- a/gfx/src/nsDeviceContext.cpp
+++ b/gfx/src/nsDeviceContext.cpp
@@ -629,37 +629,34 @@ nsDeviceContext::BeginPage(void)
 {
     nsresult rv = NS_OK;
 
     if (mDeviceContextSpec)
         rv = mDeviceContextSpec->BeginPage();
 
     if (NS_FAILED(rv)) return rv;
 
-    /* We need to get a new surface for each page on the Mac */
 #ifdef XP_MACOSX
+    // We need to get a new surface for each page on the Mac, as the
+    // CGContextRefs are only good for one page.
+    // And we don't null it out in EndPage because mPrintingSurface needs
+    // to be available also in-between EndPage/BeginPage (bug 665218).
     mDeviceContextSpec->GetSurfaceForPrinter(getter_AddRefs(mPrintingSurface));
 #endif
+
     rv = mPrintingSurface->BeginPage();
 
     return rv;
 }
 
 nsresult
 nsDeviceContext::EndPage(void)
 {
     nsresult rv = mPrintingSurface->EndPage();
 
-    /* We need to release the CGContextRef in the surface here, plus it's
-       not something you would want anyway, as these CGContextRefs are only good
-       for one page. */
-#ifdef XP_MACOSX
-    mPrintingSurface = nsnull;
-#endif
-
     if (mDeviceContextSpec)
         mDeviceContextSpec->EndPage();
 
     return rv;
 }
 
 void
 nsDeviceContext::ComputeClientRectUsingScreen(nsRect* outRect)