diff options
author | Loïc Guilloux <glx22@users.noreply.github.com> | 2021-02-09 21:21:57 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-09 21:21:57 +0100 |
commit | f1f281b318dc562d5741b55ff25198f3f1602312 (patch) | |
tree | d8b437c76b988b1db9dee3b95ac7c6fa1927134c /src/os/windows | |
parent | 395e015282279e95910128ebcd221879a22f9421 (diff) | |
download | openttd-f1f281b318dc562d5741b55ff25198f3f1602312.tar.xz |
Fix: [Win32] Set minimum resolution for timers to 1ms. (#8660)
Diffstat (limited to 'src/os/windows')
-rw-r--r-- | src/os/windows/crashlog_win.cpp | 4 | ||||
-rw-r--r-- | src/os/windows/win32.cpp | 8 |
2 files changed, 12 insertions, 0 deletions
diff --git a/src/os/windows/crashlog_win.cpp b/src/os/windows/crashlog_win.cpp index 872e472d5..b5916dd26 100644 --- a/src/os/windows/crashlog_win.cpp +++ b/src/os/windows/crashlog_win.cpp @@ -21,6 +21,7 @@ #include <windows.h> #include <signal.h> +#include <timeapi.h> #include "../../safeguards.h" @@ -540,6 +541,9 @@ void *_safe_esp = nullptr; static LONG WINAPI ExceptionHandler(EXCEPTION_POINTERS *ep) { + /* Restore system timer resolution. */ + timeEndPeriod(1); + /* Disable our event loop. */ SetWindowLongPtr(GetActiveWindow(), GWLP_WNDPROC, (LONG_PTR)&DefWindowProc); diff --git a/src/os/windows/win32.cpp b/src/os/windows/win32.cpp index 6576ea20d..8783b3762 100644 --- a/src/os/windows/win32.cpp +++ b/src/os/windows/win32.cpp @@ -18,6 +18,7 @@ #define NO_SHOBJIDL_SORTDIRECTION // Avoid multiple definition of SORT_ASCENDING #include <shlobj.h> /* SHGetFolderPath */ #include <shellapi.h> +#include <timeapi.h> #include "win32.h" #include "../../fios.h" #include "../../core/alloc_func.hpp" @@ -413,6 +414,9 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi int argc; char *argv[64]; // max 64 command line arguments + /* Set system timer resolution to 1ms. */ + timeBeginPeriod(1); + CrashLog::InitialiseCrashLog(); #if defined(UNICODE) @@ -440,6 +444,10 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi for (int i = 0; i < argc; i++) ValidateString(argv[i]); openttd_main(argc, argv); + + /* Restore system timer resolution. */ + timeEndPeriod(1); + free(cmdline); return 0; } |