diff --git a/indra/llappearance/llavatarappearance.cpp b/indra/llappearance/llavatarappearance.cpp
index 6fdf9e2e072cb31c1d76e4164d7a73b368003043..0a1569a9bad45b816eeeb486b4f6302c22265955 100755
--- a/indra/llappearance/llavatarappearance.cpp
+++ b/indra/llappearance/llavatarappearance.cpp
@@ -953,19 +953,19 @@ BOOL LLAvatarAppearance::loadSkeletonNode ()
 	mRoot->addChild(mMeshLOD[MESH_ID_SKIRT]);
 	mRoot->addChild(mMeshLOD[MESH_ID_HEAD]);
 
-	LLAvatarJoint *skull = (LLAvatarJoint*)mRoot->findJoint("mSkull");
+	LLAvatarJoint *skull = dynamic_cast<LLAvatarJoint*>(mRoot->findJoint("mSkull"));
 	if (skull)
 	{
 		skull->addChild(mMeshLOD[MESH_ID_HAIR] );
 	}
 
-	LLAvatarJoint *eyeL = (LLAvatarJoint*)mRoot->findJoint("mEyeLeft");
+	LLAvatarJoint *eyeL = dynamic_cast<LLAvatarJoint*>(mRoot->findJoint("mEyeLeft"));
 	if (eyeL)
 	{
 		eyeL->addChild( mMeshLOD[MESH_ID_EYEBALL_LEFT] );
 	}
 
-	LLAvatarJoint *eyeR = (LLAvatarJoint*)mRoot->findJoint("mEyeRight");
+	LLAvatarJoint *eyeR = dynamic_cast<LLAvatarJoint*>(mRoot->findJoint("mEyeRight"));
 	if (eyeR)
 	{
 		eyeR->addChild( mMeshLOD[MESH_ID_EYEBALL_RIGHT] );
diff --git a/indra/llappearance/llavatarjoint.cpp b/indra/llappearance/llavatarjoint.cpp
index 2ee3c65a01ddef2a2cde2a688fe40ffa5afb4261..cb887d856901ebb58e86ca628e7d19b8c5249175 100644
--- a/indra/llappearance/llavatarjoint.cpp
+++ b/indra/llappearance/llavatarjoint.cpp
@@ -104,8 +104,9 @@ void LLAvatarJoint::setValid( BOOL valid, BOOL recursive )
 		for (child_list_t::iterator iter = mChildren.begin();
 			 iter != mChildren.end(); ++iter)
 		{
-			LLAvatarJoint* joint = (LLAvatarJoint*)(*iter);
-			joint->setValid(valid, TRUE);
+			LLAvatarJoint* joint = dynamic_cast<LLAvatarJoint*>(*iter);
+			if (joint)
+				joint->setValid(valid, TRUE);
 		}
 	}
 
@@ -123,7 +124,8 @@ void LLAvatarJoint::setSkeletonComponents( U32 comp, BOOL recursive )
 			 iter != mChildren.end(); ++iter)
 		{
 			LLAvatarJoint* joint = dynamic_cast<LLAvatarJoint*>(*iter);
-			joint->setSkeletonComponents(comp, recursive);
+			if (joint)
+				joint->setSkeletonComponents(comp, recursive);
 		}
 	}
 }
@@ -137,8 +139,9 @@ void LLAvatarJoint::setVisible(BOOL visible, BOOL recursive)
 		for (child_list_t::iterator iter = mChildren.begin();
 			 iter != mChildren.end(); ++iter)
 		{
-			LLAvatarJoint* joint = (LLAvatarJoint*)(*iter);
-			joint->setVisible(visible, recursive);
+			LLAvatarJoint* joint = dynamic_cast<LLAvatarJoint*>(*iter);
+			if (joint)
+				joint->setVisible(visible, recursive);
 		}
 	}
 }
@@ -149,7 +152,8 @@ void LLAvatarJoint::updateFaceSizes(U32 &num_vertices, U32& num_indices, F32 pix
 		 iter != mChildren.end(); ++iter)
 	{
 		LLAvatarJoint* joint = dynamic_cast<LLAvatarJoint*>(*iter);
-		joint->updateFaceSizes(num_vertices, num_indices, pixel_area);
+		if (joint)
+			joint->updateFaceSizes(num_vertices, num_indices, pixel_area);
 	}
 }
 
@@ -159,7 +163,8 @@ void LLAvatarJoint::updateFaceData(LLFace *face, F32 pixel_area, BOOL damp_wind,
 		 iter != mChildren.end(); ++iter)
 	{
 		LLAvatarJoint* joint = dynamic_cast<LLAvatarJoint*>(*iter);
-		joint->updateFaceData(face, pixel_area, damp_wind, terse_update);
+		if (joint)
+			joint->updateFaceData(face, pixel_area, damp_wind, terse_update);
 	}
 }
 
@@ -169,7 +174,8 @@ void LLAvatarJoint::updateJointGeometry()
 		 iter != mChildren.end(); ++iter)
 	{
 		LLAvatarJoint* joint = dynamic_cast<LLAvatarJoint*>(*iter);
-		joint->updateJointGeometry();
+		if (joint)
+			joint->updateJointGeometry();
 	}
 }
 
