MCPcopy Create free account
hub / github.com/URLab-Sim/UnrealRoboticsLab / StartupModule

Method StartupModule

Source/URLab/Private/URLab.cpp:36–134  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

34
35#define LOCTEXT_NAMESPACE "FURLabModule"
36void FURLabModule::StartupModule()
37{
38 FString PluginDir = IPluginManager::Get().FindPlugin("UnrealRoboticsLab")->GetBaseDir();
39 FString InstallDir = FPaths::Combine(PluginDir, TEXT("third_party/install"));
40
41 // Resolve LibraryPattern (literal filename or shell-style wildcard) to
42 // an absolute path inside SearchDir, or empty if no file matches.
43 auto ResolveLibraryFile = [](const FString& SearchDir, const FString& LibraryPattern) -> FString {
44 if (!LibraryPattern.Contains(TEXT("*")))
45 {
46 const FString Candidate = FPaths::Combine(SearchDir, LibraryPattern);
47 return FPaths::FileExists(Candidate) ? Candidate : FString();
48 }
49 TArray<FString> Matches;
50 IFileManager::Get().FindFiles(Matches, *FPaths::Combine(SearchDir, LibraryPattern),
51 /*Files=*/true, /*Directories=*/false);
52 return Matches.Num() > 0 ? FPaths::Combine(SearchDir, Matches[0]) : FString();
53 };
54
55 // Load a shared library and log success/failure. LibraryPattern may
56 // contain `*` so we can match toolset-versioned filenames (libzmq bakes
57 // the MSVC toolset version into its DLL name; building with a different
58 // toolset than the URLab hardcode used to surface as a delay-load
59 // 0xc06d007e on first ZMQ call). BinSubDir is the per-package
60 // subdirectory under third_party/install/<SubDir>/ that holds the
61 // loadable artifact: "bin" on Windows (DLLs), "lib" on Linux (.so).
62 auto LoadDependencyDLL = [&](const FString& LibraryPattern, const FString& SubDir, const FString& BinSubDir) {
63 // Try plugin third-party path first (editor / development).
64 FString DLLPath = ResolveLibraryFile(FPaths::Combine(InstallDir, SubDir, BinSubDir), LibraryPattern);
65 if (DLLPath.IsEmpty())
66 {
67 // Packaged build: shared libs staged next to the executable.
68 DLLPath = ResolveLibraryFile(FPlatformProcess::GetModulesDirectory(), LibraryPattern);
69 }
70 if (DLLPath.IsEmpty())
71 {
72 UE_LOG(LogURLab, Error,
73 TEXT("%s not found in third_party/install/%s/%s or the modules directory. "
74 "Run third_party/build_all.ps1 (Windows) or build_all.sh (Linux/macOS) "
75 "from the plugin root, then rebuild the editor."),
76 *LibraryPattern, *SubDir, *BinSubDir);
77 return false;
78 }
79 void* Handle = FPlatformProcess::GetDllHandle(*DLLPath);
80 if (Handle)
81 {
82 UE_LOG(LogURLab, Log, TEXT("Loaded %s from %s"), *FPaths::GetCleanFilename(DLLPath), *DLLPath);
83 return true;
84 }
85 UE_LOG(LogURLab, Error, TEXT("Failed to load %s (GetLastError surfaces in delay-load fault otherwise)"), *DLLPath);
86 return false;
87 };
88
89 bool bAllDepsLoaded = true;
90#if PLATFORM_WINDOWS
91 // Load MuJoCo. Since 3.7.0 the obj/stl decoders are compiled into
92 // mujoco.dll itself (changelog item 9); loading the standalone
93 // obj_decoder.dll / stl_decoder.dll would cause a plugin-registration

Callers

nothing calls this directly

Calls 1

IsEmptyMethod · 0.80

Tested by

no test coverage detected