Added IOException handling to image loading from disk (fixes GZDB Git issue #8)

This commit is contained in:
ZZYZX 2017-01-15 05:12:19 +02:00
parent 8277d7b63c
commit 5e11072970
3 changed files with 45 additions and 32 deletions

View file

@ -142,38 +142,51 @@ namespace CodeImp.DoomBuilder.Data
// Load file data
if(bitmap != null) bitmap.Dispose(); bitmap = null;
MemoryStream filedata = new MemoryStream(File.ReadAllBytes(filepathname));
MemoryStream filedata = null;
try
{
filedata = new MemoryStream(File.ReadAllBytes(filepathname));
}
catch (IOException)
{
General.ErrorLogger.Add(ErrorType.Error, "Image file \"" + filepathname + "\" could not be read, while loading image \"" + this.Name + "\". Consider reloading resources.");
loadfailed = true;
}
// Get a reader for the data
IImageReader reader = ImageDataFormat.GetImageReader(filedata, probableformat, General.Map.Data.Palette);
if(!(reader is UnknownImageReader))
{
// Load the image
filedata.Seek(0, SeekOrigin.Begin);
try { bitmap = reader.ReadAsBitmap(filedata); }
catch(InvalidDataException)
{
// Data cannot be read!
bitmap = null;
}
}
if (filedata != null)
{
// Get a reader for the data
IImageReader reader = ImageDataFormat.GetImageReader(filedata, probableformat, General.Map.Data.Palette);
if (!(reader is UnknownImageReader))
{
// Load the image
filedata.Seek(0, SeekOrigin.Begin);
try { bitmap = reader.ReadAsBitmap(filedata); }
catch (InvalidDataException)
{
// Data cannot be read!
bitmap = null;
}
}
// Not loaded?
if(bitmap == null)
{
General.ErrorLogger.Add(ErrorType.Error, "Image file \"" + filepathname + "\" data format could not be read, while loading image \"" + this.Name + "\". Is this a valid picture file at all?");
loadfailed = true;
}
else
{
// Get width and height
width = bitmap.Size.Width;
height = bitmap.Size.Height;
}
// Not loaded?
if (bitmap == null)
{
General.ErrorLogger.Add(ErrorType.Error, "Image file \"" + filepathname + "\" data format could not be read, while loading image \"" + this.Name + "\". Is this a valid picture file at all?");
loadfailed = true;
}
else
{
// Get width and height
width = bitmap.Size.Width;
height = bitmap.Size.Height;
}
// Pass on to base
filedata.Dispose();
base.LocalLoadImage();
filedata.Dispose();
}
// Pass on to base
base.LocalLoadImage();
}
}

View file

@ -30,6 +30,6 @@ using CodeImp.DoomBuilder;
// Build Number
// Revision
//
[assembly: AssemblyVersion("2.3.0.2803")]
[assembly: AssemblyVersion("2.3.0.2804")]
[assembly: NeutralResourcesLanguageAttribute("en")]
[assembly: AssemblyHash("9843233")]
[assembly: AssemblyHash("8277d7b")]

View file

@ -29,5 +29,5 @@ using System.Resources;
// Build Number
// Revision
//
[assembly: AssemblyVersion("2.3.0.2803")]
[assembly: AssemblyVersion("2.3.0.2804")]
[assembly: NeutralResourcesLanguageAttribute("en")]