Help the compiler not fuck up. If I keep the thread spawn in the constructor, optimizations will get rid of the if on "!fileToLoad.empty()" for some reason.

This commit is contained in:
IrisZ64
2025-12-17 22:04:05 +01:00
parent f870d8f979
commit ebeb5f2cb5
2 changed files with 5 additions and 6 deletions

View File

@@ -10,10 +10,6 @@ KaizenGui::KaizenGui() noexcept : window("Kaizen", 800, 600), settingsWindow(win
SDL_InitSubSystem(SDL_INIT_GAMEPAD); SDL_InitSubSystem(SDL_INIT_GAMEPAD);
SDL_AddGamepadMapping(gamecontrollerdb_str); SDL_AddGamepadMapping(gamecontrollerdb_str);
std::thread fileWorker(&KaizenGui::FileWorker, this);
fileWorker.detach();
} }
KaizenGui::~KaizenGui() { KaizenGui::~KaizenGui() {
@@ -391,7 +387,7 @@ void KaizenGui::RenderUI() {
fileDialogOpen = false; fileDialogOpen = false;
constexpr SDL_DialogFileFilter filters[] = {{"All files", "*"}, {"Nintendo 64 executable", "n64;z64;v64"}, {"Nintendo 64 executable archive", "rar;tar;zip;7z"}}; constexpr SDL_DialogFileFilter filters[] = {{"All files", "*"}, {"Nintendo 64 executable", "n64;z64;v64"}, {"Nintendo 64 executable archive", "rar;tar;zip;7z"}};
SDL_ShowOpenFileDialog([](void *userdata, const char * const *filelist, int) { SDL_ShowOpenFileDialog([](void *userdata, const char * const *filelist, int) {
const auto kaizen = static_cast<KaizenGui*>(userdata); auto kaizen = static_cast<KaizenGui*>(userdata);
if (!filelist) { if (!filelist) {
panic("An error occured: {}", SDL_GetError()); panic("An error occured: {}", SDL_GetError());
@@ -405,6 +401,9 @@ void KaizenGui::RenderUI() {
kaizen->fileToLoad = *filelist; kaizen->fileToLoad = *filelist;
kaizen->shouldDisplaySpinner = true; kaizen->shouldDisplaySpinner = true;
std::thread fileWorker(&KaizenGui::FileWorker, kaizen);
fileWorker.detach();
}, this, window.getHandle(), filters, 3, nullptr, false); }, this, window.getHandle(), filters, 3, nullptr, false);
} }

View File

@@ -32,7 +32,7 @@ private:
bool fileDialogOpen = false; bool fileDialogOpen = false;
bool quit = false; bool quit = false;
bool shouldDisplaySpinner = false; bool shouldDisplaySpinner = false;
std::string fileToLoad; std::string fileToLoad = "";
void RenderUI(); void RenderUI();
void HandleInput(const SDL_Event &event); void HandleInput(const SDL_Event &event);
void QueryDevices(const SDL_Event &event); void QueryDevices(const SDL_Event &event);