@@ -28,7 +28,6 @@ static ankerl::unordered_dense::map<unsigned int, ContextData<IFeature_Vk>> VkCo
2828static int evalCounter = 0 ;
2929static bool shutdown = false ;
3030static thread_local bool _skipInit = false ;
31- static wchar_t const ** paths;
3231
3332class ScopedInitVk
3433{
@@ -45,9 +44,9 @@ class ScopedInitVk
4544 ~ScopedInitVk () { _skipInit = previousState; }
4645};
4746
48- static void UpdateInitPaths (NVSDK_NGX_FeatureCommonInfo* InFeatureInfo)
47+ [[nodiscard]] static NgxPathSnapshot::Owner UpdateInitPaths (NVSDK_NGX_FeatureCommonInfo* InFeatureInfo)
4948{
50- State::Instance (). NVNGX_FeatureInfo_Paths . clear () ;
49+ std::vector<std::wstring> initPaths ;
5150
5251 if (InFeatureInfo != nullptr )
5352 {
@@ -98,14 +97,14 @@ static void UpdateInitPaths(NVSDK_NGX_FeatureCommonInfo* InFeatureInfo)
9897
9998 // Override locations
10099 if (Config::Instance ()->DLSSFeaturePath .has_value ())
101- State::Instance (). NVNGX_FeatureInfo_Paths .push_back (Config::Instance ()->DLSSFeaturePath .value ());
100+ initPaths .push_back (Config::Instance ()->DLSSFeaturePath .value ());
102101
103102 // If DLSS path is overriden
104103 if (Config::Instance ()->NVNGX_DLSS_Library .has_value () && nvngxDlssPath.has_value ())
105- State::Instance (). NVNGX_FeatureInfo_Paths .push_back (nvngxDlssPath.value ().parent_path ().wstring ());
104+ initPaths .push_back (nvngxDlssPath.value ().parent_path ().wstring ());
106105
107106 // OptiDll Path
108- State::Instance (). NVNGX_FeatureInfo_Paths .push_back (Config::Instance ()->MainDllPath .value ());
107+ initPaths .push_back (Config::Instance ()->MainDllPath .value ());
109108
110109 // WAR: Doom Ethernal is sending junk data
111110 if (InFeatureInfo->PathListInfo .Length < 10 )
@@ -114,35 +113,29 @@ static void UpdateInitPaths(NVSDK_NGX_FeatureCommonInfo* InFeatureInfo)
114113 for (size_t i = 0 ; i < InFeatureInfo->PathListInfo .Length ; i++)
115114 {
116115 const wchar_t * path = InFeatureInfo->PathListInfo .Path [i];
117- State::Instance (). NVNGX_FeatureInfo_Paths .push_back (std::wstring (path));
116+ initPaths .push_back (std::wstring (path));
118117 }
119118 }
120119
121120 // Exe path
122- State::Instance (). NVNGX_FeatureInfo_Paths .push_back (exePath.wstring ());
121+ initPaths .push_back (exePath.wstring ());
123122
124123 // If DLSS path is not overriden
125124 if (!Config::Instance ()->NVNGX_DLSS_Library .has_value () && nvngxDlssPath.has_value ())
126- State::Instance (). NVNGX_FeatureInfo_Paths .push_back (nvngxDlssPath.value ().parent_path ().wstring ());
125+ initPaths .push_back (nvngxDlssPath.value ().parent_path ().wstring ());
127126
128127 // Add found locations
129128 if (nvngxDlssDPath.has_value ())
130- State::Instance (). NVNGX_FeatureInfo_Paths .push_back (nvngxDlssDPath.value ().parent_path ().wstring ());
129+ initPaths .push_back (nvngxDlssDPath.value ().parent_path ().wstring ());
131130
132131 if (nvngxDlssGPath.has_value ())
133- State::Instance (). NVNGX_FeatureInfo_Paths .push_back (nvngxDlssGPath.value ().parent_path ().wstring ());
132+ initPaths .push_back (nvngxDlssGPath.value ().parent_path ().wstring ());
134133
135- // Build pointer array
136- paths = new const wchar_t *[State::Instance ().NVNGX_FeatureInfo_Paths .size ()];
137- for (size_t i = 0 ; i < State::Instance ().NVNGX_FeatureInfo_Paths .size (); ++i)
138- {
139- paths[i] = State::Instance ().NVNGX_FeatureInfo_Paths [i].c_str ();
140- LOG_DEBUG (" Feature Path [{}]: {}" , i, wstring_to_string (State::Instance ().NVNGX_FeatureInfo_Paths [i]));
141- }
142-
143- InFeatureInfo->PathListInfo .Path = paths;
144- InFeatureInfo->PathListInfo .Length = (int ) State::Instance ().NVNGX_FeatureInfo_Paths .size ();
134+ auto owner = State::Instance ().NVNGX_FeatureInfo_Paths .Publish (std::move (initPaths));
135+ owner->Bind (InFeatureInfo->PathListInfo );
136+ return owner;
145137 }
138+ return {};
146139}
147140
148141NVSDK_NGX_API NVSDK_NGX_Result NVSDK_NGX_VULKAN_Init_Ext2 (
@@ -157,8 +150,8 @@ NVSDK_NGX_API NVSDK_NGX_Result NVSDK_NGX_VULKAN_Init_Ext2(
157150 if (InFeatureInfo != nullptr )
158151 std::memcpy (&localFeatureInfo, InFeatureInfo, sizeof (NVSDK_NGX_FeatureCommonInfo));
159152
160- if (!_skipInit)
161- UpdateInitPaths (&localFeatureInfo);
153+ // A delegated call borrows its outer call's still-live snapshot.
154+ const auto initPaths = _skipInit ? NgxPathSnapshot::Owner {} : UpdateInitPaths (&localFeatureInfo);
162155
163156 State::Instance ().NVNGX_ApplicationId = InApplicationId;
164157 State::Instance ().NVNGX_ApplicationDataPath = std::wstring (InApplicationDataPath);
@@ -273,8 +266,8 @@ NVSDK_NGX_API NVSDK_NGX_Result NVSDK_NGX_VULKAN_Init_Ext(unsigned long long InAp
273266 if (InFeatureInfo != nullptr )
274267 std::memcpy (&localFeatureInfo, InFeatureInfo, sizeof (NVSDK_NGX_FeatureCommonInfo));
275268
276- if (!_skipInit)
277- UpdateInitPaths (&localFeatureInfo);
269+ // A delegated call borrows its outer call's still-live snapshot.
270+ const auto initPaths = _skipInit ? NgxPathSnapshot::Owner {} : UpdateInitPaths (&localFeatureInfo);
278271
279272 if (Config::Instance ()->DLSSEnabled .value_or_default () && !_skipInit)
280273 {
@@ -324,8 +317,8 @@ NVSDK_NGX_API NVSDK_NGX_Result NVSDK_NGX_VULKAN_Init_ProjectID_Ext(
324317 if (InFeatureInfo != nullptr )
325318 std::memcpy (&localFeatureInfo, InFeatureInfo, sizeof (NVSDK_NGX_FeatureCommonInfo));
326319
327- if (!_skipInit)
328- UpdateInitPaths (&localFeatureInfo);
320+ // A delegated call borrows its outer call's still-live snapshot.
321+ const auto initPaths = _skipInit ? NgxPathSnapshot::Owner {} : UpdateInitPaths (&localFeatureInfo);
329322
330323 if (Config::Instance ()->DLSSEnabled .value_or_default () && !_skipInit)
331324 {
@@ -379,8 +372,8 @@ NVSDK_NGX_API NVSDK_NGX_Result NVSDK_NGX_VULKAN_Init(unsigned long long InApplic
379372 if (InFeatureInfo != nullptr )
380373 std::memcpy (&localFeatureInfo, InFeatureInfo, sizeof (NVSDK_NGX_FeatureCommonInfo));
381374
382- if (!_skipInit)
383- UpdateInitPaths (&localFeatureInfo);
375+ // A delegated call borrows its outer call's still-live snapshot.
376+ const auto initPaths = _skipInit ? NgxPathSnapshot::Owner {} : UpdateInitPaths (&localFeatureInfo);
384377
385378 if (Config::Instance ()->DLSSEnabled .value_or_default () && !_skipInit)
386379 {
@@ -430,8 +423,8 @@ NVSDK_NGX_VULKAN_Init_ProjectID(const char* InProjectId, NVSDK_NGX_EngineType In
430423 if (InFeatureInfo != nullptr )
431424 std::memcpy (&localFeatureInfo, InFeatureInfo, sizeof (NVSDK_NGX_FeatureCommonInfo));
432425
433- if (!_skipInit)
434- UpdateInitPaths (&localFeatureInfo);
426+ // A delegated call borrows its outer call's still-live snapshot.
427+ const auto initPaths = _skipInit ? NgxPathSnapshot::Owner {} : UpdateInitPaths (&localFeatureInfo);
435428
436429 if (Config::Instance ()->DLSSEnabled .value_or_default () && !_skipInit)
437430 {
0 commit comments