diff --git a/.hgtags b/.hgtags
index 199404dbf6196fc69e89ff4b243e94e595cbb534..f122124a39a184d7f719528178cc7abff5744eb6 100644
--- a/.hgtags
+++ b/.hgtags
@@ -74,3 +74,4 @@ b723921b5c711bd24dbe77dc76ef488b544dac78 DRTVWR-31_2.5.0-release
 92e58e51776a4f8c29069b1a62ff21454d2085f0 2.6.0-start
 63a6aedfce785a6c760377bf685b2dae616797d2 2.5.1-start
 4dede9ae1ec74d41f6887719f6f1de7340d8578d 2.5.1-release
+4dede9ae1ec74d41f6887719f6f1de7340d8578d DRTVWR-37_2.5.1-release
diff --git a/BuildParams b/BuildParams
index f816c7b368ba6d771f8619290255961ce32f74b9..97af68d37982e12a0377b13818a483db53dc1fab 100755
--- a/BuildParams
+++ b/BuildParams
@@ -57,6 +57,12 @@ viewer-release.build_debug_release_separately = true
 viewer-release.build_viewer_update_version_manager = true
 viewer-release.release-viewer.jira = DRTVWR-13
 
+viewer-pre-release.viewer_channel = "Second Life Release"
+viewer-pre-release.login_channel = "Second Life Release"
+viewer-pre-release.build_debug_release_separately = true
+viewer-pre-release.build_viewer_update_version_manager = true
+#viewer-pre-release.release-viewer.jira = DRTVWR-13
+
 # ========================================
 # aimee
 # ========================================
diff --git a/doc/contributions.txt b/doc/contributions.txt
index 7231bf4da06a95aa24d137a44e7c3fe6e10fb0c7..337a3da6b820bddd5d45fcde8f81c4ee4cb61fe9 100644
--- a/doc/contributions.txt
+++ b/doc/contributions.txt
@@ -84,10 +84,12 @@ Aleric Inglewood
 	VWR-24315
 	VWR-24317
 	VWR-24320
-    VWR-24321
+	VWR-24321
+	VWR-24337
  	VWR-24354
 	VWR-24366
 	VWR-24519
+	VWR-24520
 	SNOW-84
 	SNOW-477
 	SNOW-744
@@ -238,6 +240,7 @@ Coaldust Numbers
     VWR-1095
 Cron Stardust
 	VWR-10579
+	VWR-25120
 Cypren Christenson
 	STORM-417
 Dale Glass
@@ -407,7 +410,9 @@ Jonathan Yap
 	STORM-1040
 	VWR-17801
 	VWR-24347
+	STORM-975
 	STORM-990
+	STORM-1020
 Kage Pixel
 	VWR-11
 Ken March
@@ -424,6 +429,7 @@ Kitty Barnett
 	STORM-288
 	STORM-799
 	STORM-800
+	STORM-1001
     VWR-24217
 Kunnis Basiat
 	VWR-82
diff --git a/indra/cmake/FindLLQtWebkit.cmake b/indra/cmake/FindLLQtWebkit.cmake
index c747ec32a2850957f45ccb5fe239b6f995cb611c..4bf5f5cb7340cabccd7f6e29736959308d88bcd2 100644
--- a/indra/cmake/FindLLQtWebkit.cmake
+++ b/indra/cmake/FindLLQtWebkit.cmake
@@ -22,9 +22,9 @@ if (PKG_CONFIG_FOUND)
     else (LLQtWebkit_FIND_REQUIRED AND LLQtWebkit_FIND_VERSION)
         set(_PACKAGE_ARGS libllqtwebkit)
     endif (LLQtWebkit_FIND_REQUIRED AND LLQtWebkit_FIND_VERSION)
-    if (NOT "${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" VERSION_LESS "2.8")
+    if (NOT "${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_LESS "2.8.2")
       # As virtually nobody will have a pkg-config file for this, do this check always quiet.
-      # Unfortunately cmake 2.8 or higher is required for pkg_check_modules to have a 'QUIET'.
+      # Unfortunately cmake 2.8.2 or higher is required for pkg_check_modules to have a 'QUIET'.
       set(_PACKAGE_ARGS ${_PACKAGE_ARGS} QUIET)
     endif ()
     pkg_check_modules(LLQTWEBKIT ${_PACKAGE_ARGS})
diff --git a/indra/llprimitive/llmodel.cpp b/indra/llprimitive/llmodel.cpp
index 4ce5c15898014edb52aca6f12bfadf5b975131b6..2284ca0beeee32d3af1e465f4abc404e128e5bcb 100755
--- a/indra/llprimitive/llmodel.cpp
+++ b/indra/llprimitive/llmodel.cpp
@@ -57,6 +57,7 @@ const int MODEL_NAMES_LENGTH = sizeof(model_names) / sizeof(std::string);
 
 LLModel::LLModel(LLVolumeParams& params, F32 detail)
 	: LLVolume(params, detail), mNormalizedScale(1,1,1), mNormalizedTranslation(0,0,0)
+	, mPelvisOffset( 0.0f )
 {
 	mDecompID = -1;
 }
@@ -1497,6 +1498,7 @@ LLSD LLModel::writeModel(
 			}
 		}
 		
