Skip to content

Commit

Permalink
Fix serious issues with XRay::Module
Browse files Browse the repository at this point in the history
1. Fix handle fills with trash on construction
2. Add new param dontUnload, which used for renderers to prevent RTTI
invalidation
(fe7bc5f)
  • Loading branch information
Xottab-DUTY committed Nov 13, 2017
1 parent 623611f commit 9c218b4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
16 changes: 9 additions & 7 deletions src/xrCore/ModuleLookup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,34 @@

namespace XRay
{
Module::Module() : handle(nullptr) {}
Module::Module(const bool dontUnload) : handle(nullptr), dontUnload(dontUnload) {}

Module::Module(pcstr moduleName, bool log /*= true*/)
Module::Module(pcstr moduleName, bool dontUnload /*= false*/) : handle(nullptr)
{
open(moduleName, log);
open(moduleName);
}

Module::~Module()
{
close();
}

void* Module::open(pcstr moduleName, bool log /*= true*/)
void* Module::open(pcstr moduleName)
{
if (exist())
close();

if (log)
Log("Loading DLL:", moduleName);

Log("Loading DLL:", moduleName);

handle = ::LoadLibrary(moduleName);
return handle;
}

void Module::close()
{
if (dontUnload)
return;

FreeLibrary(static_cast<HMODULE>(handle));
handle = nullptr;
}
Expand Down
7 changes: 4 additions & 3 deletions src/xrCore/ModuleLookup.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ namespace XRay
class XRCORE_API Module
{
void* handle;
bool dontUnload;

public:
Module();
Module(pcstr moduleName, bool log = true);
Module(const bool dontUnload = false);
Module(pcstr moduleName, bool dontUnload = false);
~Module();

void* open(pcstr moduleName, bool log = true);
void* open(pcstr moduleName);
void close();

bool exist() const;
Expand Down
2 changes: 1 addition & 1 deletion src/xrEngine/EngineAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ void CEngineAPI::CreateRendererList()
bool bSupports_r3 = false;
bool bSupports_r4 = false;

hRender = std::make_unique<XRay::Module>();
hRender = std::make_unique<XRay::Module>(true);

if (strstr(Core.Params, "-perfhud_hack"))
{
Expand Down

0 comments on commit 9c218b4

Please sign in to comment.