Skip to content
This repository was archived by the owner on Apr 29, 2024. It is now read-only.

Commit cd1a330

Browse files
committed
[linux] fix for mimalloc_fun for Windows and Linux
Old bad behavior. In Windows and Linux mimalloc_fun will be called >= 2 times: 1) Initialization will remove old file and will keep alive mimalloc_log_path until you exit. 2) Not sure, but I did not see in Windows any other messages, but it's totally possible and I have at least one in Linux. 3) When you press exit you: firstly go to the end of main "return EXIT_SUCCESS;" and after that calling mimalloc_fun In Windows after exiting main and running mimalloc_fun I got mimalloc_log_path.empty() == true: it remove all previous messages and write only last block of messages. In Linux after exiting main and running mimalloc_fun I got mimalloc_log_path.empty() == false, but it contain random non ascii chars => it will not remove previous messages in mimalloc.log but will create random non ascii filename in current folder New behavior. 1) For Windows and Linux mimalloc_fun will get "init" arg only once in main when calling mi_register_output and then it will remove old mimalloc.log. 2) All other calls will write to mimalloc.log without removing it. 3) I have to remove static in GetStashPath() and from "static std::filesystem::path mimalloc_log_path;" to not get random non ascii in Linux.
1 parent 123280b commit cd1a330

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

src/apps/engine/src/main.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@ void RunFrameWithOverflowCheck()
5757

5858
void mimalloc_fun(const char *msg, void *arg)
5959
{
60-
static std::filesystem::path mimalloc_log_path;
61-
if (mimalloc_log_path.empty())
60+
std::filesystem::path mimalloc_log_path;
61+
mimalloc_log_path = fs::GetLogsPath() / "mimalloc.log";
62+
if (arg && ((std::string *)arg)->compare("init") == 0)
6263
{
63-
mimalloc_log_path = fs::GetLogsPath() / "mimalloc.log";
6464
std::error_code ec;
6565
remove(mimalloc_log_path, ec);
6666
}
@@ -133,7 +133,10 @@ int main(int argc, char *argv[])
133133
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error", "Another instance is already running!", nullptr);
134134
return EXIT_SUCCESS;
135135
}
136-
mi_register_output(mimalloc_fun, nullptr);
136+
std::string *mi_arg = new std::string("init");
137+
mi_register_output(mimalloc_fun, (void *)mi_arg);
138+
mi_arg->clear();
139+
std::destroy_at(mi_arg);
137140
mi_option_set(mi_option_show_errors, 1);
138141
mi_option_set(mi_option_show_stats, 1);
139142
mi_option_set(mi_option_eager_commit, 1);

src/libs/util/include/storm/fs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ using namespace std::filesystem;
1515

1616
inline path GetStashPath()
1717
{
18-
static path path;
18+
path path;
1919
if (path.empty())
2020
{
2121
#ifdef _WIN32 // FIX_LINUX SHGetKnownFolderPath

0 commit comments

Comments
 (0)