diff options
author | rubidium <rubidium@openttd.org> | 2014-01-03 08:29:07 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2014-01-03 08:29:07 +0000 |
commit | 1e1656110a3c980448a0ddf708c1d5415ae7ea11 (patch) | |
tree | 29ab4011086540c73e701e1cf131fa18bb08c6e9 /src | |
parent | 4c84d13454414b84b72540265b793aeec938cdd3 (diff) | |
download | openttd-1e1656110a3c980448a0ddf708c1d5415ae7ea11.tar.xz |
(svn r26215) -Codechange: rework code so one can test if a blitter factory exists before attempting trying to instantiate an instance
Diffstat (limited to 'src')
-rw-r--r-- | src/blitter/factory.hpp | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/src/blitter/factory.hpp b/src/blitter/factory.hpp index 83edd99aa..cda470510 100644 --- a/src/blitter/factory.hpp +++ b/src/blitter/factory.hpp @@ -95,6 +95,24 @@ public: */ 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"; #else @@ -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; |