Skip to content

Commit 1e4430a

Browse files
committed
Recreate DDupl adapters when an adapter's output has no handle
This happens under unclear circumstances when switching two screes beween extended and duplicated mode. Contrary to the error description, it goes away only once the user switched back.
1 parent 5b4d33d commit 1e4430a

File tree

4 files changed

+27
-4
lines changed

4 files changed

+27
-4
lines changed

Software/grab/DDuplGrabber.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,11 @@ bool anyWidgetOnThisMonitor(HMONITOR monitor, const QList<GrabWidget *> &grabWid
221221
}
222222

223223
QList< ScreenInfo > * DDuplGrabber::screensWithWidgets(QList< ScreenInfo > * result, const QList<GrabWidget *> &grabWidgets)
224+
{
225+
return __screensWithWidgets(result, grabWidgets);
226+
}
227+
228+
QList< ScreenInfo > * DDuplGrabber::__screensWithWidgets(QList< ScreenInfo > * result, const QList<GrabWidget *> &grabWidgets, bool noRecursion)
224229
{
225230
result->clear();
226231

@@ -237,6 +242,17 @@ QList< ScreenInfo > * DDuplGrabber::screensWithWidgets(QList< ScreenInfo > * res
237242
{
238243
DXGI_OUTPUT_DESC outputDesc;
239244
output->GetDesc(&outputDesc);
245+
if (outputDesc.Monitor == NULL) {
246+
if (!noRecursion) {
247+
qWarning() << Q_FUNC_INFO << "Found a monitor with NULL handle. Recreating adapters";
248+
recreateAdapters();
249+
return __screensWithWidgets(result, grabWidgets, true);
250+
} else {
251+
qWarning() << Q_FUNC_INFO << "Found a monitor with NULL handle (after recreation)";
252+
continue;
253+
}
254+
}
255+
240256
if (anyWidgetOnThisMonitor(outputDesc.Monitor, grabWidgets))
241257
{
242258
ScreenInfo screenInfo;
@@ -357,6 +373,7 @@ bool DDuplGrabber::_reallocate(const QList< ScreenInfo > &grabScreens, bool noRe
357373
}
358374

359375
BOOL success = SetThreadDesktop(screensaverDesk);
376+
CloseHandle(screensaverDesk);
360377
if (!success) {
361378
qCritical(Q_FUNC_INFO " Failed to set grab desktop: %x", GetLastError());
362379
return false;
@@ -647,7 +664,7 @@ GrabResult DDuplGrabber::grabScreens()
647664
screenData->duplication->ReleaseFrame();
648665
}
649666

650-
if (!anyUpdate)
667+
if (!anyUpdate)
651668
return GrabResultFrameNotReady;
652669
}
653670
catch (_com_error e)

Software/grab/GrabberBase.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,11 @@ void GrabberBase::grab()
119119
QList< ScreenInfo > screens2Grab;
120120
screens2Grab.reserve(5);
121121
screensWithWidgets(&screens2Grab, *_context->grabWidgets);
122+
if (screens2Grab.empty()) {
123+
qCritical() << Q_FUNC_INFO << "No screens with widgets found";
124+
emit frameGrabAttempted(GrabResultError);
125+
return;
126+
}
122127
if (isReallocationNeeded(screens2Grab)) {
123128
DEBUG_LOW_LEVEL << Q_FUNC_INFO << "reallocating";
124129
if (!reallocate(screens2Grab)) {

Software/grab/include/DDuplGrabber.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,10 @@ public slots:
7474
protected slots:
7575
virtual GrabResult grabScreens();
7676
virtual bool reallocate(const QList< ScreenInfo > &grabScreens);
77-
virtual bool _reallocate(const QList< ScreenInfo > &grabScreens, bool noRecursion = false);
77+
bool _reallocate(const QList< ScreenInfo > &grabScreens, bool noRecursion = false);
7878

7979
virtual QList< ScreenInfo > * screensWithWidgets(QList< ScreenInfo > * result, const QList<GrabWidget *> &grabWidgets);
80+
QList< ScreenInfo > * __screensWithWidgets(QList< ScreenInfo > * result, const QList<GrabWidget *> &grabWidgets, bool noRecursion = false);
8081

8182
virtual bool isReallocationNeeded(const QList< ScreenInfo > &grabScreens) const;
8283

Software/src/version.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@
2727
#pragma once
2828

2929
// Current version of Lightpack software
30-
#define VERSION_STR "5.11.2.16"
30+
#define VERSION_STR "5.11.2.17"
3131

3232
// Resource defines using in Lightpack.rc
33-
#define VER_FILEVERSION 5,11,2,16
33+
#define VER_FILEVERSION 5,11,2,17
3434
#define VER_PRODUCTVERSION VER_FILEVERSION
3535

3636
#define VER_FILEVERSION_STR VERSION_STR "\0"

0 commit comments

Comments
 (0)