diff options
Diffstat (limited to '')
| -rw-r--r-- | src/yuzu/main.cpp | 12 | ||||
| -rw-r--r-- | src/yuzu/startup_checks.cpp | 53 |
2 files changed, 48 insertions, 17 deletions
diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index a2b11fdbf..69f9cdd9c 100644 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp | |||
| @@ -3852,19 +3852,9 @@ void GMainWindow::SetDiscordEnabled([[maybe_unused]] bool state) { | |||
| 3852 | 3852 | ||
| 3853 | int main(int argc, char* argv[]) { | 3853 | int main(int argc, char* argv[]) { |
| 3854 | bool has_broken_vulkan = false; | 3854 | bool has_broken_vulkan = false; |
| 3855 | #ifdef _WIN32 | 3855 | if (StartupChecks(argv[0], &has_broken_vulkan)) { |
| 3856 | char variable_contents[32]; | ||
| 3857 | const DWORD startup_check_var = | ||
| 3858 | GetEnvironmentVariable(STARTUP_CHECK_ENV_VAR, variable_contents, 32); | ||
| 3859 | const std::string variable_contents_s{variable_contents}; | ||
| 3860 | if (startup_check_var > 0 && variable_contents_s == "ON") { | ||
| 3861 | CheckVulkan(); | ||
| 3862 | return 0; | 3856 | return 0; |
| 3863 | } | 3857 | } |
| 3864 | StartupChecks(argv[0], &has_broken_vulkan); | ||
| 3865 | #elif YUZU_UNIX | ||
| 3866 | #error "Unimplemented" | ||
| 3867 | #endif | ||
| 3868 | 3858 | ||
| 3869 | Common::DetachedTasks detached_tasks; | 3859 | Common::DetachedTasks detached_tasks; |
| 3870 | MicroProfileOnThreadCreate("Frontend"); | 3860 | MicroProfileOnThreadCreate("Frontend"); |
diff --git a/src/yuzu/startup_checks.cpp b/src/yuzu/startup_checks.cpp index c860f0aa0..6bd895400 100644 --- a/src/yuzu/startup_checks.cpp +++ b/src/yuzu/startup_checks.cpp | |||
| @@ -8,6 +8,8 @@ | |||
| 8 | #include <processthreadsapi.h> | 8 | #include <processthreadsapi.h> |
| 9 | #include <windows.h> | 9 | #include <windows.h> |
| 10 | #elif defined(YUZU_UNIX) | 10 | #elif defined(YUZU_UNIX) |
| 11 | #include <errno.h> | ||
| 12 | #include <sys/wait.h> | ||
| 11 | #include <unistd.h> | 13 | #include <unistd.h> |
| 12 | #endif | 14 | #endif |
| 13 | 15 | ||
| @@ -36,9 +38,20 @@ void CheckVulkan() { | |||
| 36 | 38 | ||
| 37 | bool StartupChecks(const char* arg0, bool* has_broken_vulkan) { | 39 | bool StartupChecks(const char* arg0, bool* has_broken_vulkan) { |
| 38 | #ifdef _WIN32 | 40 | #ifdef _WIN32 |
| 41 | // Check environment variable to see if we are the child | ||
| 42 | char variable_contents[32]; | ||
| 43 | const DWORD startup_check_var = | ||
| 44 | GetEnvironmentVariable(STARTUP_CHECK_ENV_VAR, variable_contents, 32); | ||
| 45 | const std::string variable_contents_s{variable_contents}; | ||
| 46 | if (startup_check_var > 0 && variable_contents_s == "ON") { | ||
| 47 | CheckVulkan(); | ||
| 48 | return true; | ||
| 49 | } | ||
| 50 | |||
| 51 | // Set the startup variable for child processes | ||
| 39 | const bool env_var_set = SetEnvironmentVariableA(STARTUP_CHECK_ENV_VAR, "ON"); | 52 | const bool env_var_set = SetEnvironmentVariableA(STARTUP_CHECK_ENV_VAR, "ON"); |
| 40 | if (!env_var_set) { | 53 | if (!env_var_set) { |
| 41 | std::fprintf(stderr, "SetEnvironmentVariableA failed to set %s, %d\n", | 54 | std::fprintf(stderr, "SetEnvironmentVariableA failed to set %s with error %d\n", |
| 42 | STARTUP_CHECK_ENV_VAR, GetLastError()); | 55 | STARTUP_CHECK_ENV_VAR, GetLastError()); |
| 43 | return false; | 56 | return false; |
| 44 | } | 57 | } |
| @@ -53,15 +66,43 @@ bool StartupChecks(const char* arg0, bool* has_broken_vulkan) { | |||
| 53 | // wait until the processs exits | 66 | // wait until the processs exits |
| 54 | DWORD exit_code = STILL_ACTIVE; | 67 | DWORD exit_code = STILL_ACTIVE; |
| 55 | while (exit_code == STILL_ACTIVE) { | 68 | while (exit_code == STILL_ACTIVE) { |
| 56 | GetExitCodeProcess(process_info.hProcess, &exit_code); | 69 | const int err = GetExitCodeProcess(process_info.hProcess, &exit_code); |
| 70 | if (err == 0) { | ||
| 71 | std::fprintf(stderr, "GetExitCodeProcess failed with error %d\n", GetLastError()); | ||
| 72 | break; | ||
| 73 | } | ||
| 57 | } | 74 | } |
| 58 | 75 | ||
| 59 | *has_broken_vulkan = (exit_code != 0); | 76 | *has_broken_vulkan = (exit_code != 0); |
| 60 | 77 | ||
| 61 | CloseHandle(process_info.hProcess); | 78 | if (CloseHandle(process_info.hProcess) == 0) { |
| 62 | CloseHandle(process_info.hThread); | 79 | std::fprintf(stderr, "CloseHandle failed with error %d\n", GetLastError()); |
| 80 | } | ||
| 81 | if (CloseHandle(process_info.hThread) == 0) { | ||
| 82 | std::fprintf(stderr, "CloseHandle failed with error %d\n", GetLastError()); | ||
| 83 | } | ||
| 84 | |||
| 85 | #elif defined(YUZU_UNIX) | ||
| 86 | const pid_t pid = fork(); | ||
| 87 | if (pid == 0) { | ||
| 88 | CheckVulkan(); | ||
| 89 | return true; | ||
| 90 | } else if (pid == -1) { | ||
| 91 | const int err = errno; | ||
| 92 | std::fprintf(stderr, "fork failed with error %d\n", err); | ||
| 93 | return false; | ||
| 94 | } | ||
| 95 | |||
| 96 | int status; | ||
| 97 | const int r_val = wait(&status); | ||
| 98 | if (r_val == -1) { | ||
| 99 | const int err = errno; | ||
| 100 | std::fprintf(stderr, "wait failed with error %d\n", err); | ||
| 101 | return false; | ||
| 102 | } | ||
| 103 | *has_broken_vulkan = (status != 0); | ||
| 63 | #endif | 104 | #endif |
| 64 | return true; | 105 | return false; |
| 65 | } | 106 | } |
| 66 | 107 | ||
| 67 | #ifdef _WIN32 | 108 | #ifdef _WIN32 |
| @@ -87,7 +128,7 @@ bool SpawnChild(const char* arg0, PROCESS_INFORMATION* pi) { | |||
| 87 | pi // lpProcessInformation | 128 | pi // lpProcessInformation |
| 88 | ); | 129 | ); |
| 89 | if (!process_created) { | 130 | if (!process_created) { |
| 90 | std::fprintf(stderr, "CreateProcessA failed, %d\n", GetLastError()); | 131 | std::fprintf(stderr, "CreateProcessA failed with error %d\n", GetLastError()); |
| 91 | return false; | 132 | return false; |
| 92 | } | 133 | } |
| 93 | 134 | ||