From 39fe7b79d2af38859de5d98f3134483c8b998ff4 Mon Sep 17 00:00:00 2001 From: Robert McRackan Date: Mon, 6 Feb 2023 08:35:24 -0500 Subject: [PATCH] Bug fix #474 --- Source/AppScaffolding/AppScaffolding.csproj | 2 +- Source/LibationAvalonia/ViewModels/GridEntry.cs | 13 +++++++++++-- Source/LibationWinForms/GridView/GridEntry.cs | 11 ++++++++++- Source/LibationWinForms/LibationWinForms.csproj | 10 ---------- 4 files changed, 22 insertions(+), 14 deletions(-) diff --git a/Source/AppScaffolding/AppScaffolding.csproj b/Source/AppScaffolding/AppScaffolding.csproj index 27f04f60..16e47668 100644 --- a/Source/AppScaffolding/AppScaffolding.csproj +++ b/Source/AppScaffolding/AppScaffolding.csproj @@ -2,7 +2,7 @@ net7.0 - 9.2.1.1 + 9.2.2.1 diff --git a/Source/LibationAvalonia/ViewModels/GridEntry.cs b/Source/LibationAvalonia/ViewModels/GridEntry.cs index b20f12cd..0baad921 100644 --- a/Source/LibationAvalonia/ViewModels/GridEntry.cs +++ b/Source/LibationAvalonia/ViewModels/GridEntry.cs @@ -130,8 +130,17 @@ namespace LibationAvalonia.ViewModels } private void PictureStorage_PictureCached(object sender, PictureCachedEventArgs e) - { - if (e.Definition.PictureId == Book.PictureId) + { + // state validation + if (e is null || + e.Definition.PictureId is null || + Book?.PictureId is null || + e.Picture is null || + e.Picture.Length == 0) + return; + + // logic validation + if (e.Definition.PictureId == Book.PictureId) { using var ms = new System.IO.MemoryStream(e.Picture); Cover = new Avalonia.Media.Imaging.Bitmap(ms); diff --git a/Source/LibationWinForms/GridView/GridEntry.cs b/Source/LibationWinForms/GridView/GridEntry.cs index 43aff6fa..4923b86b 100644 --- a/Source/LibationWinForms/GridView/GridEntry.cs +++ b/Source/LibationWinForms/GridView/GridEntry.cs @@ -140,7 +140,16 @@ namespace LibationWinForms.GridView private void PictureStorage_PictureCached(object sender, PictureCachedEventArgs e) { - if (e.Definition.PictureId == Book.PictureId) + // state validation + if (e is null || + e.Definition.PictureId is null || + Book?.PictureId is null || + e.Picture is null || + e.Picture.Length == 0) + return; + + // logic validation + if (e.Definition.PictureId == Book.PictureId) { Cover = ImageReader.ToImage(e.Picture); PictureStorage.PictureCached -= PictureStorage_PictureCached; diff --git a/Source/LibationWinForms/LibationWinForms.csproj b/Source/LibationWinForms/LibationWinForms.csproj index 6f70cb52..7c025399 100644 --- a/Source/LibationWinForms/LibationWinForms.csproj +++ b/Source/LibationWinForms/LibationWinForms.csproj @@ -64,16 +64,6 @@ SettingsDialog.cs - - - Form1.cs - - - - - Form1.cs - -