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:43:47 +0200
changeset 70589 7fc29f37f62d3a558188c87933a54648e74d690f
parent 70588 eeabcaa28b68956fc3133b7ec844431323715e35
child 70590 2f8c75dcbe0bae7dff893d0b9db1ad8f5176bc7f
push id139
push usermpalmgren@mozilla.com
push dateMon, 01 Aug 2011 22:44:39 +0000
treeherdermozilla-beta@7fc29f37f62d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc, asa
bugs665218
milestone6.0
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
@@ -639,37 +639,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)