diff --git a/indra/newview/llagent.cpp b/indra/newview/llagent.cpp
index 2f80193f3a2efcd8f45d24c9c58a63f7e082f78c..6870dd0605ae8f04616094ce401bfb7155ec56ae 100644
--- a/indra/newview/llagent.cpp
+++ b/indra/newview/llagent.cpp
@@ -5301,14 +5301,17 @@ LLUUID LLAgent::getGroupForRezzing()
 	if (gSavedSettings.getBOOL("AlchemyRezUnderLandGroup"))
 	{
 		LLParcel* land_parcel = LLViewerParcelMgr::getInstanceFast()->getAgentParcel();
-		// Is the agent in the land group
-		if (gAgent.isInGroup(land_parcel->getGroupID()))
-			return land_parcel->getGroupID();
-		// Is the agent in the land group (the group owns the land)
-		else if (gAgent.isInGroup(land_parcel->getOwnerID()))
-			return land_parcel->getOwnerID();
-	}
-	return LLUUID::null;
+		if (land_parcel)
+		{
+			// Is the agent in the land group
+			if (isInGroup(land_parcel->getGroupID()))
+				return land_parcel->getGroupID();
+			// Is the agent in the land group (the group owns the land)
+			else if (isInGroup(land_parcel->getOwnerID()))
+				return land_parcel->getOwnerID();
+		}
+	}
+	return getGroupID();
 }
 
 // EOF