Merge pull request #4833 from larsbrubaker/master

Don't process bad images
This commit is contained in:
Lars Brubaker 2020-08-30 16:58:07 -07:00 committed by GitHub
commit f60aeab8eb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 3 deletions

View file

@ -92,17 +92,19 @@ namespace MatterHackers.MatterControl
var expectedCachePath = this.CachePath(libraryItem, width, height);
ImageBuffer cachedItem = LoadImage(expectedCachePath);
if(cachedItem != null)
if (cachedItem != null
&& cachedItem.Width > 0 && cachedItem.Height > 0)
{
cachedItem.SetRecieveBlender(new BlenderPreMultBGRA());
return cachedItem;
}
// if we don't find it see if it is in the cache at a bigger size
foreach(var cacheSize in cacheSizes.Where(s => s > width))
foreach (var cacheSize in cacheSizes.Where(s => s > width))
{
cachedItem = LoadImage(this.CachePath(libraryItem, cacheSize, cacheSize));
if(cachedItem != null)
if (cachedItem != null
&& cachedItem.Width > 0 && cachedItem.Height > 0)
{
cachedItem = cachedItem.CreateScaledImage(width, height);
cachedItem.SetRecieveBlender(new BlenderPreMultBGRA());

View file

@ -201,6 +201,11 @@ namespace MatterHackers.MatterControl.Library
{
if (icon != null)
{
if (icon.Width == 0)
{
return;
}
icon = await Task.Run(() => this.EnsureCorrectThumbnailSizing(icon, thumbWidth, thumbHeight));
thumbnailListener?.Invoke(icon);
}