Skip to content

Commit

Permalink
Better handling of paint failures
Browse files Browse the repository at this point in the history
  • Loading branch information
cyotek committed Jan 16, 2020
1 parent edd0f20 commit 1003c62
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,13 @@
# Cyotek ImageBox Change Log

## 1.2.2

### Fixed

* Any exception during image painting will now be caught, and the error text printed
in lieu of the image
* Fixed a crash that could occur when dragging a selection if the selection was empty

## 1.2

### Changed
Expand Down
10 changes: 3 additions & 7 deletions Cyotek.Windows.Forms.ImageBox/ImageBox.cs
Expand Up @@ -7,7 +7,7 @@
namespace Cyotek.Windows.Forms
{
// Cyotek ImageBox
// Copyright (c) 2010-2017 Cyotek Ltd.
// Copyright (c) 2010-2020 Cyotek Ltd.
// http://cyotek.com
// http://cyotek.com/blog/tag/imagebox

Expand Down Expand Up @@ -2953,13 +2953,9 @@ protected virtual void DrawImage(Graphics g)

g.DrawImage(this.Image, this.GetImageViewPort(), this.GetSourceImageRegion(), GraphicsUnit.Pixel);
}
catch (ArgumentException)
catch (Exception ex)
{
// ignore errors that occur due to the image being disposed
}
catch (OutOfMemoryException)
{
// also ignore errors that occur due to running out of memory
TextRenderer.DrawText(g, ex.Message, this.Font, this.ClientRectangle, this.ForeColor, this.BackColor, TextFormatFlags.VerticalCenter | TextFormatFlags.HorizontalCenter | TextFormatFlags.WordBreak | TextFormatFlags.NoPadding | TextFormatFlags.NoPrefix);
}

g.PixelOffsetMode = currentPixelOffsetMode;
Expand Down

0 comments on commit 1003c62

Please sign in to comment.