Skip to content

Commit

Permalink
Fix library loading on non-windows platforms
Browse files Browse the repository at this point in the history
  • Loading branch information
DoubleDeez committed Jun 10, 2023
1 parent 7b199db commit 269054d
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 40 deletions.
21 changes: 14 additions & 7 deletions Source/ThirdParty/FastNoise2/FastNoise2.build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@ public FastNoise2(ReadOnlyTargetRules Target) : base(Target)

PublicAdditionalLibraries.Add(LibraryPath);

if (Target.Platform.IsInGroup(UnrealPlatformGroup.Microsoft))
{
// Delay-load the DLL, so we can load it from the right place first
PublicDelayLoadDLLs.Add(LibraryName + RuntimeLibExtension);
}
// Delay-load the library, so we can load it from the right place first
PublicDelayLoadDLLs.Add(LibraryName + RuntimeLibExtension);

// Ensure that the DLL is staged along with the executable
// Ensure that the library is staged along with the executable
RuntimeDependencies.Add(RuntimePath);

PublicDefinitions.Add("FASTNOISE_LIBRARY_PATH=\"" + RelativeRuntimePath.Replace("\\", "\\\\") + "\"");
}

private string ConfigName
Expand All @@ -42,7 +41,15 @@ private string RuntimePath
{
get
{
return Path.Combine("$(PluginDir)", "Binaries", "ThirdParty", "FastNoise2", PlatformString, LibraryName + RuntimeLibExtension);
return Path.Combine("$(PluginDir)", RelativeRuntimePath);
}
}

private string RelativeRuntimePath
{
get
{
return Path.Combine("Binaries", "ThirdParty", "FastNoise2", PlatformString, LibraryName + RuntimeLibExtension);
}
}

Expand Down
16 changes: 5 additions & 11 deletions Source/UnrealFastNoise2/Private/UnrealFastNoise2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,15 @@

void FUnrealFastNoise2Module::StartupModule()
{
// Get the base directory of this plugin
FString BaseDir = IPluginManager::Get().FindPlugin("UnrealFastNoise2")->GetBaseDir();

// Add on the relative location of the third party dll and load it
#if UE_BUILD_DEBUG
FString LibraryPath = FPaths::Combine(*BaseDir, TEXT("Binaries/ThirdParty/FastNoise2/Win64/FastNoiseD.dll"));
#else
FString LibraryPath = FPaths::Combine(*BaseDir, TEXT("Binaries/ThirdParty/FastNoise2/Win64/FastNoise.dll"));
#endif
const FString BaseDir = IPluginManager::Get().FindPlugin("UnrealFastNoise2")->GetBaseDir();
const FString LibraryPath = FPaths::Combine(*BaseDir, TEXT(FASTNOISE_LIBRARY_PATH));

FastNoiseHandle = !LibraryPath.IsEmpty() ? FPlatformProcess::GetDllHandle(*LibraryPath) : nullptr;

if (FastNoiseHandle == nullptr)
{
FMessageDialog::Open(EAppMsgType::Ok, NSLOCTEXT("UnrealFastNoise2Module", "ThirdPartyLibraryError", "Failed to load FastNoise library"));
const FText ErrorFormat = NSLOCTEXT("UnrealFastNoise2Module", "ThirdPartyLibraryError", "Failed to load FastNoise library at path [{0}]");
FMessageDialog::Open(EAppMsgType::Ok, FText::Format(ErrorFormat, FText::FromString(LibraryPath)));
}
}

Expand All @@ -32,5 +26,5 @@ void FUnrealFastNoise2Module::ShutdownModule()
FPlatformProcess::FreeDllHandle(FastNoiseHandle);
FastNoiseHandle = nullptr;
}

IMPLEMENT_MODULE(FUnrealFastNoise2Module, UnrealFastNoise2)
2 changes: 1 addition & 1 deletion Source/UnrealFastNoise2/Public/UnrealFastNoise2.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ class FUnrealFastNoise2Module : public IModuleInterface
virtual void ShutdownModule() override;

private:
void* FastNoiseHandle;
void* FastNoiseHandle = nullptr;
};
29 changes: 8 additions & 21 deletions Source/UnrealFastNoise2/UnrealFastNoise2.Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,13 @@ public class UnrealFastNoise2 : ModuleRules
public UnrealFastNoise2(ReadOnlyTargetRules Target) : base(Target)
{
PCHUsage = ModuleRules.PCHUsageMode.UseExplicitOrSharedPCHs;

PublicIncludePaths.AddRange(
new string[] {
}
);



PrivateIncludePaths.AddRange(
new string[] {
}
);
);


PublicDependencyModuleNames.AddRange(
new string[]
{
Expand All @@ -28,21 +22,14 @@ public UnrealFastNoise2(ReadOnlyTargetRules Target) : base(Target)
"Projects",
"FastNoise2"
}
);
);


PrivateDependencyModuleNames.AddRange(
new string[]
{
"CoreUObject"
}
);


DynamicallyLoadedModuleNames.AddRange(
new string[]
{
}
);
);
}
}

0 comments on commit 269054d

Please sign in to comment.