diff --git a/src/wieldmesh.cpp b/src/wieldmesh.cpp
index 63c09786bcce5d2b8dfc03cadbc55b4a86f82c98..f12771968246af20127c2ea92f96dc3379d7c20f 100644
--- a/src/wieldmesh.cpp
+++ b/src/wieldmesh.cpp
@@ -357,8 +357,13 @@ void WieldMeshSceneNode::setItem(const ItemStack &item, IGameDef *gamedef)
 					def.wield_scale * WIELD_SCALE_FACTOR
 					/ (BS * f.visual_scale));
 		}
-		for (u32 i = 0; i < m_meshnode->getMaterialCount(); ++i) {
-			assert(i < 6);
+		u32 material_count = m_meshnode->getMaterialCount();
+		if (material_count >= 6) {
+			errorstream << "WieldMeshSceneNode::setItem: Invalid material "
+				"count " << material_count << ", truncating to 6" << std::endl;
+			material_count = 6;
+		}
+		for (u32 i = 0; i < material_count; ++i) {
 			video::SMaterial &material = m_meshnode->getMaterial(i);
 			material.setFlag(video::EMF_BACK_FACE_CULLING, true);
 			material.setFlag(video::EMF_BILINEAR_FILTER, m_bilinear_filter);