+		
 		if ( upload_joints && high->mAlternateBindMatrix.size() > 0 )
 		{
 			for (U32 i = 0; i < high->mJointList.size(); ++i)
@@ -1509,6 +1511,8 @@ LLSD LLModel::writeModel(
 					}
 				}
 			}
+
+			mdl["skin"]["pelvis_offset"] = high->mPelvisOffset;
 		}
 		
 	}
diff --git a/indra/llprimitive/llmodel.h b/indra/llprimitive/llmodel.h
index c10ca1c11be60fa5154990d1fe917381535a4541..e9e33bdee51abd6abef57ff43a0b9b97a97892d8 100755
--- a/indra/llprimitive/llmodel.h
+++ b/indra/llprimitive/llmodel.h
@@ -194,6 +194,7 @@ class LLModel : public LLVolume
 	LLVector3 mNormalizedScale;
 	LLVector3 mNormalizedTranslation;
 
+	float	mPelvisOffset;
 	// convex hull decomposition
 	S32 mDecompID;
 	convex_hull_decomposition mConvexHullDecomp;
diff --git a/indra/llprimitive/lltextureentry.cpp b/indra/llprimitive/lltextureentry.cpp
index 861bde5c89285bceae0bb9e730a233ab353ae812..34eff17519e60752304692a9845690ae56a48029 100644
--- a/indra/llprimitive/lltextureentry.cpp
+++ b/indra/llprimitive/lltextureentry.cpp
@@ -423,24 +423,10 @@ S32 LLTextureEntry::setBumpShinyFullbright(U8 bump)
 
 S32 LLTextureEntry::setMediaTexGen(U8 media)
 {
-	if (mMediaFlags != media)
-	{
-		mMediaFlags = media;
-
-		// Special code for media handling
-		if( hasMedia() && mMediaEntry == NULL)
-		{
-			mMediaEntry = new LLMediaEntry;
-		}
-        else if ( ! hasMedia() && mMediaEntry != NULL)
-        {
-            delete mMediaEntry;
-            mMediaEntry = NULL;
-        }
-
-		return TEM_CHANGE_MEDIA;
-	}
-	return TEM_CHANGE_NONE;
+	S32 result = TEM_CHANGE_NONE;
+	result |= setTexGen(media & TEM_TEX_GEN_MASK);
+	result |= setMediaFlags(media & TEM_MEDIA_MASK);
+	return result;
 }
 
 S32 LLTextureEntry::setBumpmap(U8 bump)
diff --git a/indra/newview/llfloatermodelpreview.cpp b/indra/newview/llfloatermodelpreview.cpp
index f65fab41e756147098a18b35a1d54b23a889d5ba..d4ba039eeb583fc8bafa50aae964baf6d1045e2a 100755
--- a/indra/newview/llfloatermodelpreview.cpp
+++ b/indra/newview/llfloatermodelpreview.cpp
@@ -310,6 +310,7 @@ BOOL LLFloaterModelPreview::postBuild()
 	childSetCommitCallback("upload_joints", onUploadJointsCommit, this);
 
 	childSetCommitCallback("import_scale", onImportScaleCommit, this);
+	childSetCommitCallback("pelvis_offset", onPelvisOffsetCommit, this);
 
 	childSetCommitCallback("lod_file_or_limit", refresh, this);
 	childSetCommitCallback("physics_load_radio", refresh, this);
@@ -318,6 +319,9 @@ BOOL LLFloaterModelPreview::postBuild()
 
 	childDisable("upload_skin");
 	childDisable("upload_joints");
+
+	childDisable("pelvis_offset");
+
 	childDisable("ok_btn");
 
 	mViewOptionMenuButton = getChild<LLMenuButton>("options_gear_btn");
