aboutsummaryrefslogtreecommitdiffstats
path: root/router
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2018-10-30 17:03:21 -0700
committerChris Robinson <[email protected]>2018-10-30 17:03:21 -0700
commitda150572f94ec354c8061c0bf1aafa0926c6dbc7 (patch)
tree916247e9790b7ae5649b44a14763e61d3bdc2d34 /router
parent615c025b6786adfd38446559b48b453e1e6c4883 (diff)
Clean up the DriverIface in its destructor
Diffstat (limited to 'router')
-rw-r--r--router/router.cpp9
-rw-r--r--router/router.h14
2 files changed, 13 insertions, 10 deletions
diff --git a/router/router.cpp b/router/router.cpp
index 049ac3bc..66bf5dd3 100644
--- a/router/router.cpp
+++ b/router/router.cpp
@@ -63,11 +63,6 @@ BOOL APIENTRY DllMain(HINSTANCE UNUSED(module), DWORD reason, void* UNUSED(reser
break;
case DLL_PROCESS_DETACH:
- for(auto &drv : DriverList)
- {
- if(drv.Module)
- FreeLibrary(drv.Module);
- }
DriverList.clear();
if(LogFile && LogFile != stderr)
@@ -98,7 +93,7 @@ static void AddModule(HMODULE module, const WCHAR *name)
}
}
- DriverList.emplace_back();
+ DriverList.emplace_back(name, module);
DriverIface &newdrv = DriverList.back();
/* Load required functions. */
@@ -209,8 +204,6 @@ static void AddModule(HMODULE module, const WCHAR *name)
if(!err)
{
ALCint alc_ver[2] = { 0, 0 };
- newdrv.Name = name;
- newdrv.Module = module;
newdrv.alcGetIntegerv(nullptr, ALC_MAJOR_VERSION, 1, &alc_ver[0]);
newdrv.alcGetIntegerv(nullptr, ALC_MINOR_VERSION, 1, &alc_ver[1]);
if(newdrv.alcGetError(nullptr) == ALC_NO_ERROR)
diff --git a/router/router.h b/router/router.h
index 41060ecd..d2574e74 100644
--- a/router/router.h
+++ b/router/router.h
@@ -31,7 +31,7 @@
#define MAKE_ALC_VER(major, minor) (((major)<<8) | (minor))
-typedef struct DriverIface {
+struct DriverIface {
std::wstring Name;
HMODULE Module{nullptr};
int ALCVer{0};
@@ -133,7 +133,17 @@ typedef struct DriverIface {
LPALDOPPLERVELOCITY alDopplerVelocity{nullptr};
LPALSPEEDOFSOUND alSpeedOfSound{nullptr};
LPALDISTANCEMODEL alDistanceModel{nullptr};
-} DriverIface;
+
+ DriverIface(std::wstring name, HMODULE mod)
+ : Name(std::move(name)), Module(mod)
+ { }
+ ~DriverIface()
+ {
+ if(Module)
+ FreeLibrary(Module);
+ Module = nullptr;
+ }
+};
extern std::vector<DriverIface> DriverList;