(svn r26215) -Codechange: rework code so one can test if a blitter factory exists before attempting trying to instantiate an instance

This commit is contained in:
rubidium 2014-01-03 08:29:07 +00:00
parent 4c84d13454
commit 1e1656110a
1 changed files with 19 additions and 6 deletions

View File

@ -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;