@@ -183,23 +189,26 @@ BOOL LLAvatarJoint::updateLOD(F32 pixel_area, BOOL activate)
 		 iter != mChildren.end(); ++iter)
 	{
 		LLAvatarJoint* joint = dynamic_cast<LLAvatarJoint*>(*iter);
-		F32 jointLOD = joint->getLOD();
-		
-		if (found_lod || jointLOD == DEFAULT_AVATAR_JOINT_LOD)
+		if (joint)
 		{
-			// we've already found a joint to enable, so enable the rest as alternatives
-			lod_changed |= joint->updateLOD(pixel_area, TRUE);
-		}
-		else
-		{
-			if (pixel_area >= jointLOD || sDisableLOD)
+			F32 jointLOD = joint->getLOD();
+
+			if (found_lod || jointLOD == DEFAULT_AVATAR_JOINT_LOD)
 			{
+				// we've already found a joint to enable, so enable the rest as alternatives
 				lod_changed |= joint->updateLOD(pixel_area, TRUE);
-				found_lod = TRUE;
 			}
 			else
 			{
-				lod_changed |= joint->updateLOD(pixel_area, FALSE);
+				if (pixel_area >= jointLOD || sDisableLOD)
+				{
+					lod_changed |= joint->updateLOD(pixel_area, TRUE);
+					found_lod = TRUE;
+				}
+				else
+				{
+					lod_changed |= joint->updateLOD(pixel_area, FALSE);
+				}
 			}
 		}
 	}
@@ -212,7 +221,8 @@ void LLAvatarJoint::dump()
 		 iter != mChildren.end(); ++iter)
 	{
 		LLAvatarJoint* joint = dynamic_cast<LLAvatarJoint*>(*iter);
-		joint->dump();
+		if (joint)
+			joint->dump();
 	}
 }
 
diff --git a/indra/llappearance/llavatarjointmesh.cpp b/indra/llappearance/llavatarjointmesh.cpp
index 520ad775db7cbc46c59a1c95b5bf01167f69325f..d32915caabaad3489a9f7335f2cdbbd4e7a581fe 100644
--- a/indra/llappearance/llavatarjointmesh.cpp
+++ b/indra/llappearance/llavatarjointmesh.cpp
@@ -98,7 +98,7 @@ BOOL LLSkinJoint::setupSkinJoint( LLAvatarJoint *joint)
 	while (joint)
 	{
 		rootSkinOffset += joint->getSkinOffset();
-		joint = (LLAvatarJoint*)joint->getParent();
+		joint = dynamic_cast<LLAvatarJoint*>(joint->getParent());
 	}
 
 	mRootToJointSkinOffset = -rootSkinOffset;
@@ -362,8 +362,11 @@ void LLAvatarJointMesh::setupJoint(LLAvatarJoint* current_joint)
 	for (LLJoint::child_list_t::iterator iter = current_joint->mChildren.begin();
 		 iter != current_joint->mChildren.end(); ++iter)
 	{
-		LLAvatarJoint* child_joint = (LLAvatarJoint*)(*iter);
-		setupJoint(child_joint);
+		LLAvatarJoint* child_joint = dynamic_cast<LLAvatarJoint*>(*iter);
+		if (child_joint)
+		{
+			setupJoint(child_joint);
+		}
 	}
 }
 
diff --git a/indra/llappearance/llpolyskeletaldistortion.cpp b/indra/llappearance/llpolyskeletaldistortion.cpp
index ea29cbd4519c7fae24617a3d20d9733d67426a0f..29f54b3a4285538f72437c23fc0eeb81380edcc3 100644
--- a/indra/llappearance/llpolyskeletaldistortion.cpp
+++ b/indra/llappearance/llpolyskeletaldistortion.cpp
@@ -164,8 +164,8 @@ BOOL LLPolySkeletalDistortion::setInfo(LLPolySkeletalDistortionInfo *info)
                 for (LLJoint::child_list_t::iterator iter = joint->mChildren.begin();
                      iter != joint->mChildren.end(); ++iter)
                 {
-                        LLAvatarJoint* child_joint = (LLAvatarJoint*)(*iter);
-                        if (child_joint->inheritScale())
+                        LLAvatarJoint* child_joint = dynamic_cast<LLAvatarJoint*>(*iter);
+						if (child_joint && child_joint->inheritScale())
                         {
                                 LLVector3 childDeformation = LLVector3(child_joint->getScale());
                                 childDeformation.scaleVec(bone_info->mScaleDeformation);
diff --git a/indra/newview/llviewerjoint.cpp b/indra/newview/llviewerjoint.cpp
index e46299f9d2d54ae2cf90c2aff73944100d9ceaa6..173f39738f28b2378c631b2a9451b86e6e22a35e 100755
--- a/indra/newview/llviewerjoint.cpp
+++ b/indra/newview/llviewerjoint.cpp
@@ -143,21 +143,24 @@ U32 LLViewerJoint::render( F32 pixelArea, BOOL first_pass, BOOL is_dummy )
 	// render children
 	//----------------------------------------------------------------
 	for (child_list_t::iterator iter = mChildren.begin();
-		 iter != mChildren.end(); ++iter)
+		iter != mChildren.end(); ++iter)
 	{
 		LLAvatarJoint* joint = dynamic_cast<LLAvatarJoint*>(*iter);
-		F32 jointLOD = joint->getLOD();
-		if (pixelArea >= jointLOD || sDisableLOD)
+		if (joint)
 		{
-			triangle_count += joint->render( pixelArea, TRUE, is_dummy );
-
-			if (jointLOD != DEFAULT_AVATAR_JOINT_LOD)
+			F32 jointLOD = joint->getLOD();
+			if (pixelArea >= jointLOD || sDisableLOD)
 			{
-				break;
+				triangle_count += joint->render(pixelArea, TRUE, is_dummy);
+
+				if (jointLOD != DEFAULT_AVATAR_JOINT_LOD)
+				{
+					break;
+				}
 			}
+
 		}
 	}
-
 	return triangle_count;
 }