mirror of
https://github.com/OpenTTD/OpenTTD
synced 2026-01-19 10:22:39 +01:00
Codechange: Use unique_ptr to manage drivers.
This commit is contained in:
committed by
Peter Nelson
parent
c3457cd4c0
commit
d95422561b
@@ -139,20 +139,18 @@ bool DriverFactoryBase::SelectDriverImpl(const std::string &name, Driver::Type t
|
||||
FioFOpenFile(HWACCELERATION_TEST_FILE, "w", BASE_DIR);
|
||||
}
|
||||
|
||||
Driver *oldd = *GetActiveDriver(type);
|
||||
Driver *newd = d->CreateInstance();
|
||||
*GetActiveDriver(type) = newd;
|
||||
/* Keep old driver in case we need to switch back, or may still need to process an OS callback. */
|
||||
auto oldd = std::move(GetActiveDriver(type));
|
||||
GetActiveDriver(type) = d->CreateInstance();
|
||||
|
||||
auto err = newd->Start({});
|
||||
auto err = GetActiveDriver(type)->Start({});
|
||||
if (!err) {
|
||||
Debug(driver, 1, "Successfully probed {} driver '{}'", GetDriverTypeName(type), d->name);
|
||||
delete oldd;
|
||||
return true;
|
||||
}
|
||||
|
||||
*GetActiveDriver(type) = oldd;
|
||||
GetActiveDriver(type) = std::move(oldd);
|
||||
Debug(driver, 1, "Probing {} driver '{}' failed with error: {}", GetDriverTypeName(type), d->name, *err);
|
||||
delete newd;
|
||||
|
||||
if (type == Driver::DT_VIDEO && _video_hw_accel && d->UsesHardwareAcceleration()) {
|
||||
_video_hw_accel = false;
|
||||
@@ -185,17 +183,14 @@ bool DriverFactoryBase::SelectDriverImpl(const std::string &name, Driver::Type t
|
||||
if (!StrEqualsIgnoreCase(dname, d->name)) continue;
|
||||
|
||||
/* Found our driver, let's try it */
|
||||
Driver *newd = d->CreateInstance();
|
||||
|
||||
auto newd = d->CreateInstance();
|
||||
auto err = newd->Start(parms);
|
||||
if (err) {
|
||||
delete newd;
|
||||
UserError("Unable to load driver '{}'. The error was: {}", d->name, *err);
|
||||
}
|
||||
|
||||
Debug(driver, 1, "Successfully loaded {} driver '{}'", GetDriverTypeName(type), d->name);
|
||||
delete *GetActiveDriver(type);
|
||||
*GetActiveDriver(type) = newd;
|
||||
GetActiveDriver(type) = std::move(newd);
|
||||
return true;
|
||||
}
|
||||
UserError("No such {} driver: {}\n", GetDriverTypeName(type), dname);
|
||||
|
||||
Reference in New Issue
Block a user