From b07445d149d68a2a1b4ef70e7bfb0f75343a23f7 Mon Sep 17 00:00:00 2001
From: Christoph Oelckers <coelckers@zdoom.fake>
Date: Sun, 6 Sep 2009 21:32:57 +0000
Subject: [PATCH] - fixed: Trying to pick up an object of the Ammo base class
 caused a crash.

SVN r1804 (trunk)
---
 docs/rh-log.txt            | 1 +
 src/g_shared/a_pickups.cpp | 4 ++--
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/docs/rh-log.txt b/docs/rh-log.txt
index ab69effb3..0ef17a33e 100644
--- a/docs/rh-log.txt
+++ b/docs/rh-log.txt
@@ -1,4 +1,5 @@
 September 6, 2009  (Changes by Graf Zahl)
+- fixed: Trying to pick up an object of the Ammo base class caused a crash.
 - changed line_t's sidenum into sidedef pointers.
 - changed side_t's linenum into a linedef pointer.
 - Added PinkSilver's SetActorVelocity code submission (with optimizations.)
diff --git a/src/g_shared/a_pickups.cpp b/src/g_shared/a_pickups.cpp
index 523aaca23..2753a750b 100644
--- a/src/g_shared/a_pickups.cpp
+++ b/src/g_shared/a_pickups.cpp
@@ -55,7 +55,7 @@ const PClass *AAmmo::GetParentAmmo () const
 {
 	const PClass *type = GetClass ();
 
-	while (type->ParentClass != RUNTIME_CLASS(AAmmo))
+	while (type->ParentClass != RUNTIME_CLASS(AAmmo) && type->ParentClass != NULL)
 	{
 		type = type->ParentClass;
 	}
@@ -128,7 +128,7 @@ AInventory *AAmmo::CreateCopy (AActor *other)
 		amount = FixedMul(amount, G_SkillProperty(SKILLP_AmmoFactor));
 	}
 
-	if (GetClass()->ParentClass != RUNTIME_CLASS(AAmmo))
+	if (GetClass()->ParentClass != RUNTIME_CLASS(AAmmo) && GetClass() != RUNTIME_CLASS(AAmmo))
 	{
 		const PClass *type = GetParentAmmo();
 		assert (type->ActorInfo != NULL);