added some exception handling in case textures/sprites can't load for some reason

This commit is contained in:
codeimp 2008-02-23 13:12:59 +00:00
parent 8f4716babc
commit d904fb415c
8 changed files with 62 additions and 23 deletions

View file

@ -83,6 +83,7 @@ namespace CodeImp.DoomBuilder.Data
// Read data as bitmap
mem.Seek(0, SeekOrigin.Begin);
bitmap = reader.ReadAsBitmap(mem);
if(bitmap == null) return;
// Get width and height from image
width = bitmap.Size.Width;

View file

@ -101,6 +101,7 @@ namespace CodeImp.DoomBuilder.Data
// Load the image
mem.Seek(0, SeekOrigin.Begin);
bitmap = reader.ReadAsBitmap(mem);
if(bitmap == null) return;
}
// Pass on to base

View file

@ -84,6 +84,7 @@ namespace CodeImp.DoomBuilder.Data
// Read data as bitmap
mem.Seek(0, SeekOrigin.Begin);
bitmap = reader.ReadAsBitmap(mem);
if(bitmap == null) return;
// Get width and height from image
width = bitmap.Size.Width;

View file

@ -90,10 +90,19 @@ namespace CodeImp.DoomBuilder.Data
lock(this)
{
// Create texture bitmap
try
{
bitmap = new Bitmap(width, height, PixelFormat.Format32bppArgb);
bitmapdata = bitmap.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);
pixels = (PixelColor*)bitmapdata.Scan0.ToPointer();
General.ZeroMemory(new IntPtr(pixels), width * height * sizeof(PixelColor));
}
catch(Exception e)
{
// Unable to make bitmap
General.WriteLogLine("ERROR: Unable to load texture image '" + this.Name + "'. " + e.GetType().Name + ": " + e.Message);
return;
}
// Go for all patches
foreach(TexturePatch p in patches)

View file

@ -94,6 +94,8 @@ namespace CodeImp.DoomBuilder.IO
// Read pixel data
pixeldata = ReadAsPixelData(stream, out width, out height);
if(pixeldata != null)
{
try
{
// Create bitmap and lock pixels
bmp = new Bitmap(width, height, PixelFormat.Format32bppArgb);
@ -106,6 +108,13 @@ namespace CodeImp.DoomBuilder.IO
// Done
bmp.UnlockBits(bitmapdata);
}
catch(Exception e)
{
// Unable to make bitmap
General.WriteLogLine("ERROR: Unable to make doom flat data. " + e.GetType().Name + ": " + e.Message);
return null;
}
}
else
{
// Failed loading picture

View file

@ -112,6 +112,8 @@ namespace CodeImp.DoomBuilder.IO
if(pixeldata != null)
{
// Create bitmap and lock pixels
try
{
bmp = new Bitmap(width, height, PixelFormat.Format32bppArgb);
bitmapdata = bmp.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);
targetdata = (PixelColor*)bitmapdata.Scan0.ToPointer();
@ -122,6 +124,13 @@ namespace CodeImp.DoomBuilder.IO
// Done
bmp.UnlockBits(bitmapdata);
}
catch(Exception e)
{
// Unable to make bitmap
General.WriteLogLine("ERROR: Unable to make doom picture data. " + e.GetType().Name + ": " + e.Message);
return null;
}
}
else
{
// Failed loading picture

View file

@ -50,9 +50,18 @@ namespace CodeImp.DoomBuilder.IO
// This reads the image and returns a Bitmap
public Bitmap ReadAsBitmap(Stream stream)
{
try
{
return (Bitmap)Bitmap.FromStream(stream);
}
catch(Exception e)
{
// Unable to make bitmap
General.WriteLogLine("ERROR: Unable to make file image. " + e.GetType().Name + ": " + e.Message);
return null;
}
}
// This draws the picture to the given pixel color data
// Throws exception on failure