From bf4ea2594af1bc6baab2e705dc167c70382b89d5 Mon Sep 17 00:00:00 2001 From: rubidium Date: Fri, 3 Jan 2014 08:29:07 +0000 Subject: [PATCH] (svn r26215) -Codechange: rework code so one can test if a blitter factory exists before attempting trying to instantiate an instance --- src/blitter/factory.hpp | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/blitter/factory.hpp b/src/blitter/factory.hpp index 83edd99aa7..cda470510b 100644 --- a/src/blitter/factory.hpp +++ b/src/blitter/factory.hpp @@ -94,6 +94,24 @@ public: * @post Sets the blitter so GetCurrentBlitter() returns it too. */ static Blitter *SelectBlitter(const char *name) + { + BlitterFactory *b = GetBlitterFactory(name); + if (b == NULL) return NULL; + + Blitter *newb = b->CreateInstance(); + delete *GetActiveBlitter(); + *GetActiveBlitter() = newb; + + DEBUG(driver, 1, "Successfully %s blitter '%s'", StrEmpty(name) ? "probed" : "loaded", newb->GetName()); + return newb; + } + + /** + * Get the blitter factory with the given name. + * @param name the blitter factory to select. + * @return The blitter factory, or NULL when there isn't one with the wanted name. + */ + static BlitterFactory *GetBlitterFactory(const char *name) { #if defined(DEDICATED) const char *default_blitter = "null"; @@ -117,12 +135,7 @@ public: for (; it != GetBlitters().end(); it++) { BlitterFactory *b = (*it).second; if (strcasecmp(bname, b->name) == 0) { - Blitter *newb = b->CreateInstance(); - delete *GetActiveBlitter(); - *GetActiveBlitter() = newb; - - DEBUG(driver, 1, "Successfully %s blitter '%s'", StrEmpty(name) ? "probed" : "loaded", bname); - return newb; + return b; } } return NULL;