Skip to content

Commit

Permalink
Temporary diagnostic details paid off
Browse files Browse the repository at this point in the history
This reverts commit 12583e9.
  • Loading branch information
jnm2 committed Feb 23, 2021
1 parent 12583e9 commit 03e6c93
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 42 deletions.
34 changes: 2 additions & 32 deletions src/Techsola.InstantReplay/Frame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ public void Overwrite(
bitmap.Dispose();
}

Kernel32.SetLastError(0xDEADBEEF);
bitmap = Gdi32.CreateDIBSection(bitmapDC, new()
{
bmiHeader =
Expand All @@ -61,36 +60,15 @@ public void Overwrite(
biPlanes = 1,
biBitCount = BitsPerPixel,
},
}, Gdi32.DIB.RGB_COLORS, ppvBits: out _, hSection: IntPtr.Zero, offset: 0);

if (bitmap.IsInvalid)
{
var lastError = Marshal.GetLastWin32Error();
if ((uint)lastError == 0xDEADBEEF)
{
var flushSucceeded = Gdi32.GdiFlush();
var flushError = Marshal.GetLastWin32Error();
throw new Win32Exception($"CreateDIBSection returned false but did not set the last error.");
}

throw new Win32Exception($"CreateDIBSection failed with last error code {lastError}");
}
}, Gdi32.DIB.RGB_COLORS, ppvBits: out _, hSection: IntPtr.Zero, offset: 0).ThrowLastErrorIfInvalid();
}

Gdi32.SelectObject(bitmapDC, bitmap).ThrowWithoutLastErrorAvailableIfInvalid(nameof(Gdi32.SelectObject));

retryBitBlt:
Kernel32.SetLastError(0xDEADBEEF);
if (!Gdi32.BitBlt(bitmapDC, 0, 0, windowMetrics.ClientWidth, windowMetrics.ClientHeight, windowDC, 0, 0, Gdi32.RasterOperation.SRCCOPY))
{
var lastError = Marshal.GetLastWin32Error();
if ((uint)lastError == 0xDEADBEEF)
{
var flushSucceeded = Gdi32.GdiFlush();
var flushError = Marshal.GetLastWin32Error();
throw new Win32Exception($"BitBlt returned false but did not set the last error. GdiFlush(): {flushSucceeded}. Last error after GdiFlush: {flushError}");
}

if ((ERROR)lastError is ERROR.INVALID_WINDOW_HANDLE or ERROR.DC_NOT_FOUND)
{
windowDC.Dispose();
Expand All @@ -107,15 +85,7 @@ public void Overwrite(
goto retryBitBlt;
}

if (lastError != 0)
{
var flushSucceeded = Gdi32.GdiFlush();
var flushError = Marshal.GetLastWin32Error();

var isWindowVisible = User32.IsWindowVisible(windowDC.HWnd);
using var dcHandle = User32.GetDC(windowDC.HWnd);
throw new Win32Exception(lastError, $"BitBlt failed with last error code {lastError}. GdiFlush(): {flushSucceeded}. Last error after GdiFlush: {flushError}. IsWindowVisible({windowDC.HWnd}): {isWindowVisible}. GetDC({windowDC.HWnd}): {dcHandle.DangerousGetHandle()}");
}
if (lastError != 0) throw new Win32Exception(lastError);
needsGdiFlush = true;
}
else
Expand Down
10 changes: 0 additions & 10 deletions src/Techsola.InstantReplay/Native/Kernel32.cs

This file was deleted.

0 comments on commit 03e6c93

Please sign in to comment.