Changed DynLib internal
Fixes the "Assimp32.dll not found" bug Former-commit-id: 662adba33c5d9cfbd23c8b0af0670626070baaa9
This commit is contained in:
parent
6545b919c5
commit
9389e1ea05
|
|
@ -33,8 +33,6 @@ class NzDynLibImpl;
|
||||||
|
|
||||||
class NzDynLib : NzNonCopyable
|
class NzDynLib : NzNonCopyable
|
||||||
{
|
{
|
||||||
friend NzDynLibImpl;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
NzDynLib();
|
NzDynLib();
|
||||||
NzDynLib(NzDynLib&& lib);
|
NzDynLib(NzDynLib&& lib);
|
||||||
|
|
@ -45,7 +43,7 @@ class NzDynLib : NzNonCopyable
|
||||||
|
|
||||||
bool IsLoaded() const;
|
bool IsLoaded() const;
|
||||||
|
|
||||||
bool Load(const NzString& libraryPath, bool appendExtension = true);
|
bool Load(const NzString& libraryPath);
|
||||||
void Unload();
|
void Unload();
|
||||||
|
|
||||||
NzDynLib& operator=(NzDynLib&& lib);
|
NzDynLib& operator=(NzDynLib&& lib);
|
||||||
|
|
|
||||||
|
|
@ -88,7 +88,7 @@ bool NzOpenAL::Initialize(bool openDevice)
|
||||||
for (const char* path : libs)
|
for (const char* path : libs)
|
||||||
{
|
{
|
||||||
NzString libPath(path);
|
NzString libPath(path);
|
||||||
if (!s_library.Load(libPath, false))
|
if (!s_library.Load(libPath))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
try
|
try
|
||||||
|
|
|
||||||
|
|
@ -61,18 +61,14 @@ bool NzDynLib::IsLoaded() const
|
||||||
return m_impl != nullptr;
|
return m_impl != nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NzDynLib::Load(const NzString& libraryPath, bool appendExtension)
|
bool NzDynLib::Load(const NzString& libraryPath)
|
||||||
{
|
{
|
||||||
NazaraLock(m_mutex)
|
NazaraLock(m_mutex)
|
||||||
|
|
||||||
Unload();
|
Unload();
|
||||||
|
|
||||||
NzString path = libraryPath;
|
|
||||||
if (appendExtension && !path.EndsWith(NAZARA_DYNLIB_EXTENSION))
|
|
||||||
path += NAZARA_DYNLIB_EXTENSION;
|
|
||||||
|
|
||||||
std::unique_ptr<NzDynLibImpl> impl(new NzDynLibImpl(this));
|
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);
|
NazaraError("Failed to load library: " + m_lastError);
|
||||||
return false;
|
return false;
|
||||||
|
|
|
||||||
|
|
@ -83,7 +83,7 @@ bool NzPluginManager::Mount(const NzString& pluginPath, bool appendExtension)
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<NzDynLib> library(new NzDynLib);
|
std::unique_ptr<NzDynLib> library(new NzDynLib);
|
||||||
if (!library->Load(path, false))
|
if (!library->Load(path))
|
||||||
{
|
{
|
||||||
NazaraError("Failed to load plugin");
|
NazaraError("Failed to load plugin");
|
||||||
return false;
|
return false;
|
||||||
|
|
|
||||||
|
|
@ -8,12 +8,12 @@
|
||||||
#include <Nazara/Core/String.hpp>
|
#include <Nazara/Core/String.hpp>
|
||||||
#include <Nazara/Core/Debug.hpp>
|
#include <Nazara/Core/Debug.hpp>
|
||||||
|
|
||||||
NzDynLibImpl::NzDynLibImpl(NzDynLib* parent) :
|
NzDynLibImpl::NzDynLibImpl(NzDynLib* parent)
|
||||||
m_parent(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.
|
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());
|
converter.pointer = dlsym(m_handle, symbol.GetConstBuffer());
|
||||||
if (!converter.pointer)
|
if (!converter.pointer)
|
||||||
m_parent->SetLastError(dlerror());
|
*errorMessage = dlerror();
|
||||||
|
|
||||||
return converter.func;
|
return converter.func;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NzDynLibImpl::Load(const NzString& libraryPath)
|
bool NzDynLibImpl::Load(const NzString& libraryPath, NzString* errorMessage)
|
||||||
{
|
{
|
||||||
NzString path = libraryPath;
|
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";
|
path += ".so";
|
||||||
|
|
||||||
dlerror(); // Clear error flag
|
dlerror(); // Clear error flag
|
||||||
|
|
||||||
m_handle = dlopen(path.GetConstBuffer(), RTLD_LAZY | RTLD_GLOBAL);
|
m_handle = dlopen(path.GetConstBuffer(), RTLD_LAZY | RTLD_GLOBAL);
|
||||||
|
|
||||||
if (m_handle)
|
if (m_handle)
|
||||||
return true;
|
return true;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_parent->SetLastError(dlerror());
|
*errorMessage = dlerror();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,6 @@ class NzDynLibImpl : NzNonCopyable
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void* m_handle;
|
void* m_handle;
|
||||||
NzDynLib* m_parent;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // NAZARA_DYNLIBIMPL_HPP
|
#endif // NAZARA_DYNLIBIMPL_HPP
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@
|
||||||
#include <Nazara/Core/Win32/DynLibImpl.hpp>
|
#include <Nazara/Core/Win32/DynLibImpl.hpp>
|
||||||
#include <Nazara/Core/DynLib.hpp>
|
#include <Nazara/Core/DynLib.hpp>
|
||||||
#include <Nazara/Core/Error.hpp>
|
#include <Nazara/Core/Error.hpp>
|
||||||
|
#include <Nazara/Core/File.hpp>
|
||||||
#include <Nazara/Core/String.hpp>
|
#include <Nazara/Core/String.hpp>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <Nazara/Core/Debug.hpp>
|
#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)
|
bool NzDynLibImpl::Load(const NzString& libraryPath, NzString* errorMessage)
|
||||||
{
|
{
|
||||||
std::unique_ptr<wchar_t[]> wPath(libraryPath.GetWideBuffer());
|
NzString path = libraryPath;
|
||||||
m_handle = LoadLibraryW(wPath.get());
|
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)
|
if (m_handle)
|
||||||
return true;
|
return true;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue