diff --git a/indra/llcharacter/llcharacter.cpp b/indra/llcharacter/llcharacter.cpp
index 583f01cf91316cd8cccb15f123ae7c8a8710d8b7..c6ed3e6b5d3c79a24ffb635c8c06856d19bf8c3e 100644
--- a/indra/llcharacter/llcharacter.cpp
+++ b/indra/llcharacter/llcharacter.cpp
@@ -169,6 +169,15 @@ void LLCharacter::updateMotion(BOOL force_update)
 }
 
 
+//-----------------------------------------------------------------------------
+// deactivateAllMotions()
+//-----------------------------------------------------------------------------
+void LLCharacter::deactivateAllMotions()
+{
+	mMotionController.deactivateAllMotions();
+}
+
+
 //-----------------------------------------------------------------------------
 // flushAllMotions()
 //-----------------------------------------------------------------------------
diff --git a/indra/llcharacter/llcharacter.h b/indra/llcharacter/llcharacter.h
index 44fb6d08338e6975d1d25e31aa50cb927ee6d711..8f720d3b841f0e35e67be4145220a3f860b771f0 100644
--- a/indra/llcharacter/llcharacter.h
+++ b/indra/llcharacter/llcharacter.h
@@ -150,6 +150,9 @@ class LLCharacter
 	// no cached references to character joint data.  This is 
 	// useful if a character wants to rebuild it's skeleton.
 	virtual void flushAllMotions();
+	
+	// Flush only wipes active animations. 
+	virtual void deactivateAllMotions();
 
 	// dumps information for debugging
 	virtual void dumpCharacter( LLJoint *joint = NULL );
diff --git a/indra/llcharacter/llmotioncontroller.cpp b/indra/llcharacter/llmotioncontroller.cpp
index 71bbdfb9327db8e05a0bf4c45bea8abaf95d3652..fad69fc6e9d4734ab3712a82866c1b3aad18891a 100644
--- a/indra/llcharacter/llmotioncontroller.cpp
+++ b/indra/llcharacter/llmotioncontroller.cpp
@@ -835,6 +835,23 @@ LLMotion *LLMotionController::findMotion(const LLUUID& id)
 	return mAllMotions[id];
 }
 
+//-----------------------------------------------------------------------------
+// deactivateAllMotions()
+//-----------------------------------------------------------------------------
+void LLMotionController::deactivateAllMotions()
+{
+	//They must all die, precious.
+	for (std::map<LLUUID, LLMotion*>::iterator iter = mAllMotions.begin();
+		 iter != mAllMotions.end(); iter++)
+	{
+		LLMotion* motionp = iter->second;
+		if (motionp) motionp->deactivate();
+	}
+
+	// delete all motion instances
+	deleteAllMotions();
+}
+
 
 //-----------------------------------------------------------------------------
 // flushAllMotions()
diff --git a/indra/llcharacter/llmotioncontroller.h b/indra/llcharacter/llmotioncontroller.h
index a19e704643a871c6e83b756b6803ceedcf1cf765..15791b63188a15346db9e8432e466de50442aff4 100644
--- a/indra/llcharacter/llmotioncontroller.h
+++ b/indra/llcharacter/llmotioncontroller.h
@@ -138,6 +138,9 @@ class LLMotionController
 	// releases all motion instances
 	void flushAllMotions();
 
+	//Flush is a liar.
+	void deactivateAllMotions();	
+
 	// pause and continue all motions
 	void pause();
 	void unpause();
diff --git a/indra/newview/llpreview.cpp b/indra/newview/llpreview.cpp
index 562e4c37c1037bec4485ed750ad7f3f36424d7c3..c4f958420b9c86df4d673837ed80dc40aca71c2d 100644
--- a/indra/newview/llpreview.cpp
+++ b/indra/newview/llpreview.cpp
@@ -50,7 +50,7 @@ LLPreview::LLPreview(const std::string& name) :
 	mAutoFocus = FALSE;
 }
 
-LLPreview::LLPreview(const std::string& name, const LLRect& rect, const std::string& title, const LLUUID& item_uuid, const LLUUID& object_uuid, BOOL allow_resize, S32 min_width, S32 min_height, LLViewerInventoryItem* inv_item )
+LLPreview::LLPreview(const std::string& name, const LLRect& rect, const std::string& title, const LLUUID& item_uuid, const LLUUID& object_uuid, BOOL allow_resize, S32 min_width, S32 min_height, LLPointer<LLViewerInventoryItem> inv_item )
 :	LLFloater(name, rect, title, allow_resize, min_width, min_height ),
 	mItemUUID(item_uuid),
 	mSourceID(LLUUID::null),
