Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CREATE_WAITABLE_TIMER_HIGH_RESOLUTION define to avoid compile errors for low system versions #1054

Closed
wants to merge 1 commit into from

Conversation

ggqshr
Copy link

@ggqshr ggqshr commented Mar 22, 2023

Description

Sunshine use CreateWaitableTimerEx api and CREATE_WAITABLE_TIMER_HIGH_RESOLUTION flag to replace busy loop frame capture

// Use CREATE_WAITABLE_TIMER_HIGH_RESOLUTION if supported (Windows 10 1809+)
HANDLE timer = CreateWaitableTimerEx(nullptr, nullptr, CREATE_WAITABLE_TIMER_HIGH_RESOLUTION, TIMER_ALL_ACCESS);
if(!timer) {
timer = CreateWaitableTimerEx(nullptr, nullptr, 0, TIMER_ALL_ACCESS);
if(!timer) {
auto winerr = GetLastError();
BOOST_LOG(error) << "Failed to create timer: "sv << winerr;
return capture_e::error;
}
}

As commented in the above code, CREATE_WAITABLE_TIMER_HIGH_RESOLUTION is only available on higher versions of systems. The above code is able to handle version-compatible behavior correctly at runtime, but when I compile on a lower version of the system that will report the following error:

error: 'CREATE_WAITABLE_TIMER_HIGH_RESOLUTION' was not declared in this scope; did you mean 'CREATE_WAITABLE_TIMER_MANUAL_RESET'

To avoid compile errors, we can add the following code just like python/cpython#89592 (comment)

#ifndef CREATE_WAITABLE_TIMER_HIGH_RESOLUTION
#define CREATE_WAITABLE_TIMER_HIGH_RESOLUTION 0x00000002
#endif

Screenshot

Issues Fixed or Closed

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Dependency update (updates to dependencies)
  • Documentation update (changes to documentation)
  • Repository update (changes to repository files, e.g. .github/...)

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated the in code docstring/documentation-blocks for new or existing methods/components

Branch Updates

LizardByte requires that branches be up-to-date before merging. This means that after any PR is merged, this branch
must be updated before it can be merged. You must also
Allow edits from maintainers.

  • I want maintainers to keep my branch updated

@CLAassistant
Copy link

CLAassistant commented Mar 22, 2023

CLA assistant check
All committers have signed the CLA.

@ggqshr ggqshr force-pushed the avoid_compile_error branch from 5ea1dde to f267b76 Compare March 22, 2023 03:16
@psyke83
Copy link
Collaborator

psyke83 commented Mar 23, 2023

What version of Windows are you attempting to compile on? The definition is provided by mingw's synchapi.h header for Vista or later. Given that Microsoft's Desktop Duplication API is only supported on Windows 8 or later, my guess is that you just need to update your MSYS2 / MinGW-w64 installation to a newer version that includes the definition in the aforementioned header.

@ggqshr
Copy link
Author

ggqshr commented Mar 24, 2023

What version of Windows are you attempting to compile on?

win10 21H2

You're right, This problem can be solved by update MYSY2, i tried it on another new computer(also win10 21H2), but the computer where the compilation error occurred is not very convenient to upgrade the MYSY2 version, but I can manually add this define to make it compile successfully.

@psyke83
Copy link
Collaborator

psyke83 commented Mar 24, 2023

The latest MSYS2 release still supports Windows 8.1, so I think it's reasonable that a more recent version is installed for the purpose of compiling Sunshine rather than adding duplicate definitions to the Sunshine code. It's probably a good idea to keep your toolchain as updated as possible, especially when you consider that you could be also compiling against insecure security libraries such as OpenSSL, etc.

I think this can be closed, given that recent MSYS2 installations can run even on Windows 8.1. Thanks for your understanding.

@psyke83 psyke83 closed this Mar 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants