Bug 651926: abort (even in production) if anything in gfxPlatform::Init fails, its callers can't cope. r=jrmuizel
authorZack Weinberg <zackw@panix.com>
Thu, 21 Apr 2011 12:36:53 -0700
changeset 68495 2250bc3d05326abc1fdba1fe71c72d75d389bb85
parent 68494 33b198be1aa3c79438f0fba0ab2595d6034a5303
child 68496 c4864738e3fd0e7e9083d72e553d5ec34940dbdc
push id19662
push userzackw@panix.com
push dateMon, 25 Apr 2011 03:12:04 +0000
treeherdermozilla-central@d29e9cb9d0c9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjrmuizel
bugs651926
milestone6.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 651926: abort (even in production) if anything in gfxPlatform::Init fails, its callers can't cope. r=jrmuizel
gfx/src/nsThebesGfxFactory.cpp
gfx/thebes/gfxPlatform.cpp
gfx/thebes/gfxPlatform.h
--- a/gfx/src/nsThebesGfxFactory.cpp
+++ b/gfx/src/nsThebesGfxFactory.cpp
@@ -132,17 +132,18 @@ static const mozilla::Module::ContractID
 static const mozilla::Module::CategoryEntry kThebesCategories[] = {
     { "app-startup", "Gfx Initialization", "service,@mozilla.org/gfx/init;1" },
     { NULL }
 };
 
 static nsresult
 nsThebesGfxModuleCtor()
 {
-    return gfxPlatform::Init();
+    gfxPlatform::Init();
+    return NS_OK;
 }
 
 static void
 nsThebesGfxModuleDtor()
 {
     nsDeviceContext::ClearCachedSystemFonts();
     gfxPlatform::Shutdown();
 }
--- a/gfx/thebes/gfxPlatform.cpp
+++ b/gfx/thebes/gfxPlatform.cpp
@@ -229,17 +229,17 @@ gfxPlatform::gfxPlatform()
 }
 
 gfxPlatform*
 gfxPlatform::GetPlatform()
 {
     return gPlatform;
 }
 
-nsresult
+void
 gfxPlatform::Init()
 {
     NS_ASSERTION(!gPlatform, "Already started???");
 
     gfxAtoms::RegisterAtoms();
 
 #ifdef PR_LOGGING
     sFontlistLog = PR_NewLogModule("fontlist");;
@@ -276,67 +276,55 @@ gfxPlatform::Init()
     #error "No gfxPlatform implementation available"
 #endif
 
     nsresult rv;
 
 #if defined(XP_MACOSX) || defined(XP_WIN) || defined(ANDROID) // temporary, until this is implemented on others
     rv = gfxPlatformFontList::Init();
     if (NS_FAILED(rv)) {
-        NS_ERROR("Could not initialize gfxPlatformFontList");
-        Shutdown();
-        return rv;
+        NS_RUNTIMEABORT("Could not initialize gfxPlatformFontList");
     }
 #endif
 
     gPlatform->mScreenReferenceSurface =
         gPlatform->CreateOffscreenSurface(gfxIntSize(1,1),
                                           gfxASurface::CONTENT_COLOR_ALPHA);
     if (!gPlatform->mScreenReferenceSurface) {
-        NS_ERROR("Could not initialize mScreenReferenceSurface");
-        Shutdown();
-        return NS_ERROR_OUT_OF_MEMORY;
+        NS_RUNTIMEABORT("Could not initialize mScreenReferenceSurface");
     }
 
     rv = gfxFontCache::Init();
     if (NS_FAILED(rv)) {
-        NS_ERROR("Could not initialize gfxFontCache");
-        Shutdown();
-        return rv;
+        NS_RUNTIMEABORT("Could not initialize gfxFontCache");
     }
 
     rv = gfxTextRunWordCache::Init();
     if (NS_FAILED(rv)) {
-        NS_ERROR("Could not initialize gfxTextRunWordCache");
-        Shutdown();
-        return rv;
+        NS_RUNTIMEABORT("Could not initialize gfxTextRunWordCache");
     }
 
     rv = gfxTextRunCache::Init();
     if (NS_FAILED(rv)) {
-        NS_ERROR("Could not initialize gfxTextRunCache");
-        Shutdown();
-        return rv;
+        NS_RUNTIMEABORT("Could not initialize gfxTextRunCache");
     }
 
     /* Pref migration hook. */
     MigratePrefs();
 
     /* Create and register our CMS Override observer. */
     gPlatform->overrideObserver = new SRGBOverrideObserver();
     FontPrefsObserver *fontPrefObserver = new FontPrefsObserver();
 
     nsCOMPtr<nsIPrefBranch2> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
     if (prefs) {
         prefs->AddObserver(CMForceSRGBPrefName, gPlatform->overrideObserver, PR_TRUE);
         prefs->AddObserver("gfx.downloadable_fonts.", fontPrefObserver, PR_FALSE);
         prefs->AddObserver("gfx.font_rendering.", fontPrefObserver, PR_FALSE);
     }
-
-    return NS_OK;
 }
 
 void
 gfxPlatform::Shutdown()
 {
     // These may be called before the corresponding subsystems have actually
     // started up. That's OK, they can handle it.
     gfxTextRunCache::Shutdown();
--- a/gfx/thebes/gfxPlatform.h
+++ b/gfx/thebes/gfxPlatform.h
@@ -142,22 +142,23 @@ public:
     /**
      * Return a pointer to the current active platform.
      * This is a singleton; it contains mostly convenience
      * functions to obtain platform-specific objects.
      */
     static gfxPlatform *GetPlatform();
 
     /**
-     * Start up Thebes. This can fail.
+     * Start up Thebes.
      */
-    static nsresult Init();
+    static void Init();
 
     /**
-     * Clean up static objects to shut down thebes.
+     * Shut down Thebes.
+     * Init() arranges for this to be called at an appropriate time.
      */
     static void Shutdown();
 
     /**
      * Create an offscreen surface of the given dimensions
      * and image format.
      */
     virtual already_AddRefed<gfxASurface> CreateOffscreenSurface(const gfxIntSize& size,