Skip to content

Conversation

@jamespearce2006
Copy link
Contributor

The OnPaint call arrives on a thread other than the UI thread. This means it is possible that the InvokeRenderAsync method, which is dispatched back to the UI thread, will get called after the Dispose method. In this case, a NullReferenceException is thrown, because FileMappingHandle is no longer set.

Because the OnPaint arrives on a thread other than the UI thread, it the
bitmap rendering process can occur after Dispose() has been called.
@jamespearce2006 jamespearce2006 changed the title WPF - Handle case where Bitmap in WpfBitmapInfo is IntPtr.Zero WPF - Handle case where Bitmap in WpfBitmapInfo is null May 5, 2015
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer to eval == first, flows better when reading code.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CreateBitmap() is usually called after the bitmap has already been cleared. In the scenario your trying to handle hear is it possible for bitmap != null?

Ideally would fail fast, have a code block like this as the first operation.

// Unable to create bitmap without valid File Handle (Most likely control is being disposed)
if (FileMappingHandle == IntPtr.Zero)
{
  return null;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think my update fulfils your request. Let me know.

On 5 May 2015 at 22:54, Alex Maitland notifications@github.com wrote:

In CefSharp.Wpf/Rendering/InteropBitmapInfo.cs
#1003 (comment):

     }

     public override BitmapSource CreateBitmap()
     {
         var stride = Width * BytesPerPixel;
  •        Bitmap = (InteropBitmap)Imaging.CreateBitmapSourceFromMemorySection(FileMappingHandle, Width, Height, PixelFormat, stride, 0);
    
  •        if (FileMappingHandle == IntPtr.Zero)
    
  •        {
    
  •            ClearBitmap();
    

CreateBitmap() is usually called after the bitmap has already been
cleared. In the scenario your trying to handle hear is it possible for bitmap
!= null?

Ideally would fail fast, have a code block like this as the first
operation.

// Unable to create bitmap without valid File Handle (Most likely control is being disposed)if (FileMappingHandle == IntPtr.Zero)
{
return null;
}


Reply to this email directly or view it on GitHub
https://github.com/cefsharp/CefSharp/pull/1003/files#r29717350.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Close 😄 I'll remove the else (redundant) and move the stride calculation after the if when it's eventually time to merge this 👍

@amaitland amaitland added this to the 39.0.2 milestone May 5, 2015
@amaitland amaitland merged commit 6fa4b47 into cefsharp:master May 6, 2015
amaitland added a commit that referenced this pull request May 6, 2015
…the rare case where it's been disposed of and the async OnPaint is called after the file handles have been released

Related to #1003
@amaitland
Copy link
Member

Applied a similar change to WritableBitmapInfo see 561507b

@amaitland amaitland changed the title WPF - Handle case where Bitmap in WpfBitmapInfo is null WPF - Handle case where Bitmap in InteropBitmapInfo is null May 6, 2015
@amaitland amaitland added the wpf WPF Implementation label May 6, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

wpf WPF Implementation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants