mirror of
https://git.do.srb2.org/STJr/UltimateZoneBuilder.git
synced 2025-01-31 04:40:55 +00:00
added some exception handling in case textures/sprites can't load for some reason
This commit is contained in:
parent
8f4716babc
commit
d904fb415c
8 changed files with 62 additions and 23 deletions
|
@ -268,7 +268,7 @@ namespace CodeImp.DoomBuilder.Data
|
|||
{
|
||||
// If a loader is already running, stop it first
|
||||
if(backgroundloader != null) StopBackgroundLoader();
|
||||
|
||||
|
||||
// Start a low priority thread to load images in background
|
||||
General.WriteLogLine("Starting background resource loading...");
|
||||
backgroundloader = new Thread(new ThreadStart(BackgroundLoad));
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -84,7 +84,8 @@ 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;
|
||||
height = bitmap.Size.Height;
|
||||
|
|
|
@ -90,11 +90,20 @@ namespace CodeImp.DoomBuilder.Data
|
|||
lock(this)
|
||||
{
|
||||
// Create texture bitmap
|
||||
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));
|
||||
|
||||
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)
|
||||
{
|
||||
|
|
|
@ -95,16 +95,25 @@ namespace CodeImp.DoomBuilder.IO
|
|||
pixeldata = ReadAsPixelData(stream, out width, out height);
|
||||
if(pixeldata != null)
|
||||
{
|
||||
// Create bitmap and lock pixels
|
||||
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();
|
||||
try
|
||||
{
|
||||
// Create bitmap and lock pixels
|
||||
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();
|
||||
|
||||
// Copy the pixels
|
||||
General.CopyMemory((void*)targetdata, (void*)pixeldata.Pointer, new UIntPtr((uint)(width * height * sizeof(PixelColor))));
|
||||
// Copy the pixels
|
||||
General.CopyMemory((void*)targetdata, (void*)pixeldata.Pointer, new UIntPtr((uint)(width * height * sizeof(PixelColor))));
|
||||
|
||||
// Done
|
||||
bmp.UnlockBits(bitmapdata);
|
||||
// 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
|
||||
{
|
||||
|
|
|
@ -112,15 +112,24 @@ namespace CodeImp.DoomBuilder.IO
|
|||
if(pixeldata != null)
|
||||
{
|
||||
// Create bitmap and lock pixels
|
||||
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();
|
||||
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();
|
||||
|
||||
// Copy the pixels
|
||||
General.CopyMemory((void*)targetdata, (void*)pixeldata.Pointer, new UIntPtr((uint)(width * height * sizeof(PixelColor))));
|
||||
// Copy the pixels
|
||||
General.CopyMemory((void*)targetdata, (void*)pixeldata.Pointer, new UIntPtr((uint)(width * height * sizeof(PixelColor))));
|
||||
|
||||
// Done
|
||||
bmp.UnlockBits(bitmapdata);
|
||||
// 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
|
||||
{
|
||||
|
|
|
@ -51,7 +51,16 @@ namespace CodeImp.DoomBuilder.IO
|
|||
// This reads the image and returns a Bitmap
|
||||
public Bitmap ReadAsBitmap(Stream stream)
|
||||
{
|
||||
return (Bitmap)Bitmap.FromStream(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
|
||||
|
|
Loading…
Reference in a new issue