@@ -456,6 +460,18 @@ void LLFloaterModelPreview::onImportScaleCommit(LLUICtrl*,void* userdata)
 	fp->mModelPreview->calcResourceCost();
 	fp->mModelPreview->refresh();
 }
+//static
+void LLFloaterModelPreview::onPelvisOffsetCommit( LLUICtrl*, void* userdata )
+{
+	LLFloaterModelPreview *fp =(LLFloaterModelPreview*)userdata;
+
+	if (!fp->mModelPreview)
+	{
+		return;
+	}
+
+	fp->mModelPreview->refresh();
+}
 
 //static
 void LLFloaterModelPreview::onUploadJointsCommit(LLUICtrl*,void* userdata)
@@ -3742,7 +3758,7 @@ BOOL LLModelPreview::render()
 		if (fmp)
 		{
 			fmp->enableViewOption("show_skin_weight");
-			fmp->setViewOptionEnabled("show_joint_positions", skin_weight);
+			fmp->setViewOptionEnabled("show_joint_positions", skin_weight);	
 		}
 		mFMP->childEnable("upload_skin");
 	}
diff --git a/indra/newview/llfloatermodelpreview.h b/indra/newview/llfloatermodelpreview.h
index ffda565fefc63022bf780a32624b803347f2df90..aac20244cc390175d0536ae990bd12f320674b53 100644
--- a/indra/newview/llfloatermodelpreview.h
+++ b/indra/newview/llfloatermodelpreview.h
@@ -183,6 +183,7 @@ class LLFloaterModelPreview : public LLFloater
 	friend class LLPhysicsDecomp;
 	
 	static void		onImportScaleCommit(LLUICtrl*, void*);
+	static void		onPelvisOffsetCommit(LLUICtrl*, void*);
 	static void		onUploadJointsCommit(LLUICtrl*,void*);
 	static void		onUploadSkinCommit(LLUICtrl*,void*);
 	
diff --git a/indra/newview/llmeshrepository.cpp b/indra/newview/llmeshrepository.cpp
index a9a8e28b00d3d7e36e0471c5fa2350a2554e9005..fb686fccd7deb2a357921a9bae7704da529a00c3 100755
--- a/indra/newview/llmeshrepository.cpp
+++ b/indra/newview/llmeshrepository.cpp
@@ -1162,7 +1162,12 @@ bool LLMeshRepoThread::skinInfoReceived(const LLUUID& mesh_id, U8* data, S32 dat
 				info.mAlternateBindMatrix.push_back(mat);
 			}
 		}
-		
+
+		if (skin.has("pelvis_offset"))
+		{
+			info.mPelvisOffset = skin["pelvis_offset"].asReal();
+		}
+
 		mSkinInfoQ.push(info);
 	}
 
diff --git a/indra/newview/llmeshrepository.h b/indra/newview/llmeshrepository.h
index 0fcb2213de78920ac38ea7777bf5e965af9ff227..ccdcc03310fa38c3c1ffaa2f2f24a24d2cfd21bc 100644
--- a/indra/newview/llmeshrepository.h
+++ b/indra/newview/llmeshrepository.h
@@ -131,6 +131,7 @@ class LLMeshSkinInfo
 	std::vector<LLMatrix4> mAlternateBindMatrix;
 	
 	LLMatrix4 mBindShapeMatrix;
+	float mPelvisOffset;
 };
 
 class LLMeshDecomposition
diff --git a/indra/newview/llstartup.cpp b/indra/newview/llstartup.cpp
index b98cbd5b78fd836fc41119ad01b62419a619adbc..aee3e6cfe90dc4f656d3f3baa5c9ec04c2ee24a9 100755
--- a/indra/newview/llstartup.cpp
+++ b/indra/newview/llstartup.cpp
@@ -775,6 +775,7 @@ bool idle_startup()
 		gViewerWindow->setNormalControlsVisible( FALSE );	
 		gLoginMenuBarView->setVisible( TRUE );
 		gLoginMenuBarView->setEnabled( TRUE );
+		show_debug_menus();
 
 		// Hide the splash screen
 		LLSplashScreen::hide();
diff --git a/indra/newview/lltexturecache.cpp b/indra/newview/lltexturecache.cpp
index f54214b95cbc6e173270fe7d39cc544299171c9e..7fb52c1939565298476948049db4becb0659e19a 100644
--- a/indra/newview/lltexturecache.cpp
+++ b/indra/newview/lltexturecache.cpp
@@ -1419,22 +1419,21 @@ void LLTextureCache::readHeaderCache()
 					}
 				}
 			}
