Skip to content

Commit becbb9e

Browse files
committed
WPF - Exception on wakeup from sleep
Issue #4426
1 parent 2e2b53f commit becbb9e

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

CefSharp.Wpf/Rendering/WritableBitmapRenderHandler.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,14 @@ protected override void CreateOrUpdateBitmap(bool isPopup, Rect dirtyRect, IntPt
160160
return;
161161
}
162162

163+
var sourceBufferPtr = sourceBuffer.DangerousGetHandle();
164+
165+
// Issue https://github.com/cefsharp/CefSharp/issues/4426
166+
if (sourceBufferPtr == IntPtr.Zero)
167+
{
168+
return;
169+
}
170+
163171
//By default we'll only update the dirty rect, for those that run into a MILERR_WIN32ERROR Exception (#2035)
164172
//it's desirably to either upgrade to a newer .Net version (only client runtime needs to be installed, not compiled
165173
//against a newer version. Or invalidate the whole bitmap
@@ -169,7 +177,7 @@ protected override void CreateOrUpdateBitmap(bool isPopup, Rect dirtyRect, IntPt
169177
var sourceRect = new Int32Rect(dirtyRect.X, dirtyRect.Y, dirtyRect.Width, dirtyRect.Height);
170178

171179
bitmap.Lock();
172-
bitmap.WritePixels(sourceRect, sourceBuffer.DangerousGetHandle(), noOfBytes, stride, dirtyRect.X, dirtyRect.Y);
180+
bitmap.WritePixels(sourceRect, sourceBufferPtr, noOfBytes, stride, dirtyRect.X, dirtyRect.Y);
173181
bitmap.Unlock();
174182
}
175183
else
@@ -178,7 +186,7 @@ protected override void CreateOrUpdateBitmap(bool isPopup, Rect dirtyRect, IntPt
178186
var sourceRect = new Int32Rect(0, 0, width, height);
179187

180188
bitmap.Lock();
181-
bitmap.WritePixels(sourceRect, sourceBuffer.DangerousGetHandle(), noOfBytes, stride);
189+
bitmap.WritePixels(sourceRect, sourceBufferPtr, noOfBytes, stride);
182190
bitmap.Unlock();
183191
}
184192
}

0 commit comments

Comments
 (0)