@@ -89,7 +89,7 @@ namespace {
8989thread_local bool should_inject_next_call = false ;
9090
9191bool should_log_all_calls = false ;
92- std::unique_ptr<std::wostream> log_all_calls_stream;
92+ std::wofstream log_all_calls_stream{} ;
9393std::mutex log_all_calls_stream_mutex{};
9494
9595std::unordered_map<FName, utils::StringViewMap<std::wstring, List>> hooks{};
@@ -98,17 +98,17 @@ void log_all_calls(bool should_log) {
9898 // Only keep this file stream open while we need it
9999 if (should_log) {
100100 const std::lock_guard<std::mutex> lock (log_all_calls_stream_mutex);
101- log_all_calls_stream = std::make_unique<std::wofstream> (
101+ log_all_calls_stream. open (
102102 utils::get_this_dll ().parent_path ()
103103 / config::get_str (" unrealsdk.log_all_calls_file" ).value_or (" unrealsdk.calls.tsv" ),
104- std::ofstream ::trunc);
104+ std::wofstream ::trunc);
105105 }
106106
107107 should_log_all_calls = should_log;
108108
109109 if (!should_log) {
110110 const std::lock_guard<std::mutex> lock (log_all_calls_stream_mutex);
111- log_all_calls_stream = nullptr ;
111+ log_all_calls_stream. close () ;
112112 }
113113}
114114
@@ -219,11 +219,14 @@ const List* preprocess_hook(std::wstring_view source, const UFunction* func, con
219219 std::wstring func_name{};
220220
221221 if (should_log_all_calls) {
222- func_name = func->get_path_name ();
223- auto obj_name = obj->get_path_name ();
222+ // Extra safety check
223+ if (log_all_calls_stream.is_open ()) {
224+ func_name = func->get_path_name ();
225+ auto obj_name = obj->get_path_name ();
224226
225- const std::lock_guard<std::mutex> lock (log_all_calls_stream_mutex);
226- *log_all_calls_stream << source << L' \t ' << func_name << L' \t ' << obj_name << L' \n ' ;
227+ const std::lock_guard<std::mutex> lock (log_all_calls_stream_mutex);
228+ log_all_calls_stream << source << L' \t ' << func_name << L' \t ' << obj_name << L' \n ' ;
229+ }
227230 }
228231
229232 // Check if anything matches the function FName
0 commit comments