Skip to content

Commit 9c218b4

Browse files
committed
Fix serious issues with XRay::Module
1. Fix handle fills with trash on construction 2. Add new param dontUnload, which used for renderers to prevent RTTI invalidation (fe7bc5f)
1 parent 623611f commit 9c218b4

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

src/xrCore/ModuleLookup.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,34 @@
44

55
namespace XRay
66
{
7-
Module::Module() : handle(nullptr) {}
7+
Module::Module(const bool dontUnload) : handle(nullptr), dontUnload(dontUnload) {}
88

9-
Module::Module(pcstr moduleName, bool log /*= true*/)
9+
Module::Module(pcstr moduleName, bool dontUnload /*= false*/) : handle(nullptr)
1010
{
11-
open(moduleName, log);
11+
open(moduleName);
1212
}
1313

1414
Module::~Module()
1515
{
1616
close();
1717
}
1818

19-
void* Module::open(pcstr moduleName, bool log /*= true*/)
19+
void* Module::open(pcstr moduleName)
2020
{
2121
if (exist())
2222
close();
23-
24-
if (log)
25-
Log("Loading DLL:", moduleName);
23+
24+
Log("Loading DLL:", moduleName);
2625

2726
handle = ::LoadLibrary(moduleName);
2827
return handle;
2928
}
3029

3130
void Module::close()
3231
{
32+
if (dontUnload)
33+
return;
34+
3335
FreeLibrary(static_cast<HMODULE>(handle));
3436
handle = nullptr;
3537
}

src/xrCore/ModuleLookup.hpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@ namespace XRay
55
class XRCORE_API Module
66
{
77
void* handle;
8+
bool dontUnload;
89

910
public:
10-
Module();
11-
Module(pcstr moduleName, bool log = true);
11+
Module(const bool dontUnload = false);
12+
Module(pcstr moduleName, bool dontUnload = false);
1213
~Module();
1314

14-
void* open(pcstr moduleName, bool log = true);
15+
void* open(pcstr moduleName);
1516
void close();
1617

1718
bool exist() const;

src/xrEngine/EngineAPI.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ void CEngineAPI::CreateRendererList()
199199
bool bSupports_r3 = false;
200200
bool bSupports_r4 = false;
201201

202-
hRender = std::make_unique<XRay::Module>();
202+
hRender = std::make_unique<XRay::Module>(true);
203203

204204
if (strstr(Core.Params, "-perfhud_hack"))
205205
{

0 commit comments

Comments
 (0)