Skip to content

Commit

Permalink
Fix for #310 : Null Pointer Exception on DisplayRecordingSource.MainM…
Browse files Browse the repository at this point in the history
…onitor
  • Loading branch information
sskodje committed Aug 11, 2024
1 parent fe00a9e commit 8ae3b75
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
18 changes: 13 additions & 5 deletions ScreenRecorderLib/RecordingSources.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,15 +199,23 @@ namespace ScreenRecorderLib {
bool _isBorderRequired = true;
String^ _deviceName;
public:
/// <summary>
/// Returns a recording source for the main display output. If no display output is available, it returns NULL.
/// </summary>
static property DisplayRecordingSource^ MainMonitor {
DisplayRecordingSource^ get() {
DisplayRecordingSource^ source = gcnew DisplayRecordingSource();
IDXGIOutput* output;
GetMainOutput(&output);
DXGI_OUTPUT_DESC outputDesc;
output->GetDesc(&outputDesc);
source->DeviceName = gcnew String(outputDesc.DeviceName);
return source;
HRESULT hr = GetMainOutput(&output);
if (SUCCEEDED(hr)) {
DXGI_OUTPUT_DESC outputDesc;
output->GetDesc(&outputDesc);
source->DeviceName = gcnew String(outputDesc.DeviceName);
return source;
}
else {
return nullptr;
}
}
}
/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion ScreenRecorderLibNative/DX.util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ HRESULT GetOutputRectsForRecordingSources(_In_ const std::vector<RECORDING_SOURC
}

HRESULT GetMainOutput(_Outptr_result_maybenull_ IDXGIOutput **ppOutput) {
HRESULT hr = S_FALSE;
HRESULT hr = DXGI_ERROR_NOT_FOUND;
if (ppOutput) {
*ppOutput = nullptr;
}
Expand Down

0 comments on commit 8ae3b75

Please sign in to comment.