-			if (num_entries > sCacheMaxEntries)
+			if (num_entries - empty_entries > sCacheMaxEntries)
 			{
 				// Special case: cache size was reduced, need to remove entries
 				// Note: After we prune entries, we will call this again and create the LRU
-				U32 entries_to_purge = (num_entries-empty_entries) - sCacheMaxEntries;
+				U32 entries_to_purge = (num_entries - empty_entries) - sCacheMaxEntries;
 				llinfos << "Texture Cache Entries: " << num_entries << " Max: " << sCacheMaxEntries << " Empty: " << empty_entries << " Purging: " << entries_to_purge << llendl;
-				if (entries_to_purge > 0)
+				// We can exit the following loop with the given condition, since if we'd reach the end of the lru set we'd have:
+				// purge_list.size() = lru.size() = num_entries - empty_entries = entries_to_purge + sCacheMaxEntries >= entries_to_purge
+				// So, it's certain that iter will never reach lru.end() first.
+				std::set<lru_data_t>::iterator iter = lru.begin();
+				while (purge_list.size() < entries_to_purge)
 				{
-					for (std::set<lru_data_t>::iterator iter = lru.begin(); iter != lru.end(); ++iter)
-					{
-						purge_list.insert(iter->second);
-						if (purge_list.size() >= entries_to_purge)
-							break;
-					}
+					purge_list.insert(iter->second);
+					++iter;
 				}
-				llassert_always(purge_list.size() >= entries_to_purge);
 			}
 			else
 			{
diff --git a/indra/newview/llviewerobjectlist.cpp b/indra/newview/llviewerobjectlist.cpp
index 1aa9987fd9d855f6e12c7bb5438b1469082b3487..007175383147c229baa3309ef3278d3f0223ddcf 100644
--- a/indra/newview/llviewerobjectlist.cpp
+++ b/indra/newview/llviewerobjectlist.cpp
@@ -1546,6 +1546,7 @@ void LLViewerObjectList::clearAllMapObjectsInRegion(LLViewerRegion* regionp)
 	}
 }
 
+
 void LLViewerObjectList::renderObjectsForMap(LLNetMap &netmap)
 {
 	LLColor4 above_water_color = LLUIColorTable::instance().getColor( "NetMapOtherOwnAboveWater" );
@@ -1565,7 +1566,6 @@ void LLViewerObjectList::renderObjectsForMap(LLNetMap &netmap)
 	{
 		LLViewerObject* objectp = *iter;
 
-		//llassert_always(!objectp->isDead());
 		if(objectp->isDead())//some dead objects somehow not cleaned.
 		{
 			continue ;
diff --git a/indra/newview/skins/default/xui/en/floater_model_preview.xml b/indra/newview/skins/default/xui/en/floater_model_preview.xml
index ca4e4a3a2abb95a777eef1e3980453bcab265f3c..e79dfcbc7d3cc82969d5e87ea93e004b35d9cb87 100644
--- a/indra/newview/skins/default/xui/en/floater_model_preview.xml
+++ b/indra/newview/skins/default/xui/en/floater_model_preview.xml
@@ -388,6 +388,13 @@
       <check_box top_pad="5" name="upload_textures" height="15" follows="top|left" label="Textures"/>
       <check_box top_pad="5" name="upload_skin" height="15" follows="top|left" label="Skin weight"/>
       <check_box top_pad="5" left="20" name="upload_joints" height="15" follows="top|left" label="Joint positions"/>
+
+      <text left="10" top_pad="4" width="90" bottom="30" follows="top|left" height="15">
+        Pelvis Offset:
+      </text>
+
+      <spinner left="10" top_pad="4" height="20" follows="top|left" width="80" value="0.0" min_val="0.00" max_val="32.0" name="pelvis_offset"/>
+
     </panel>
   </tab_container>
   
diff --git a/indra/newview/viewer_manifest.py b/indra/newview/viewer_manifest.py
index 1653a01b4a8291bd75eddd5480c7ce7b91e0bfa1..1a4551d069e612519d8661fab841348cc62f44f2 100644
--- a/indra/newview/viewer_manifest.py
+++ b/indra/newview/viewer_manifest.py
@@ -821,7 +821,7 @@ def package_finish(self):
                 self.run_command('SetFile -a V %r' % pathname)
 
             # Create the alias file (which is a resource file) from the .r
-            self.run_command('rez %r -o %r' %
+            self.run_command('Rez %r -o %r' %
                              (self.src_path_of("installers/darwin/release-dmg/Applications-alias.r"),
                               os.path.join(volpath, "Applications")))