From 0c8b91f443612bdef247d80b27cfc24fec66a658 Mon Sep 17 00:00:00 2001
From: MaxED <j.maxed@gmail.com>
Date: Tue, 29 Dec 2015 18:22:08 +0000
Subject: [PATCH] Fixed a crash when trying to create a texture from an unnamed
 TEXTURE1/2 entry.

---
 Source/Core/Data/PK3StructuredReader.cs | 9 ++++-----
 Source/Core/Data/WADReader.cs           | 2 +-
 2 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/Source/Core/Data/PK3StructuredReader.cs b/Source/Core/Data/PK3StructuredReader.cs
index fda3f7f0c..e1366d47f 100644
--- a/Source/Core/Data/PK3StructuredReader.cs
+++ b/Source/Core/Data/PK3StructuredReader.cs
@@ -163,12 +163,11 @@ namespace CodeImp.DoomBuilder.Data
 		// This loads the textures
 		public override ICollection<ImageData> LoadTextures(PatchNames pnames)
 		{
-			Dictionary<long, ImageData> images = new Dictionary<long, ImageData>();
-			ICollection<ImageData> collection;
-			List<ImageData> imgset = new List<ImageData>();
-			
 			// Error when suspended
 			if(issuspended) throw new Exception("Data reader is suspended");
+
+			Dictionary<long, ImageData> images = new Dictionary<long, ImageData>();
+			ICollection<ImageData> collection;
 			
 			// Load from wad files (NOTE: backward order, because the last wad's images have priority)
 			for(int i = wads.Count - 1; i >= 0; i--)
@@ -186,7 +185,7 @@ namespace CodeImp.DoomBuilder.Data
 			}
 			
 			// Load TEXTURE1 lump file
-			imgset.Clear();
+			List<ImageData> imgset = new List<ImageData>();
 			string texture1file = FindFirstFile("TEXTURE1", false);
 			if((texture1file != null) && FileExists(texture1file))
 			{
diff --git a/Source/Core/Data/WADReader.cs b/Source/Core/Data/WADReader.cs
index c8e7633a1..b2a93dc94 100644
--- a/Source/Core/Data/WADReader.cs
+++ b/Source/Core/Data/WADReader.cs
@@ -502,7 +502,7 @@ namespace CodeImp.DoomBuilder.Data
 					}
 					
 					// Add image to collection
-					images.Add(image);
+					if(image != null) images.Add(image);
 				}
 				else
 				{
-- 
GitLab