@@ -135,11 +135,11 @@ void LLPreview::setSourceID(const LLUUID& source_id)
 	sPreviewsBySource.insert(preview_multimap_t::value_type(mSourceID, mViewHandle));
 }
 
-LLViewerInventoryItem* LLPreview::getItem() const
+const LLViewerInventoryItem *LLPreview::getItem() const
 {
-	if(mItem != NULL)
+	if(mItem)
 		return mItem;
-	LLViewerInventoryItem* item = NULL;
+	const LLViewerInventoryItem *item = NULL;
 	if(mObjectUUID.isNull())
 	{
 		// it's an inventory item, so get the item.
@@ -160,7 +160,7 @@ LLViewerInventoryItem* LLPreview::getItem() const
 // Sub-classes should override this function if they allow editing
 void LLPreview::onCommit()
 {
-	LLViewerInventoryItem* item = getItem();
+	const LLViewerInventoryItem *item = getItem();
 	if(item)
 	{
 		if (!item->isComplete())
@@ -333,7 +333,7 @@ BOOL LLPreview::handleHover(S32 x, S32 y, MASK mask)
 	{
 		S32 screen_x;
 		S32 screen_y;
-		LLViewerInventoryItem *item = getItem();
+		const LLViewerInventoryItem *item = getItem();
 
 		localPointToScreen(x, y, &screen_x, &screen_y );
 		if(item
@@ -419,7 +419,7 @@ void LLPreview::onDiscardBtn(void* data)
 {
 	LLPreview* self = (LLPreview*)data;
 
-	LLViewerInventoryItem* item = self->getItem();
+	const LLViewerInventoryItem* item = self->getItem();
 	if (!item) return;
 
 	self->mForceClose = TRUE;
diff --git a/indra/newview/llpreview.h b/indra/newview/llpreview.h
index 1b7c0fd9c83bda9417fdfd988f481482f5c58d93..589e1fde21bdfdc992022cb8077ef13cdcdaa185 100644
--- a/indra/newview/llpreview.h
+++ b/indra/newview/llpreview.h
@@ -51,13 +51,13 @@ class LLPreview : public LLFloater
 public:
 	// Used for XML-based construction.
 	LLPreview(const std::string& name);
-	LLPreview(const std::string& name, const LLRect& rect, const std::string& title, const LLUUID& item_uuid, const LLUUID& object_uuid, BOOL allow_resize = FALSE, S32 min_width = 0, S32 min_height = 0, LLViewerInventoryItem* inv_item = NULL );
+	LLPreview(const std::string& name, const LLRect& rect, const std::string& title, const LLUUID& item_uuid, const LLUUID& object_uuid, BOOL allow_resize = FALSE, S32 min_width = 0, S32 min_height = 0, LLPointer<LLViewerInventoryItem> inv_item = NULL );
 	virtual ~LLPreview();
 
 	void setItemID(const LLUUID& item_id);
 	void setObjectID(const LLUUID& object_id);
 	void setSourceID(const LLUUID& source_id);
-	LLViewerInventoryItem* getItem() const; // searches if not constructed with it
+	const LLViewerInventoryItem *getItem() const; // searches if not constructed with it
 
 	static LLPreview* find(const LLUUID& item_uuid);
 	static LLPreview*	show(const LLUUID& item_uuid, BOOL take_focus = TRUE );
@@ -134,7 +134,7 @@ class LLPreview : public LLFloater
 	static preview_map_t sInstances;
 	LLUUID mNotecardInventoryID;
 	LLUUID mObjectID;
-	LLViewerInventoryItem* mItem;
+	LLPointer<LLViewerInventoryItem> mItem;
 };
 
 
diff --git a/indra/newview/llpreviewanim.cpp b/indra/newview/llpreviewanim.cpp
index 99cff4b71885accc2ab3000fec4df6cb1f083d6e..6e3403932d14eb7417b5e0aef1377f233158ccca 100644
--- a/indra/newview/llpreviewanim.cpp
+++ b/indra/newview/llpreviewanim.cpp
@@ -31,7 +31,7 @@ LLPreviewAnim::LLPreviewAnim(const std::string& name, const LLRect& rect, const
 	childSetAction("Anim play btn",playAnim,this);
 	childSetAction("Anim audition btn",auditionAnim,this);
 
-	LLInventoryItem* item = getItem();
+	const LLInventoryItem* item = getItem();
 	
 	childSetCommitCallback("desc", LLPreview::onText, this);
 	childSetText("desc", item->getDescription());
@@ -87,7 +87,7 @@ void LLPreviewAnim::endAnimCallback( void *userdata )
 void LLPreviewAnim::playAnim( void *userdata )
 {
 	LLPreviewAnim* self = (LLPreviewAnim*) userdata;
-	LLInventoryItem *item = self->getItem();
+	const LLInventoryItem *item = self->getItem();
 
 	if(item)
 	{
@@ -124,7 +124,7 @@ void LLPreviewAnim::playAnim( void *userdata )
 void LLPreviewAnim::auditionAnim( void *userdata )
 {
 	LLPreviewAnim* self = (LLPreviewAnim*) userdata;
-	LLInventoryItem *item = self->getItem();
+	const LLInventoryItem *item = self->getItem();
 
 	if(item)
 	{
@@ -160,7 +160,7 @@ void LLPreviewAnim::auditionAnim( void *userdata )
 void LLPreviewAnim::saveAnim( void *userdata )
 {
 	LLPreviewAnim* self = (LLPreviewAnim*) userdata;
-	LLInventoryItem *item = self->getItem();
+	const LLInventoryItem *item = self->getItem();
 
 	if(item)
 	{
@@ -186,7 +186,7 @@ void LLPreviewAnim::saveAnim( void *userdata )
 
 void LLPreviewAnim::onClose(bool app_quitting)
 {
-	LLInventoryItem *item = getItem();
+	const LLInventoryItem *item = getItem();
 
 	if(item)
 	{
diff --git a/indra/newview/llpreviewgesture.cpp b/indra/newview/llpreviewgesture.cpp
index 9710fc8bf2928c83d77f1691a9c93626038719cf..c556e3f4506927c24926023c8eb2bb63c8a961d6 100644
--- a/indra/newview/llpreviewgesture.cpp
+++ b/indra/newview/llpreviewgesture.cpp
@@ -504,7 +504,7 @@ BOOL LLPreviewGesture::postBuild()
 	addSounds();
 
 
-	LLInventoryItem* item = getItem();
+	const LLInventoryItem* item = getItem();
 
 	if (item) 
 	{
@@ -830,7 +830,7 @@ void LLPreviewGesture::initDefaultGesture()
 
 void LLPreviewGesture::loadAsset()
 {
-	LLInventoryItem* item = getItem();
+	const LLInventoryItem* item = getItem();
 	if (!item) return;
 
 	LLUUID asset_id = item->getAssetUUID();
@@ -1100,7 +1100,7 @@ void LLPreviewGesture::saveIfNeeded()
 		file.write((U8*)buffer, size);
 
 		// Upload that asset to the database
-		LLInventoryItem* item = getItem();
+		const LLInventoryItem* item = getItem();
 		if (item)
 		{
 			std::string agent_url = gAgent.getRegion()->getCapability("UpdateGestureAgentInventory");
diff --git a/indra/newview/llpreviewnotecard.cpp b/indra/newview/llpreviewnotecard.cpp
index e5dfb9ae7684d7dcd00da400d649c8a535524f6f..8650bcf459187af8b68df90af40e452cf111afa2 100644
--- a/indra/newview/llpreviewnotecard.cpp
+++ b/indra/newview/llpreviewnotecard.cpp
@@ -62,7 +62,7 @@ LLPreviewNotecard::LLPreviewNotecard(const std::string& name,
 									 const LLUUID& object_id,
 									 const LLUUID& asset_id,
 									 BOOL show_keep_discard,
-									 LLViewerInventoryItem* inv_item) :
+									 LLPointer<LLViewerInventoryItem> inv_item) :
 	LLPreview(name, rect, title, item_id, object_id, TRUE,
 			  PREVIEW_MIN_WIDTH,
 			  PREVIEW_MIN_HEIGHT,
@@ -86,7 +86,7 @@ LLPreviewNotecard::LLPreviewNotecard(const std::string& name,
 		
 		if( mAssetID.isNull() )
 		{
-			LLInventoryItem* item = getItem();
+			const LLInventoryItem* item = getItem();
 			if( item )
 			{
 				mAssetID = item->getAssetUUID();
@@ -103,7 +103,7 @@ LLPreviewNotecard::LLPreviewNotecard(const std::string& name,
 			
 	childSetVisible("lock", FALSE);	
 	
-	LLInventoryItem* item = getItem();
+	const LLInventoryItem* item = getItem();
 	
 	childSetCommitCallback("desc", LLPreview::onText, this);
 	if (item)
@@ -242,7 +242,7 @@ void LLPreviewNotecard::refreshFromInventory()
 void LLPreviewNotecard::loadAsset()
 {
 	// request the asset.
-	LLInventoryItem* item = getItem();
+	const LLInventoryItem* item = getItem();
 	LLViewerTextEditor* editor = LLViewerUICtrlFactory::getViewerTextEditorByName(this, "Notecard Editor");
 
 	if (!editor)
@@ -366,7 +366,7 @@ void LLPreviewNotecard::onLoadComplete(LLVFS *vfs,
 
 			previewEditor->makePristine();
 
-			LLInventoryItem* item = preview->getItem();
+			const LLInventoryItem* item = preview->getItem();
 			BOOL modifiable = item && gAgent.allowOperation(PERM_MODIFY,
 								item->getPermissions(), GP_OBJECT_MANIPULATE);
 			preview->setEnabled(modifiable);
@@ -471,7 +471,7 @@ bool LLPreviewNotecard::saveIfNeeded(LLInventoryItem* copyitem)
 		file.setMaxSize(size);
 		file.write((U8*)buffer.c_str(), size);
 
-		LLInventoryItem* item = getItem();
+		const LLInventoryItem* item = getItem();
 		// save it out to database
 		if (item)
 		{			
diff --git a/indra/newview/llpreviewnotecard.h b/indra/newview/llpreviewnotecard.h
index 908d4da98cd3790ab5c97e831b9044c4009af3eb..88ce8b36ce49500aedfb233adcd641b63eb5f5df 100644
--- a/indra/newview/llpreviewnotecard.h
+++ b/indra/newview/llpreviewnotecard.h
@@ -30,7 +30,7 @@ class LLPreviewNotecard : public LLPreview
 					  const LLUUID& object_id = LLUUID::null,
 					  const LLUUID& asset_id = LLUUID::null,
 					  BOOL show_keep_discard = FALSE,
-					  LLViewerInventoryItem* inv_item = NULL);
+					  LLPointer<LLViewerInventoryItem> inv_item = NULL);
 
 	// llpreview	
 	virtual bool saveItem(LLPointer<LLInventoryItem>* itemptr);
diff --git a/indra/newview/llpreviewscript.cpp b/indra/newview/llpreviewscript.cpp
index 51ead9c5323ce9ef1e21b0f81711ef0292ba2d30..07e3853b2731dd2ba2f7b6df18307fab4b76f526 100644
--- a/indra/newview/llpreviewscript.cpp
+++ b/indra/newview/llpreviewscript.cpp
@@ -1077,7 +1077,7 @@ LLPreviewLSL::LLPreviewLSL(const std::string& name, const LLRect& rect,
 	moveResizeHandleToFront();
 
 	
-	LLInventoryItem* item = getItem();	
+	const LLInventoryItem* item = getItem();	
 
 	childSetCommitCallback("desc", LLPreview::onText, this);
 	childSetText("desc", item->getDescription());
@@ -1131,7 +1131,7 @@ void LLPreviewLSL::loadAsset()
 	// *HACK: we poke into inventory to see if it's there, and if so,
 	// then it might be part of the inventory library. If it's in the
 	// library, then you can see the script, but not modify it.
-	LLInventoryItem* item = gInventory.getItem(mItemUUID);
+	const LLInventoryItem* item = gInventory.getItem(mItemUUID);
 	BOOL is_library = item
 		&& !gInventory.isObjectDescendentOf(mItemUUID,
 											gAgent.getInventoryRootID());
@@ -1258,7 +1258,7 @@ void LLPreviewLSL::saveIfNeeded()
 	fclose(fp);
 	fp = NULL;
 
-	LLInventoryItem *inv_item = getItem();
+	const LLInventoryItem *inv_item = getItem();
 	// save it out to asset server
 	std::string url = gAgent.getRegion()->getCapability("UpdateScriptAgentInventory");
 	if(inv_item)
@@ -1373,8 +1373,8 @@ void LLPreviewLSL::onSaveComplete(const LLUUID& asset_uuid, void* user_data, S32
 	{
 		if (info)
 		{
-			LLViewerInventoryItem* item;
-			item = (LLViewerInventoryItem*)gInventory.getItem(info->mItemUUID);
+			const LLViewerInventoryItem* item;
+			item = (const LLViewerInventoryItem*)gInventory.getItem(info->mItemUUID);
 			if(item)
 			{
 				LLPointer<LLViewerInventoryItem> new_item = new LLViewerInventoryItem(item);
diff --git a/indra/newview/llpreviewsound.cpp b/indra/newview/llpreviewsound.cpp
index 871a0c55b7a72161cc7ceeab5fe5732820b859e1..7df0e48762cb0d759cb5e2ba7142baf55a633ec7 100644
--- a/indra/newview/llpreviewsound.cpp
+++ b/indra/newview/llpreviewsound.cpp
@@ -39,7 +39,7 @@ LLPreviewSound::LLPreviewSound(const std::string& name, const LLRect& rect, cons
 	button = LLUICtrlFactory::getButtonByName(this, "Sound audition btn");
 	button->setSoundFlags(LLView::SILENT);
 
-	LLInventoryItem* item = getItem();
+	const LLInventoryItem* item = getItem();
 	
 	childSetCommitCallback("desc", LLPreview::onText, this);
 	childSetText("desc", item->getDescription());
@@ -65,7 +65,7 @@ LLPreviewSound::LLPreviewSound(const std::string& name, const LLRect& rect, cons
 void LLPreviewSound::playSound( void *userdata )
 {
 	LLPreviewSound* self = (LLPreviewSound*) userdata;
-	LLInventoryItem *item = self->getItem();
+	const LLInventoryItem *item = self->getItem();
 
 	if(item && gAudiop)
 	{
@@ -77,7 +77,7 @@ void LLPreviewSound::playSound( void *userdata )
 void LLPreviewSound::auditionSound( void *userdata )
 {
 	LLPreviewSound* self = (LLPreviewSound*) userdata;
-	LLInventoryItem *item = self->getItem();
+	const LLInventoryItem *item = self->getItem();
 
 	if(item && gAudiop)
 	{
diff --git a/indra/newview/llpreviewtexture.cpp b/indra/newview/llpreviewtexture.cpp
index 214b3e38f8243065ac45b4aa7da435a871c008d1..974ee274768767260e0087fc95442fe7a30ac7d0 100644
--- a/indra/newview/llpreviewtexture.cpp
+++ b/indra/newview/llpreviewtexture.cpp
@@ -47,7 +47,7 @@ LLPreviewTexture::LLPreviewTexture(const std::string& name,
 	mLastHeight(0),
 	mLastWidth(0)
 {
-	LLInventoryItem *item = getItem();
+	const LLInventoryItem *item = getItem();
 	if(item)
 	{
 		mImageID = item->getAssetUUID();
@@ -157,7 +157,7 @@ void LLPreviewTexture::init()
 
 	if (!mCopyToInv) 
 	{
-		LLInventoryItem* item = getItem();
+		const LLInventoryItem* item = getItem();
 		
 		if (item)
 		{
diff --git a/indra/newview/llviewermenu.cpp b/indra/newview/llviewermenu.cpp
index 898af8932fd99d72fe9ddd8396dcf3cb5679c86e..1565a5875b8891ce1529f3d2c23b2b7135a15d9d 100644
--- a/indra/newview/llviewermenu.cpp
+++ b/indra/newview/llviewermenu.cpp
@@ -4538,11 +4538,7 @@ class LLToolsStopAllAnimations : public view_listener_t
 		
 		if (!avatarp) return true;
 		
-		LLVOAvatar::AnimSourceIterator anim_it = avatarp->mAnimationSources.begin();
-		for (;anim_it != avatarp->mAnimationSources.end(); ++anim_it)
-		{
-			avatarp->stopMotion( anim_it->second, TRUE );
-		}
+		avatarp->deactivateAllMotions();
 	
 		avatarp->processAnimationStateChanges();
 		return true;