From 0d896cb45ed60863ed7451a9ab87aae83bbf8f93 Mon Sep 17 00:00:00 2001
From: jsalmon3 <>
Date: Tue, 4 Mar 2003 18:26:02 +0000
Subject: [PATCH] Check for valid icon index, fixes crash with original wc2
 using expansion units

---
 src/ui/icons.cpp | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/src/ui/icons.cpp b/src/ui/icons.cpp
index 652c26bad..8d0d78b22 100644
--- a/src/ui/icons.cpp
+++ b/src/ui/icons.cpp
@@ -10,7 +10,7 @@
 //
 /**@name icons.c	-	The icons. */
 //
-//	(c) Copyright 1998-2002 by Lutz Sammer
+//	(c) Copyright 1998-2003 by Lutz Sammer
 //
 //	FreeCraft is free software; you can redistribute it and/or modify
 //	it under the terms of the GNU General Public License as published
@@ -213,6 +213,11 @@ global void LoadIcons(void)
 #endif
 	    }
 	    icon->Sprite = icon->File->Sprite;
+	    if (icon->Index >= (unsigned)icon->Sprite->NumFrames) {
+		DebugLevel0Fn("Invalid icon index: %s - %d\n"
+			_C_ icon->Ident _C_ icon->Index);
+		icon->Index = 0;
+	    }
 	}
     }
 }