Changed DynLib internal

Fixes the "Assimp32.dll not found" bug


Former-commit-id: 662adba33c5d9cfbd23c8b0af0670626070baaa9
This commit is contained in:
Lynix 2014-01-12 10:33:03 +01:00
parent 6545b919c5
commit 9389e1ea05
7 changed files with 21 additions and 22 deletions

View File

@ -33,8 +33,6 @@ class NzDynLibImpl;
class NzDynLib : NzNonCopyable
{
friend NzDynLibImpl;
public:
NzDynLib();
NzDynLib(NzDynLib&& lib);
@ -45,7 +43,7 @@ class NzDynLib : NzNonCopyable
bool IsLoaded() const;
bool Load(const NzString& libraryPath, bool appendExtension = true);
bool Load(const NzString& libraryPath);
void Unload();
NzDynLib& operator=(NzDynLib&& lib);

View File

@ -88,7 +88,7 @@ bool NzOpenAL::Initialize(bool openDevice)
for (const char* path : libs)
{
NzString libPath(path);
if (!s_library.Load(libPath, false))
if (!s_library.Load(libPath))
continue;
try

View File

@ -61,18 +61,14 @@ bool NzDynLib::IsLoaded() const
return m_impl != nullptr;
}
bool NzDynLib::Load(const NzString& libraryPath, bool appendExtension)
bool NzDynLib::Load(const NzString& libraryPath)
{
NazaraLock(m_mutex)
Unload();
NzString path = libraryPath;
if (appendExtension && !path.EndsWith(NAZARA_DYNLIB_EXTENSION))
path += NAZARA_DYNLIB_EXTENSION;
std::unique_ptr<NzDynLibImpl> impl(new NzDynLibImpl(this));
if (!impl->Load(path, &m_lastError))
if (!impl->Load(libraryPath, &m_lastError))
{
NazaraError("Failed to load library: " + m_lastError);
return false;

View File

@ -83,7 +83,7 @@ bool NzPluginManager::Mount(const NzString& pluginPath, bool appendExtension)
}
std::unique_ptr<NzDynLib> library(new NzDynLib);
if (!library->Load(path, false))
if (!library->Load(path))
{
NazaraError("Failed to load plugin");
return false;

View File

@ -8,12 +8,12 @@
#include <Nazara/Core/String.hpp>
#include <Nazara/Core/Debug.hpp>
NzDynLibImpl::NzDynLibImpl(NzDynLib* parent) :
m_parent(parent)
NzDynLibImpl::NzDynLibImpl(NzDynLib* parent)
{
NazaraUnused(parent);
}
NzDynLibFunc NzDynLibImpl::GetSymbol(const NzString& symbol) const
NzDynLibFunc NzDynLibImpl::GetSymbol(const NzString& symbol, NzString* errorMessage) const
{
/*
Il n'est pas standard de cast un pointeur d'objet vers un pointeur de fonction.
@ -31,26 +31,27 @@ NzDynLibFunc NzDynLibImpl::GetSymbol(const NzString& symbol) const
converter.pointer = dlsym(m_handle, symbol.GetConstBuffer());
if (!converter.pointer)
m_parent->SetLastError(dlerror());
*errorMessage = dlerror();
return converter.func;
}
bool NzDynLibImpl::Load(const NzString& libraryPath)
bool NzDynLibImpl::Load(const NzString& libraryPath, NzString* errorMessage)
{
NzString path = libraryPath;
if (!path.EndsWith(".so"))
unsigned int pos = path.FindLast(".so");
if (pos == NzString::npos || (path.GetLength() > pos+3 && path[pos+3] != '.'))
path += ".so";
dlerror(); // Clear error flag
m_handle = dlopen(path.GetConstBuffer(), RTLD_LAZY | RTLD_GLOBAL);
if (m_handle)
return true;
else
{
m_parent->SetLastError(dlerror());
*errorMessage = dlerror();
return false;
}
}

View File

@ -25,7 +25,6 @@ class NzDynLibImpl : NzNonCopyable
private:
void* m_handle;
NzDynLib* m_parent;
};
#endif // NAZARA_DYNLIBIMPL_HPP

View File

@ -5,6 +5,7 @@
#include <Nazara/Core/Win32/DynLibImpl.hpp>
#include <Nazara/Core/DynLib.hpp>
#include <Nazara/Core/Error.hpp>
#include <Nazara/Core/File.hpp>
#include <Nazara/Core/String.hpp>
#include <memory>
#include <Nazara/Core/Debug.hpp>
@ -25,8 +26,12 @@ NzDynLibFunc NzDynLibImpl::GetSymbol(const NzString& symbol, NzString* errorMess
bool NzDynLibImpl::Load(const NzString& libraryPath, NzString* errorMessage)
{
std::unique_ptr<wchar_t[]> wPath(libraryPath.GetWideBuffer());
m_handle = LoadLibraryW(wPath.get());
NzString path = libraryPath;
if (!path.EndsWith(".dll"))
path += ".dll";
std::unique_ptr<wchar_t[]> wPath(path.GetWideBuffer());
m_handle = LoadLibraryExW(wPath.get(), nullptr, (NzFile::IsAbsolute(path)) ? LOAD_WITH_ALTERED_SEARCH_PATH : 0);
if (m_handle)
return true;