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

Check API before trying to disable border on WGC capture #2825

Merged
merged 1 commit into from
Jul 10, 2024

Conversation

ns6089
Copy link
Contributor

@ns6089 ns6089 commented Jul 8, 2024

Description

Using the new WGC capture method on Windows 10 currently causes a segmentation fault.
This should resolve it.

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

@ReenigneArcher
Copy link
Member

Do you think we should just remove the whole try/catch, especially considering the catch isn't working anyway.

@ns6089
Copy link
Contributor Author

ns6089 commented Jul 8, 2024

Force-pushed an update, now it looks like this

      return -1;
    }

    /*
    Currently this triggers a segmentation fault on Windows 10
    According to
    https://learn.microsoft.com/en-us/uwp/api/windows.graphics.capture.graphicscapturesession.isborderrequired
    we are expected to request user's consent first, but doing
    winrt::GraphicsCaptureAccess::RequestAccessAsync(winrt::GraphicsCaptureAccessKind::Borderless);
    accomplishes nothing, probably requiring an entry in app's manifest

    try {
      capture_session.IsBorderRequired(false);
    }
    catch (winrt::hresult_error &e) {
      BOOST_LOG(warning) << "Screen capture may not be fully supported on this device for this release of Windows: failed to disable border around capture area: [0x"sv << util::hex(e.code()).to_string_view() << ']';
    }
    */

    try {
      capture_session.StartCapture();

@cgutman
Copy link
Collaborator

cgutman commented Jul 9, 2024

Is there a good reason to even allow WGC usage on Windows 10? I believe it was missing useful functionality like GraphicsCaptureSession.IsCursorCaptureEnabled and GraphicsCaptureSession.IsBorderRequired prior to Windows 11.

@ns6089
Copy link
Contributor Author

ns6089 commented Jul 9, 2024

Well, some support is better than no support at all. And it performs rather well outside of those two(?) things.
I think we can query the presence of these properties with winrt::Windows::Foundation::Metadata::ApiInformation::IsPropertyPresent() and handle them in a way that doesn't hinder Windows 11. I will check it.

@ns6089 ns6089 changed the title Temporary enable border on WGC capture Check API before trying to disable border on WGC capture Jul 9, 2024
@ns6089
Copy link
Contributor Author

ns6089 commented Jul 9, 2024

Yeah, checking for property presence resolves the segfault. Pushed a proper fix. Now we just need to confirm that the fix works alright on Windows 11.
GraphicsCaptureSession.IsCursorCaptureEnabled doesn't seem to be a problem on reasonably updated Windows 10, at least it functions correctly on my system.

Otherwise it causes segmentation fault on Windows 10.
Copy link

codecov bot commented Jul 10, 2024

Codecov Report

Attention: Patch coverage is 0% with 3 lines in your changes missing coverage. Please review.

Project coverage is 8.99%. Comparing base (5cea1e1) to head (bed96ae).
Report is 141 commits behind head on master.

Files with missing lines Patch % Lines
src/platform/windows/display_wgc.cpp 0.00% 3 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           master   #2825    +/-   ##
=======================================
  Coverage    8.98%   8.99%            
=======================================
  Files          95      95            
  Lines       17304   17312     +8     
  Branches     8232    8236     +4     
=======================================
+ Hits         1555    1557     +2     
- Misses      12884   13046   +162     
+ Partials     2865    2709   -156     
Flag Coverage Δ
Linux 6.80% <ø> (+0.01%) ⬆️
Windows 4.16% <0.00%> (-0.01%) ⬇️
macOS-12 10.11% <ø> (+0.02%) ⬆️
macOS-13 10.00% <ø> (-0.01%) ⬇️
macOS-14 10.31% <ø> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/platform/windows/display_wgc.cpp 4.57% <0.00%> (-0.07%) ⬇️

... and 22 files with indirect coverage changes

@ReenigneArcher
Copy link
Member

Now we just need to confirm that the fix works alright on Windows 11.

I tested, and it's working fine.

@ReenigneArcher ReenigneArcher enabled auto-merge (squash) July 10, 2024 02:47
@ReenigneArcher ReenigneArcher merged commit 30748dd into LizardByte:master Jul 10, 2024
48 of 49 checks passed
KuleRucket pushed a commit to KuleRucket/Sunshine that referenced this pull request Oct 9, 2024
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