diff --git a/indra/llcommon/llcommon.cpp b/indra/llcommon/llcommon.cpp
index 0069d03de0d487a55dc76bd8460f5972f954531f..268b12b02a565318d5803b87baefd604ab51724d 100644
--- a/indra/llcommon/llcommon.cpp
+++ b/indra/llcommon/llcommon.cpp
@@ -46,7 +46,7 @@ void LLCommon::initClass()
 		sAprInitialized = TRUE;
 	}
 	LLTimer::initClass();
-	LLThreadSafeRefCount::initClass();
+	LLThreadSafeRefCount::initThreadSafeRefCount();
 // 	LLWorkerThread::initClass();
 // 	LLFrameCallbackManager::initClass();
 }
@@ -56,7 +56,7 @@ void LLCommon::cleanupClass()
 {
 // 	LLFrameCallbackManager::cleanupClass();
 // 	LLWorkerThread::cleanupClass();
-	LLThreadSafeRefCount::cleanupClass();
+	LLThreadSafeRefCount::cleanupThreadSafeRefCount();
 	LLTimer::cleanupClass();
 	if (sAprInitialized)
 	{
diff --git a/indra/llcommon/llsdserialize.cpp b/indra/llcommon/llsdserialize.cpp
index e4ad00da6d2db6f96f110c6d9f766b4b785ac2b8..d496230dd88753f0d59aa3aa199f90c8daa05ceb 100644
--- a/indra/llcommon/llsdserialize.cpp
+++ b/indra/llcommon/llsdserialize.cpp
@@ -324,7 +324,7 @@ S32 LLSDParser::parse(std::istream& istr, LLSD& data, S32 max_bytes)
 S32 LLSDParser::parseLines(std::istream& istr, LLSD& data)
 {
 	mCheckLimits = false;
-	mParseLines = false;		// was true, Emergency fix DEV-17785 parsing newline failure
+	mParseLines = true;
 	return doParse(istr, data);
 }
 
diff --git a/indra/llcommon/llsdserialize_xml.cpp b/indra/llcommon/llsdserialize_xml.cpp
index 51a2e5ec408438ac5196348180b24a3270426540..edcc244f58108361e9424cda31f9e5542356cc18 100644
--- a/indra/llcommon/llsdserialize_xml.cpp
+++ b/indra/llcommon/llsdserialize_xml.cpp
@@ -461,11 +461,11 @@ S32 LLSDXMLParser::Impl::parseLines(std::istream& input, LLSD& data)
 				input.clear();
 			}
 		
-			// Don't parse the NULL at the end which might be added if \n was absorbed by getline()
+			// Re-insert with the \n that was absorbed by getline()
 			char * text = (char *) buffer;
 			if ( text[num_read - 1] == 0)
 			{
-				num_read--;
+				text[num_read - 1] = '\n';
 			}
 		}
 
@@ -808,12 +808,11 @@ void LLSDXMLParser::parsePart(const char *buf, int len)
 // virtual
 S32 LLSDXMLParser::doParse(std::istream& input, LLSD& data) const
 {
-// Remove code - emergency fix DEV-17785 parsing newline failure
-//	if (mParseLines)
-//	{
+	if (mParseLines)
+	{
 		// Use line-based reading (faster code)
-//		return impl.parseLines(input, data);
-//	}
+		return impl.parseLines(input, data);
+	}
 
 	return impl.parse(input, data);
 }
diff --git a/indra/llcommon/llstat.cpp b/indra/llcommon/llstat.cpp
index 21b723de71c94a5f6ed5bfbaede4d4c76d1c9431..80492d2e319dd792517f28c9fd0d6e5bef76ada7 100644
--- a/indra/llcommon/llstat.cpp
+++ b/indra/llcommon/llstat.cpp
@@ -34,47 +34,9 @@
 #include "llframetimer.h"
 #include "timing.h"
 
-class LLStatAccum::impl
-{
-public:
-	static const TimeScale IMPL_NUM_SCALES = (TimeScale)(SCALE_TWO_MINUTE + 1);
-	static U64 sScaleTimes[IMPL_NUM_SCALES];
-
-	BOOL	mUseFrameTimer;
-
-	BOOL	mRunning;
-	U64		mLastTime;
-	
-	struct Bucket
-	{
-		F64		accum;
-		U64		endTime;
-
-		BOOL	lastValid;
-		F64		lastAccum;
-	};
-
-	Bucket	mBuckets[IMPL_NUM_SCALES];
-
-	BOOL 	mLastSampleValid;
-	F64 	mLastSampleValue;
-
-
-	impl(bool useFrameTimer);
-
-	void reset(U64 when);
-
-	void sum(F64 value);
-	void sum(F64 value, U64 when);
-
-	F32 meanValue(TimeScale scale) const;
-
-	U64 getCurrentUsecs() const;
-		// Get current microseconds based on timer type
-};
 
 
-U64 LLStatAccum::impl::sScaleTimes[IMPL_NUM_SCALES] =
+U64 LLStatAccum::sScaleTimes[IMPL_NUM_SCALES] =
 {
 	USEC_PER_SEC / 10,				// 100 millisec
 	USEC_PER_SEC * 1,				// seconds
@@ -89,14 +51,22 @@ U64 LLStatAccum::impl::sScaleTimes[IMPL_NUM_SCALES] =
 };
 
 
-LLStatAccum::impl::impl(bool useFrameTimer)
+
+LLStatAccum::LLStatAccum(bool useFrameTimer)
+	: mUseFrameTimer(useFrameTimer),
+	  mRunning(FALSE),
+	  mLastSampleValue(0.0),
+	  mLastSampleValid(FALSE)
+{
+}
+
+LLStatAccum::~LLStatAccum()
 {
-	mUseFrameTimer = useFrameTimer;
-	mRunning = FALSE;
-	mLastSampleValid = FALSE;
 }
 
-void LLStatAccum::impl::reset(U64 when)
+
+
+void LLStatAccum::reset(U64 when)
 {
 	mRunning = TRUE;
 	mLastTime = when;
@@ -109,12 +79,12 @@ void LLStatAccum::impl::reset(U64 when)
 	}
 }
 
-void LLStatAccum::impl::sum(F64 value)
+void LLStatAccum::sum(F64 value)
 {
 	sum(value, getCurrentUsecs());
 }
 
-void LLStatAccum::impl::sum(F64 value, U64 when)
+void LLStatAccum::sum(F64 value, U64 when)
 {
 	if (!mRunning)
 	{
@@ -131,6 +101,9 @@ void LLStatAccum::impl::sum(F64 value, U64 when)
 		return;
 	}
 
+	// how long is this value for
+	U64 timeSpan = when - mLastTime;
+
 	for (int i = 0; i < IMPL_NUM_SCALES; ++i)
 	{
 		Bucket& bucket = mBuckets[i];
@@ -143,8 +116,6 @@ void LLStatAccum::impl::sum(F64 value, U64 when)
 		{
 			U64 timeScale = sScaleTimes[i];
 
-			U64 timeSpan = when - mLastTime;
-				// how long is this value for
 			U64 timeLeft = when - bucket.endTime;
 				// how much time is left after filling this bucket
 			
@@ -173,7 +144,7 @@ void LLStatAccum::impl::sum(F64 value, U64 when)
 }
 
 
-F32 LLStatAccum::impl::meanValue(TimeScale scale) const
+F32 LLStatAccum::meanValue(TimeScale scale) const
 {
 	if (!mRunning)
 	{
@@ -209,7 +180,7 @@ F32 LLStatAccum::impl::meanValue(TimeScale scale) const
 }
 
 
-U64 LLStatAccum::impl::getCurrentUsecs() const
+U64 LLStatAccum::getCurrentUsecs() const
 {
 	if (mUseFrameTimer)
 	{
@@ -222,24 +193,43 @@ U64 LLStatAccum::impl::getCurrentUsecs() const
 }
 
 
+// ------------------------------------------------------------------------
 
-
-
-LLStatAccum::LLStatAccum(bool useFrameTimer)
-	: m(* new impl(useFrameTimer))
+LLStatRate::LLStatRate(bool use_frame_timer)
+	: LLStatAccum(use_frame_timer)
 {
 }
 
-LLStatAccum::~LLStatAccum()
+void LLStatRate::count(U32 value)
 {
-	delete &m;
+	sum((F64)value * sScaleTimes[SCALE_SECOND]);
 }
 
-F32 LLStatAccum::meanValue(TimeScale scale) const
-{
-	return m.meanValue(scale);
-}
 
+void LLStatRate::mark()
+ { 
+	// Effectively the same as count(1), but sets mLastSampleValue
+	U64 when = getCurrentUsecs();
+
+	if ( mRunning 
+		 && (when > mLastTime) )
+	{	// Set mLastSampleValue to the time from the last mark()
+		F64 duration = ((F64)(when - mLastTime)) / sScaleTimes[SCALE_SECOND];
+		if ( duration > 0.0 )
+		{
+			mLastSampleValue = 1.0 / duration;
+		}
+		else
+		{
+			mLastSampleValue = 0.0;
+		}
+	}
+
+	sum( (F64) sScaleTimes[SCALE_SECOND], when);
+ }
+
+
+// ------------------------------------------------------------------------
 
 
 LLStatMeasure::LLStatMeasure(bool use_frame_timer)
@@ -249,53 +239,58 @@ LLStatMeasure::LLStatMeasure(bool use_frame_timer)
 
 void LLStatMeasure::sample(F64 value)
 {
-	U64 when = m.getCurrentUsecs();
+	U64 when = getCurrentUsecs();
 
-	if (m.mLastSampleValid)
+	if (mLastSampleValid)
 	{
-		F64 avgValue = (value + m.mLastSampleValue) / 2.0;
-		F64 interval = (F64)(when - m.mLastTime);
+		F64 avgValue = (value + mLastSampleValue) / 2.0;
+		F64 interval = (F64)(when - mLastTime);
 
-		m.sum(avgValue * interval, when);
+		sum(avgValue * interval, when);
 	}
 	else
 	{
-		m.reset(when);
+		reset(when);
 	}
 
-	m.mLastSampleValid = TRUE;
-	m.mLastSampleValue = value;
-}
-
-
-LLStatRate::LLStatRate(bool use_frame_timer)
-	: LLStatAccum(use_frame_timer)
-{
+	mLastSampleValid = TRUE;
+	mLastSampleValue = value;
 }
 
-void LLStatRate::count(U32 value)
-{
-	m.sum((F64)value * impl::sScaleTimes[SCALE_SECOND]);
-}
 
+// ------------------------------------------------------------------------
 
 LLStatTime::LLStatTime(bool use_frame_timer)
-	: LLStatAccum(use_frame_timer)
+	: LLStatAccum(use_frame_timer),
+	  mFrameNumber(0),
+	  mTotalTimeInFrame(0)
 {
+	mFrameNumber = LLFrameTimer::getFrameCount();
 }
 
 void LLStatTime::start()
 {
-	m.sum(0.0);
+	// Reset frame accumluation if the frame number has changed
+	U32 frame_number = LLFrameTimer::getFrameCount();
+	if ( frame_number != mFrameNumber)
+	{
+		mFrameNumber = frame_number;
+		mTotalTimeInFrame = 0;
+	}
+
+	sum(0.0);
 }
 
 void LLStatTime::stop()
 {
-	U64 endTime = m.getCurrentUsecs();
-	m.sum((F64)(endTime - m.mLastTime), endTime);
+	U64 end_time = getCurrentUsecs();
+	U64 duration = end_time - mLastTime;
+	sum(F64(duration), end_time);
+	mTotalTimeInFrame += duration;
 }
 
 
+// ------------------------------------------------------------------------
 
 LLTimer LLStat::sTimer;
 LLFrameTimer LLStat::sFrameTimer;
diff --git a/indra/llcommon/llstat.h b/indra/llcommon/llstat.h
index 5fa46fca75c1a68fc5ad98afe0031ac83281673e..d4dcb3a961b960d89e62383795e4937f591a52f0 100644
--- a/indra/llcommon/llstat.h
+++ b/indra/llcommon/llstat.h
@@ -67,6 +67,9 @@ class LLStatAccum
 		NUM_SCALES
 	};
 
+	static const TimeScale IMPL_NUM_SCALES = (TimeScale)(SCALE_TWO_MINUTE + 1);
+	static U64 sScaleTimes[IMPL_NUM_SCALES];
+
 	F32 meanValue(TimeScale scale) const;
 		// see the subclasses for the specific meaning of value
 
@@ -74,9 +77,32 @@ class LLStatAccum
 	F32 meanValueOverLastSecond() const	{ return meanValue(SCALE_SECOND); }
 	F32 meanValueOverLastMinute() const	{ return meanValue(SCALE_MINUTE); }
 
-protected:
-	class impl;
-	impl& m;
+	void reset(U64 when);
+
+	void sum(F64 value);
+	void sum(F64 value, U64 when);
+
+	U64 getCurrentUsecs() const;
+		// Get current microseconds based on timer type
+
+	BOOL	mUseFrameTimer;
+
+	BOOL	mRunning;
+	U64		mLastTime;
+	
+	struct Bucket
+	{
+		F64		accum;
+		U64		endTime;
+
+		BOOL	lastValid;
+		F64		lastAccum;
+	};
+
+	Bucket	mBuckets[IMPL_NUM_SCALES];
+
+	BOOL 	mLastSampleValid;
+	F64 	mLastSampleValue;
 };
 
 class LLStatMeasure : public LLStatAccum
@@ -105,7 +131,7 @@ class LLStatRate : public LLStatAccum
 	void count(U32);
 		// used to note that n items have occured
 	
-	void mark() { count(1); }
+	void mark();
 		// used for counting the rate thorugh a point in the code
 };
 
@@ -119,6 +145,9 @@ class LLStatTime : public LLStatAccum
 public:
 	LLStatTime(bool use_frame_timer = false);
 
+	U32		mFrameNumber;		// Current frame number
+	U64		mTotalTimeInFrame;	// Total time (microseconds) accumulated during the last frame
+
 private:
 	void start();
 	void stop();
diff --git a/indra/llcommon/llstl.h b/indra/llcommon/llstl.h
index 99fc83274b037b6048d981006b93cbfc73de828c..7b7e73470ea6eec77e697674f9cffc3e8ebca236 100644
--- a/indra/llcommon/llstl.h
+++ b/indra/llcommon/llstl.h
@@ -79,6 +79,9 @@ struct compare_pointer_contents
 // The general form is:
 //
 //  std::for_each(cont.begin(), cont.end(), DeletePointer());
+//  somemap.clear();
+//
+// Don't forget to clear()!
 
 struct DeletePointer
 {
@@ -95,7 +98,7 @@ struct DeletePointerArray
 	}
 };
 
-// DeletePointer is a simple helper for deleting all pointers in a map.
+// DeletePairedPointer is a simple helper for deleting all pointers in a map.
 // The general form is:
 //
 //  std::for_each(somemap.begin(), somemap.end(), DeletePairedPointer());
diff --git a/indra/llcommon/llthread.cpp b/indra/llcommon/llthread.cpp
index dc0a7a83e4cb213559e3be36745065070c32f218..cc58552099fea13969ae08fcd63260b8adae099b 100644
--- a/indra/llcommon/llthread.cpp
+++ b/indra/llcommon/llthread.cpp
@@ -359,7 +359,7 @@ void LLCondition::broadcast()
 LLMutex* LLThreadSafeRefCount::sMutex = 0;
 
 //static
-void LLThreadSafeRefCount::initClass()
+void LLThreadSafeRefCount::initThreadSafeRefCount()
 {
 	if (!sMutex)
 	{
@@ -368,7 +368,7 @@ void LLThreadSafeRefCount::initClass()
 }
 
 //static
-void LLThreadSafeRefCount::cleanupClass()
+void LLThreadSafeRefCount::cleanupThreadSafeRefCount()
 {
 	delete sMutex;
 	sMutex = NULL;
diff --git a/indra/llcommon/llthread.h b/indra/llcommon/llthread.h
index 7864d93395a1f27b4aa573ff6d5e10736c4f2e67..a6b2c0be7d4d51de94c49329a27b80f8fea21fdd 100644
--- a/indra/llcommon/llthread.h
+++ b/indra/llcommon/llthread.h
@@ -191,8 +191,8 @@ void LLThread::unlockData()
 class LLThreadSafeRefCount
 {
 public:
-	static void initClass(); // creates sMutex
-	static void cleanupClass(); // destroys sMutex
+	static void initThreadSafeRefCount(); // creates sMutex
+	static void cleanupThreadSafeRefCount(); // destroys sMutex
 	
 private:
 	static LLMutex* sMutex;
diff --git a/indra/llimage/llimage.cpp b/indra/llimage/llimage.cpp
index ef1467ce50fcec4efd9b1a7ac6386b88f366e6ae..4f4473a366e492e35fd54fd40beba20111dd16be 100644
--- a/indra/llimage/llimage.cpp
+++ b/indra/llimage/llimage.cpp
@@ -43,6 +43,49 @@
 #include "llimagejpeg.h"
 #include "llimagepng.h"
 #include "llimagedxt.h"
+#include "llimageworker.h"
+
+//---------------------------------------------------------------------------
+// LLImage
+//---------------------------------------------------------------------------
+
+//static
+std::string LLImage::sLastErrorMessage;
+LLMutex* LLImage::sMutex = NULL;
+
+//static
+void LLImage::initClass(LLWorkerThread* workerthread)
+{
+	sMutex = new LLMutex(NULL);
+	if (workerthread)
+	{
+		LLImageWorker::initImageWorker(workerthread);
+	}
+	LLImageJ2C::openDSO();
+}
+
+//static
+void LLImage::cleanupClass()
+{
+	LLImageJ2C::closeDSO();
+	LLImageWorker::cleanupImageWorker();
+	delete sMutex;
+	sMutex = NULL;
+}
+
+//static
+const std::string& LLImage::getLastError()
+{
+	static const std::string noerr("No Error");
+	return sLastErrorMessage.empty() ? noerr : sLastErrorMessage;
+}
+
+//static
+void LLImage::setLastError(const std::string& message)
+{
+	LLMutexLock m(sMutex);
+	sLastErrorMessage = message;
+}
 
 //---------------------------------------------------------------------------
 // LLImageBase
@@ -95,21 +138,8 @@ void LLImageBase::sanityCheck()
 	}
 }
 
-std::string LLImageBase::sLastErrorMessage;
 BOOL LLImageBase::sSizeOverride = FALSE;
 
-BOOL LLImageBase::setLastError(const std::string& message, const std::string& filename) 
-{
-	sLastErrorMessage = message;
-	if (!filename.empty())
-	{
-		sLastErrorMessage += " FILE:";
-		sLastErrorMessage += filename;
-	}
-	llwarns << sLastErrorMessage << llendl;
-	return FALSE;
-}
-
 // virtual
 void LLImageBase::deleteData()
 {
@@ -136,8 +166,6 @@ U8* LLImageBase::allocateData(S32 size)
 		llerrs << "LLImageBase::allocateData: bad size: " << size << llendl;
 	}
 	
-	resetLastError();
-
 	if (!mData || size != mDataSize)
 	{
 		deleteData(); // virtual
@@ -1269,6 +1297,23 @@ LLImageFormatted::~LLImageFormatted()
 
 //----------------------------------------------------------------------------
 
+//virtual
+void LLImageFormatted::resetLastError()
+{
+	LLImage::setLastError("");
+}
+
+//virtual
+void LLImageFormatted::setLastError(const std::string& message, const std::string& filename)
+{
+	std::string error = message;
+	if (!filename.empty())
+		error += std::string(" FILE: ") + filename;
+	LLImage::setLastError(error);
+}
+
+//----------------------------------------------------------------------------
+
 // static
 LLImageFormatted* LLImageFormatted::createFromType(S8 codec)
 {
diff --git a/indra/llimage/llimage.h b/indra/llimage/llimage.h
index 8db6a6c5bd900666234bc27bc7d4eeb19fa0ac6c..fbff9eae64271a561b90cccf262441f7952ce6d1 100644
--- a/indra/llimage/llimage.h
+++ b/indra/llimage/llimage.h
@@ -59,6 +59,7 @@ const S32 MAX_IMG_PACKET_SIZE = 1000;
 class LLImageFormatted;
 class LLImageRaw;
 class LLColor4U;
+class LLWorkerThread;
 
 typedef enum e_image_codec
 {
@@ -74,6 +75,24 @@ typedef enum e_image_codec
 } EImageCodec;
 
 //============================================================================
+// library initialization class
+
+class LLImage
+{
+public:
+	static void initClass(LLWorkerThread* workerthread);
+	static void cleanupClass();
+
+	static const std::string& getLastError();
+	static void setLastError(const std::string& message);
+	
+protected:
+	static LLMutex* sMutex;
+	static std::string sLastErrorMessage;
+};
+
+//============================================================================
+// Image base class
 
 class LLImageBase : public LLThreadSafeRefCount
 {
@@ -113,10 +132,6 @@ class LLImageBase : public LLThreadSafeRefCount
 	void setDataAndSize(U8 *data, S32 size) { mData = data; mDataSize = size; };
 	
 public:
-	static const std::string& getLastError() {return sLastErrorMessage;};
-	static void resetLastError() {sLastErrorMessage = "No Error"; };
-	static BOOL setLastError(const std::string& message, const std::string& filename = std::string()); // returns FALSE
-
 	static void generateMip(const U8 *indata, U8* mipdata, int width, int height, S32 nchannels);
 	
 	// Function for calculating the download priority for textures
@@ -141,8 +156,6 @@ class LLImageBase : public LLThreadSafeRefCount
 public:
 	S16 mMemType; // debug
 	
-	static std::string sLastErrorMessage;
-
 	static BOOL sSizeOverride;
 };
 
@@ -245,7 +258,6 @@ class LLImageFormatted : public LLImageBase
 	LLImageFormatted(S8 codec);
 
 	// LLImageBase
-public:
 	/*virtual*/ void deleteData();
 	/*virtual*/ U8* allocateData(S32 size = -1);
 	/*virtual*/ U8* reallocateData(S32 size);
@@ -254,7 +266,6 @@ class LLImageFormatted : public LLImageBase
 	/*virtual*/ void sanityCheck();
 
 	// New methods
-public:
 	// subclasses must return a prefered file extension (lowercase without a leading dot)
 	virtual std::string getExtension() = 0;
 	// calcHeaderSize() returns the maximum size of header;
@@ -287,6 +298,10 @@ class LLImageFormatted : public LLImageBase
 	void setDiscardLevel(S8 discard_level) { mDiscardLevel = discard_level; }
 	S8 getDiscardLevel() const { return mDiscardLevel; }
 
+	// setLastError needs to be deferred for J2C images since it may be called from a DLL
+	virtual void resetLastError();
+	virtual void setLastError(const std::string& message, const std::string& filename = std::string());
+	
 protected:
 	BOOL copyData(U8 *data, S32 size); // calls updateData()
 	
@@ -295,7 +310,7 @@ class LLImageFormatted : public LLImageBase
 	S8 mDecoding;
 	S8 mDecoded;
 	S8 mDiscardLevel;
-
+	
 public:
 	static S32 sGlobalFormattedMemory;
 };
diff --git a/indra/llimage/llimagej2c.cpp b/indra/llimage/llimagej2c.cpp
index 73c5b111c34e48dd9113d5c55c9c85ce5eb49f81..3b3d08d3aa350af1548af704b19e36215905ace9 100644
--- a/indra/llimage/llimagej2c.cpp
+++ b/indra/llimage/llimagej2c.cpp
@@ -218,6 +218,20 @@ LLImageJ2C::~LLImageJ2C()
 	}
 }
 
+// virtual
+void LLImageJ2C::resetLastError()
+{
+	mLastError.clear();
+}
+
+//virtual
+void LLImageJ2C::setLastError(const std::string& message, const std::string& filename)
+{
+	mLastError = message;
+	if (!filename.empty())
+		mLastError += std::string(" FILE: ") + filename;
+}
+
 // virtual
 S8  LLImageJ2C::getRawDiscardLevel()
 {
@@ -225,26 +239,34 @@ S8  LLImageJ2C::getRawDiscardLevel()
 }
 
 BOOL LLImageJ2C::updateData()
-{	
+{
+	BOOL res = TRUE;
 	resetLastError();
 
 	// Check to make sure that this instance has been initialized with data
 	if (!getData() || (getDataSize() < 16))
 	{
 		setLastError("LLImageJ2C uninitialized");
-		return FALSE;
+		res = FALSE;
+	}
+	else 
+	{
+		res = mImpl->getMetadata(*this);
 	}
 
-	if (!mImpl->getMetadata(*this))
+	if (res)
 	{
-		return FALSE;
+		// SJB: override discard based on mMaxBytes elsewhere
+		S32 max_bytes = getDataSize(); // mMaxBytes ? mMaxBytes : getDataSize();
+		S32 discard = calcDiscardLevelBytes(max_bytes);
+		setDiscardLevel(discard);
 	}
-	// SJB: override discard based on mMaxBytes elsewhere
-	S32 max_bytes = getDataSize(); // mMaxBytes ? mMaxBytes : getDataSize();
-	S32 discard = calcDiscardLevelBytes(max_bytes);
-	setDiscardLevel(discard);
 
-	return TRUE;
+	if (!mLastError.empty())
+	{
+		LLImage::setLastError(mLastError);
+	}
+	return res;
 }
 
 
@@ -258,20 +280,24 @@ BOOL LLImageJ2C::decodeChannels(LLImageRaw *raw_imagep, F32 decode_time, S32 fir
 {
 	LLMemType mt1((LLMemType::EMemType)mMemType);
 
+	BOOL res = TRUE;
+	
 	resetLastError();
 
 	// Check to make sure that this instance has been initialized with data
 	if (!getData() || (getDataSize() < 16))
 	{
 		setLastError("LLImageJ2C uninitialized");
-		return FALSE;
+		res = FALSE;
 	}
-
-	// Update the raw discard level
-	updateRawDiscardLevel();
-
-	mDecoding = TRUE;
-	BOOL res = mImpl->decodeImpl(*this, *raw_imagep, decode_time, first_channel, max_channel_count);
+	else
+	{
+		// Update the raw discard level
+		updateRawDiscardLevel();
+		mDecoding = TRUE;
+		res = mImpl->decodeImpl(*this, *raw_imagep, decode_time, first_channel, max_channel_count);
+	}
+	
 	if (res)
 	{
 		if (!mDecoding)
@@ -283,9 +309,14 @@ BOOL LLImageJ2C::decodeChannels(LLImageRaw *raw_imagep, F32 decode_time, S32 fir
 		{
 			mDecoding = FALSE;
 		}
-		return TRUE; // done
 	}
-	return FALSE;
+
+	if (!mLastError.empty())
+	{
+		LLImage::setLastError(mLastError);
+	}
+	
+	return res;
 }
 
 
@@ -298,7 +329,13 @@ BOOL LLImageJ2C::encode(const LLImageRaw *raw_imagep, F32 encode_time)
 BOOL LLImageJ2C::encode(const LLImageRaw *raw_imagep, const char* comment_text, F32 encode_time)
 {
 	LLMemType mt1((LLMemType::EMemType)mMemType);
-	return mImpl->encodeImpl(*this, *raw_imagep, comment_text, encode_time, mReversible);
+	resetLastError();
+	BOOL res = mImpl->encodeImpl(*this, *raw_imagep, comment_text, encode_time, mReversible);
+	if (!mLastError.empty())
+	{
+		LLImage::setLastError(mLastError);
+	}
+	return res;
 }
 
 //static
@@ -376,6 +413,8 @@ void LLImageJ2C::setReversible(const BOOL reversible)
 
 BOOL LLImageJ2C::loadAndValidate(const std::string &filename)
 {
+	BOOL res = TRUE;
+	
 	resetLastError();
 
 	S32 file_size = 0;
@@ -383,27 +422,38 @@ BOOL LLImageJ2C::loadAndValidate(const std::string &filename)
 	if (!apr_file)
 	{
 		setLastError("Unable to open file for reading", filename);
-		return FALSE;
+		res = FALSE;
 	}
-	if (file_size == 0)
+	else if (file_size == 0)
 	{
 		setLastError("File is empty",filename);
 		apr_file_close(apr_file);
-		return FALSE;
+		res = FALSE;
 	}
-	
-	U8 *data = new U8[file_size];
-	apr_size_t bytes_read = file_size;
-	apr_status_t s = apr_file_read(apr_file, data, &bytes_read); // modifies bytes_read	
-	if (s != APR_SUCCESS || (S32)bytes_read != file_size)
+	else
 	{
-		delete[] data;
-		setLastError("Unable to read entire file");
-		return FALSE;
+		U8 *data = new U8[file_size];
+		apr_size_t bytes_read = file_size;
+		apr_status_t s = apr_file_read(apr_file, data, &bytes_read); // modifies bytes_read	
+		apr_file_close(apr_file);
+		if (s != APR_SUCCESS || (S32)bytes_read != file_size)
+		{
+			delete[] data;
+			setLastError("Unable to read entire file");
+			res = FALSE;
+		}
+		else
+		{
+			res = validate(data, file_size);
+		}
 	}
-	apr_file_close(apr_file);
 
-	return validate(data, file_size);
+	if (!mLastError.empty())
+	{
+		LLImage::setLastError(mLastError);
+	}
+	
+	return res;
 }
 
 
@@ -411,21 +461,30 @@ BOOL LLImageJ2C::validate(U8 *data, U32 file_size)
 {
 	LLMemType mt1((LLMemType::EMemType)mMemType);
 
+	resetLastError();
+	
 	setData(data, file_size);
+
 	BOOL res = updateData();
-	if ( !res )
+	if ( res )
 	{
-		return FALSE;
+		// Check to make sure that this instance has been initialized with data
+		if (!getData() || (0 == getDataSize()))
+		{
+			setLastError("LLImageJ2C uninitialized");
+			res = FALSE;
+		}
+		else
+		{
+			res = mImpl->getMetadata(*this);
+		}
 	}
-
-	// Check to make sure that this instance has been initialized with data
-	if (!getData() || (0 == getDataSize()))
+	
+	if (!mLastError.empty())
 	{
-		setLastError("LLImageJ2C uninitialized");
-		return FALSE;
+		LLImage::setLastError(mLastError);
 	}
-
-	return mImpl->getMetadata(*this);
+	return res;
 }
 
 void LLImageJ2C::decodeFailed()
diff --git a/indra/llimage/llimagej2c.h b/indra/llimage/llimagej2c.h
index 03172d344ffd8233331ec0b1a5eda0e70d994654..4dc39ccc361f4598120592c13d39637f6bce31f4 100644
--- a/indra/llimage/llimagej2c.h
+++ b/indra/llimage/llimagej2c.h
@@ -54,6 +54,10 @@ class LLImageJ2C : public LLImageFormatted
 	/*virtual*/ S32 calcDataSize(S32 discard_level = 0);
 	/*virtual*/ S32 calcDiscardLevelBytes(S32 bytes);
 	/*virtual*/ S8  getRawDiscardLevel();
+	// Override these so that we don't try to set a global variable from a DLL
+	/*virtual*/ void resetLastError();
+	/*virtual*/ void setLastError(const std::string& message, const std::string& filename = std::string());
+	
 	
 	// Encode with comment text 
 	BOOL encode(const LLImageRaw *raw_imagep, const char* comment_text, F32 encode_time=0.0);
@@ -86,6 +90,7 @@ class LLImageJ2C : public LLImageFormatted
 	F32 mRate;
 	BOOL mReversible;
 	LLImageJ2CImpl *mImpl;
+	std::string mLastError;
 };
 
 // Derive from this class to implement JPEG2000 decoding
diff --git a/indra/llimage/llimageworker.cpp b/indra/llimage/llimageworker.cpp
index cdec2bfe6c80925eeedb764c47724a4a65c9b35c..cbc6ea7911b2e3975bc9922fd8260c45391e4179 100644
--- a/indra/llimage/llimageworker.cpp
+++ b/indra/llimage/llimageworker.cpp
@@ -41,13 +41,13 @@ LLWorkerThread* LLImageWorker::sWorkerThread = NULL;
 S32 LLImageWorker::sCount = 0;
 
 //static
-void LLImageWorker::initClass(LLWorkerThread* workerthread)
+void LLImageWorker::initImageWorker(LLWorkerThread* workerthread)
 {
 	sWorkerThread = workerthread;
 }
 
 //static
-void LLImageWorker::cleanupClass()
+void LLImageWorker::cleanupImageWorker()
 {
 }
 
diff --git a/indra/llimage/llimageworker.h b/indra/llimage/llimageworker.h
index f9c592fa5145008b0a38886099dacec3ff25f202..f3304130ea591e7230e88fc8b54b3d6b49a9658d 100644
--- a/indra/llimage/llimageworker.h
+++ b/indra/llimage/llimageworker.h
@@ -38,8 +38,10 @@
 class LLImageWorker : public LLWorkerClass
 {
 public:
-	static void initClass(LLWorkerThread* workerthread);
-	static void cleanupClass();
+	static void initImageWorker(LLWorkerThread* workerthread);
+	static void cleanupImageWorker();
+	
+public:
 	static LLWorkerThread* getWorkerThread() { return sWorkerThread; }
 
 	// LLWorkerThread
diff --git a/indra/llmath/v3color.h b/indra/llmath/v3color.h
index e2a8274839f752737747672fdb6390705b3f9201..05f6186893db09e577c86c9d0e12a3c8613a5446 100644
--- a/indra/llmath/v3color.h
+++ b/indra/llmath/v3color.h
@@ -82,13 +82,23 @@ class LLColor3
 	
 	const LLColor3&	setToBlack();					// Clears LLColor3 to (0, 0, 0)
 	const LLColor3&	setToWhite();					// Zero LLColor3 to (0, 0, 0)
-	const LLColor3&	setVec(F32 x, F32 y, F32 z);	// Sets LLColor3 to (x, y, z)
-	const LLColor3&	setVec(const LLColor3 &vec);	// Sets LLColor3 to vec
-	const LLColor3&	setVec(const F32 *vec);			// Sets LLColor3 to vec
+	
+	const LLColor3&	setVec(F32 x, F32 y, F32 z);	// deprecated
+	const LLColor3&	setVec(const LLColor3 &vec);	// deprecated
+	const LLColor3&	setVec(const F32 *vec);			// deprecated
+
+	const LLColor3&	set(F32 x, F32 y, F32 z);	// Sets LLColor3 to (x, y, z)
+	const LLColor3&	set(const LLColor3 &vec);	// Sets LLColor3 to vec
+	const LLColor3&	set(const F32 *vec);		// Sets LLColor3 to vec
+
+	F32		magVec() const;				// deprecated
+	F32		magVecSquared() const;		// deprecated
+	F32		normVec();					// deprecated
+
+	F32		length() const;				// Returns magnitude of LLColor3
+	F32		lengthSquared() const;		// Returns magnitude squared of LLColor3
+	F32		normalize();				// Normalizes and returns the magnitude of LLColor3
 
-	F32		magVec() const;				// Returns magnitude of LLColor3
-	F32		magVecSquared() const;		// Returns magnitude squared of LLColor3
-	F32		normVec();					// Normalizes and returns the magnitude of LLColor3
 	F32		brightness() const;			// Returns brightness of LLColor3
 
 	const LLColor3&	operator=(const LLColor4 &a);
@@ -214,6 +224,31 @@ inline const LLColor3&	LLColor3::setToWhite(void)
 	return (*this);
 }
 
+inline const LLColor3&	LLColor3::set(F32 r, F32 g, F32 b)
+{
+	mV[0] = r;
+	mV[1] = g;
+	mV[2] = b;
+	return (*this);
+}
+
+inline const LLColor3&	LLColor3::set(const LLColor3 &vec)
+{
+	mV[0] = vec.mV[0];
+	mV[1] = vec.mV[1];
+	mV[2] = vec.mV[2];
+	return (*this);
+}
+
+inline const LLColor3&	LLColor3::set(const F32 *vec)
+{
+	mV[0] = vec[0];
+	mV[1] = vec[1];
+	mV[2] = vec[2];
+	return (*this);
+}
+
+// deprecated
 inline const LLColor3&	LLColor3::setVec(F32 r, F32 g, F32 b)
 {
 	mV[0] = r;
@@ -222,6 +257,7 @@ inline const LLColor3&	LLColor3::setVec(F32 r, F32 g, F32 b)
 	return (*this);
 }
 
+// deprecated
 inline const LLColor3&	LLColor3::setVec(const LLColor3 &vec)
 {
 	mV[0] = vec.mV[0];
@@ -230,6 +266,7 @@ inline const LLColor3&	LLColor3::setVec(const LLColor3 &vec)
 	return (*this);
 }
 
+// deprecated
 inline const LLColor3&	LLColor3::setVec(const F32 *vec)
 {
 	mV[0] = vec[0];
@@ -243,16 +280,44 @@ inline F32		LLColor3::brightness(void) const
 	return (mV[0] + mV[1] + mV[2]) / 3.0f;
 }
 
+inline F32		LLColor3::length(void) const
+{
+	return fsqrtf(mV[0]*mV[0] + mV[1]*mV[1] + mV[2]*mV[2]);
+}
+
+inline F32		LLColor3::lengthSquared(void) const
+{
+	return mV[0]*mV[0] + mV[1]*mV[1] + mV[2]*mV[2];
+}
+
+inline F32		LLColor3::normalize(void)
+{
+	F32 mag = fsqrtf(mV[0]*mV[0] + mV[1]*mV[1] + mV[2]*mV[2]);
+	F32 oomag;
+
+	if (mag)
+	{
+		oomag = 1.f/mag;
+		mV[0] *= oomag;
+		mV[1] *= oomag;
+		mV[2] *= oomag;
+	}
+	return (mag);
+}
+
+// deprecated
 inline F32		LLColor3::magVec(void) const
 {
 	return fsqrtf(mV[0]*mV[0] + mV[1]*mV[1] + mV[2]*mV[2]);
 }
 
+// deprecated
 inline F32		LLColor3::magVecSquared(void) const
 {
 	return mV[0]*mV[0] + mV[1]*mV[1] + mV[2]*mV[2];
 }
 
+// deprecated
 inline F32		LLColor3::normVec(void)
 {
 	F32 mag = fsqrtf(mV[0]*mV[0] + mV[1]*mV[1] + mV[2]*mV[2]);
diff --git a/indra/llmath/v4color.cpp b/indra/llmath/v4color.cpp
index 8ba329eaf2de3896d14a1923eed77e8b92b8ba56..c66fe66c92beb1da89bafe63db3c872ab32ea7e1 100644
--- a/indra/llmath/v4color.cpp
+++ b/indra/llmath/v4color.cpp
@@ -161,6 +161,38 @@ LLColor4::LLColor4(const LLVector4& vector4)
 	mV[VW] = vector4.mV[VW];
 }
 
+const LLColor4&	LLColor4::set(const LLColor4U& color4u)
+{
+	const F32 SCALE = 1.f/255.f;
+	mV[VX] = color4u.mV[VX] * SCALE;
+	mV[VY] = color4u.mV[VY] * SCALE;
+	mV[VZ] = color4u.mV[VZ] * SCALE;
+	mV[VW] = color4u.mV[VW] * SCALE;
+	return (*this);
+}
+
+const LLColor4&	LLColor4::set(const LLColor3 &vec)
+{
+	mV[VX] = vec.mV[VX];
+	mV[VY] = vec.mV[VY];
+	mV[VZ] = vec.mV[VZ];
+
+//  no change to alpha!
+//	mV[VW] = 1.f;  
+
+	return (*this);
+}
+
+const LLColor4&	LLColor4::set(const LLColor3 &vec, F32 a)
+{
+	mV[VX] = vec.mV[VX];
+	mV[VY] = vec.mV[VY];
+	mV[VZ] = vec.mV[VZ];
+	mV[VW] = a;
+	return (*this);
+}
+
+// deprecated -- use set()
 const LLColor4&	LLColor4::setVec(const LLColor4U& color4u)
 {
 	const F32 SCALE = 1.f/255.f;
@@ -171,6 +203,7 @@ const LLColor4&	LLColor4::setVec(const LLColor4U& color4u)
 	return (*this);
 }
 
+// deprecated -- use set()
 const LLColor4&	LLColor4::setVec(const LLColor3 &vec)
 {
 	mV[VX] = vec.mV[VX];
@@ -183,6 +216,7 @@ const LLColor4&	LLColor4::setVec(const LLColor3 &vec)
 	return (*this);
 }
 
+// deprecated -- use set()
 const LLColor4&	LLColor4::setVec(const LLColor3 &vec, F32 a)
 {
 	mV[VX] = vec.mV[VX];
@@ -338,270 +372,270 @@ BOOL LLColor4::parseColor(const std::string& buf, LLColor4* color)
 		{
 			v = v * (1.f / 255.f);
 		}
-		color->setVec( v );
+		color->set( v );
 	}
 	else // Single value.  Read as a named color.
 	{
 		// We have a color name
 		if ( "red" == color_name )
 		{
-			color->setVec(LLColor4::red);
+			color->set(LLColor4::red);
 		}
 		else if ( "red1" == color_name )
 		{
-			color->setVec(LLColor4::red1);
+			color->set(LLColor4::red1);
 		}
 		else if ( "red2" == color_name )
 		{
-			color->setVec(LLColor4::red2);
+			color->set(LLColor4::red2);
 		}
 		else if ( "red3" == color_name )
 		{
-			color->setVec(LLColor4::red3);
+			color->set(LLColor4::red3);
 		}
 		else if ( "red4" == color_name )
 		{
-			color->setVec(LLColor4::red4);
+			color->set(LLColor4::red4);
 		}
 		else if ( "red5" == color_name )
 		{
-			color->setVec(LLColor4::red5);
+			color->set(LLColor4::red5);
 		}
 		else if( "green" == color_name )
 		{
-			color->setVec(LLColor4::green);
+			color->set(LLColor4::green);
 		}
 		else if( "green1" == color_name )
 		{
-			color->setVec(LLColor4::green1);
+			color->set(LLColor4::green1);
 		}
 		else if( "green2" == color_name )
 		{
-			color->setVec(LLColor4::green2);
+			color->set(LLColor4::green2);
 		}
 		else if( "green3" == color_name )
 		{
-			color->setVec(LLColor4::green3);
+			color->set(LLColor4::green3);
 		}
 		else if( "green4" == color_name )
 		{
-			color->setVec(LLColor4::green4);
+			color->set(LLColor4::green4);
 		}
 		else if( "green5" == color_name )
 		{
-			color->setVec(LLColor4::green5);
+			color->set(LLColor4::green5);
 		}
 		else if( "green6" == color_name )
 		{
-			color->setVec(LLColor4::green6);
+			color->set(LLColor4::green6);
 		}
 		else if( "blue" == color_name )
 		{
-			color->setVec(LLColor4::blue);
+			color->set(LLColor4::blue);
 		}
 		else if( "blue1" == color_name )
 		{
-			color->setVec(LLColor4::blue1);
+			color->set(LLColor4::blue1);
 		}
 		else if( "blue2" == color_name )
 		{
-			color->setVec(LLColor4::blue2);
+			color->set(LLColor4::blue2);
 		}
 		else if( "blue3" == color_name )
 		{
-			color->setVec(LLColor4::blue3);
+			color->set(LLColor4::blue3);
 		}
 		else if( "blue4" == color_name )
 		{
-			color->setVec(LLColor4::blue4);
+			color->set(LLColor4::blue4);
 		}
 		else if( "blue5" == color_name )
 		{
-			color->setVec(LLColor4::blue5);
+			color->set(LLColor4::blue5);
 		}
 		else if( "blue6" == color_name )
 		{
-			color->setVec(LLColor4::blue6);
+			color->set(LLColor4::blue6);
 		}
 		else if( "black" == color_name )
 		{
-			color->setVec(LLColor4::black);
+			color->set(LLColor4::black);
 		}
 		else if( "white" == color_name )
 		{
-			color->setVec(LLColor4::white);
+			color->set(LLColor4::white);
 		}
 		else if( "yellow" == color_name )
 		{
-			color->setVec(LLColor4::yellow);
+			color->set(LLColor4::yellow);
 		}
 		else if( "yellow1" == color_name )
 		{
-			color->setVec(LLColor4::yellow1);
+			color->set(LLColor4::yellow1);
 		}
 		else if( "yellow2" == color_name )
 		{
-			color->setVec(LLColor4::yellow2);
+			color->set(LLColor4::yellow2);
 		}
 		else if( "yellow3" == color_name )
 		{
-			color->setVec(LLColor4::yellow3);
+			color->set(LLColor4::yellow3);
 		}
 		else if( "yellow4" == color_name )
 		{
-			color->setVec(LLColor4::yellow4);
+			color->set(LLColor4::yellow4);
 		}
 		else if( "yellow5" == color_name )
 		{
-			color->setVec(LLColor4::yellow5);
+			color->set(LLColor4::yellow5);
 		}
 		else if( "yellow6" == color_name )
 		{
-			color->setVec(LLColor4::yellow6);
+			color->set(LLColor4::yellow6);
 		}
 		else if( "magenta" == color_name )
 		{
-			color->setVec(LLColor4::magenta);
+			color->set(LLColor4::magenta);
 		}
 		else if( "magenta1" == color_name )
 		{
-			color->setVec(LLColor4::magenta1);
+			color->set(LLColor4::magenta1);
 		}
 		else if( "magenta2" == color_name )
 		{
-			color->setVec(LLColor4::magenta2);
+			color->set(LLColor4::magenta2);
 		}
 		else if( "magenta3" == color_name )
 		{
-			color->setVec(LLColor4::magenta3);
+			color->set(LLColor4::magenta3);
 		}
 		else if( "magenta4" == color_name )
 		{
-			color->setVec(LLColor4::magenta4);
+			color->set(LLColor4::magenta4);
 		}
 		else if( "purple" == color_name )
 		{
-			color->setVec(LLColor4::purple);
+			color->set(LLColor4::purple);
 		}
 		else if( "purple1" == color_name )
 		{
-			color->setVec(LLColor4::purple1);
+			color->set(LLColor4::purple1);
 		}
 		else if( "purple2" == color_name )
 		{
-			color->setVec(LLColor4::purple2);
+			color->set(LLColor4::purple2);
 		}
 		else if( "purple3" == color_name )
 		{
-			color->setVec(LLColor4::purple3);
+			color->set(LLColor4::purple3);
 		}
 		else if( "purple4" == color_name )
 		{
-			color->setVec(LLColor4::purple4);
+			color->set(LLColor4::purple4);
 		}
 		else if( "purple5" == color_name )
 		{
-			color->setVec(LLColor4::purple5);
+			color->set(LLColor4::purple5);
 		}
 		else if( "purple6" == color_name )
 		{
-			color->setVec(LLColor4::purple6);
+			color->set(LLColor4::purple6);
 		}
 		else if( "pink" == color_name )
 		{
-			color->setVec(LLColor4::pink);
+			color->set(LLColor4::pink);
 		}
 		else if( "pink1" == color_name )
 		{
-			color->setVec(LLColor4::pink1);
+			color->set(LLColor4::pink1);
 		}
 		else if( "pink2" == color_name )
 		{
-			color->setVec(LLColor4::pink2);
+			color->set(LLColor4::pink2);
 		}
 		else if( "cyan" == color_name )
 		{
-			color->setVec(LLColor4::cyan);
+			color->set(LLColor4::cyan);
 		}
 		else if( "cyan1" == color_name )
 		{
-			color->setVec(LLColor4::cyan1);
+			color->set(LLColor4::cyan1);
 		}
 		else if( "cyan2" == color_name )
 		{
-			color->setVec(LLColor4::cyan2);
+			color->set(LLColor4::cyan2);
 		}
 		else if( "cyan3" == color_name )
 		{
-			color->setVec(LLColor4::cyan3);
+			color->set(LLColor4::cyan3);
 		}
 		else if( "cyan4" == color_name )
 		{
-			color->setVec(LLColor4::cyan4);
+			color->set(LLColor4::cyan4);
 		}
 		else if( "cyan5" == color_name )
 		{
-			color->setVec(LLColor4::cyan5);
+			color->set(LLColor4::cyan5);
 		}
 		else if( "cyan6" == color_name )
 		{
-			color->setVec(LLColor4::cyan6);
+			color->set(LLColor4::cyan6);
 		}
 		else if( "smoke" == color_name )
 		{
-			color->setVec(LLColor4::smoke);
+			color->set(LLColor4::smoke);
 		}
 		else if( "grey" == color_name )
 		{
-			color->setVec(LLColor4::grey);
+			color->set(LLColor4::grey);
 		}
 		else if( "grey1" == color_name )
 		{
-			color->setVec(LLColor4::grey1);
+			color->set(LLColor4::grey1);
 		}
 		else if( "grey2" == color_name )
 		{
-			color->setVec(LLColor4::grey2);
+			color->set(LLColor4::grey2);
 		}
 		else if( "grey3" == color_name )
 		{
-			color->setVec(LLColor4::grey3);
+			color->set(LLColor4::grey3);
 		}
 		else if( "grey4" == color_name )
 		{
-			color->setVec(LLColor4::grey4);
+			color->set(LLColor4::grey4);
 		}
 		else if( "orange" == color_name )
 		{
-			color->setVec(LLColor4::orange);
+			color->set(LLColor4::orange);
 		}
 		else if( "orange1" == color_name )
 		{
-			color->setVec(LLColor4::orange1);
+			color->set(LLColor4::orange1);
 		}
 		else if( "orange2" == color_name )
 		{
-			color->setVec(LLColor4::orange2);
+			color->set(LLColor4::orange2);
 		}
 		else if( "orange3" == color_name )
 		{
-			color->setVec(LLColor4::orange3);
+			color->set(LLColor4::orange3);
 		}
 		else if( "orange4" == color_name )
 		{
-			color->setVec(LLColor4::orange4);
+			color->set(LLColor4::orange4);
 		}
 		else if( "orange5" == color_name )
 		{
-			color->setVec(LLColor4::orange5);
+			color->set(LLColor4::orange5);
 		}
 		else if( "orange6" == color_name )
 		{
-			color->setVec(LLColor4::orange6);
+			color->set(LLColor4::orange6);
 		}
 		else if ( "clear" == color_name )
 		{
-			color->setVec(0.f, 0.f, 0.f, 0.f);
+			color->set(0.f, 0.f, 0.f, 0.f);
 		}
 		else
 		{
diff --git a/indra/llmath/v4color.h b/indra/llmath/v4color.h
index 62c0b663b89a30cdfcaf3e439ef1afb9ce164d1a..98f04130d65c7c815b29b2693b0a0b2daf3ca2ac 100644
--- a/indra/llmath/v4color.h
+++ b/indra/llmath/v4color.h
@@ -84,20 +84,33 @@ class LLColor4
 		const LLColor4&	setToBlack();						// zero LLColor4 to (0, 0, 0, 1)
 		const LLColor4&	setToWhite();						// zero LLColor4 to (0, 0, 0, 1)
 
-		const LLColor4&	setVec(F32 r, F32 g, F32 b, F32 a);	// Sets LLColor4 to (r, g, b, a)
-		const LLColor4&	setVec(F32 r, F32 g, F32 b);	// Sets LLColor4 to (r, g, b) (no change in a)
-		const LLColor4&	setVec(const LLColor4 &vec);	// Sets LLColor4 to vec
-		const LLColor4&	setVec(const LLColor3 &vec);	// Sets LLColor4 to LLColor3 vec (no change in alpha)
-		const LLColor4&	setVec(const LLColor3 &vec, F32 a);	// Sets LLColor4 to LLColor3 vec, with alpha specified
-		const LLColor4&	setVec(const F32 *vec);			// Sets LLColor4 to vec
-		const LLColor4&	setVec(const LLColor4U& color4u); // Sets LLColor4 to color4u, rescaled.
+		const LLColor4&	setVec(F32 r, F32 g, F32 b, F32 a);	// deprecated -- use set()
+		const LLColor4&	setVec(F32 r, F32 g, F32 b);		// deprecated -- use set()
+		const LLColor4&	setVec(const LLColor4 &vec);		// deprecated -- use set()
+		const LLColor4&	setVec(const LLColor3 &vec);		// deprecated -- use set()
+		const LLColor4&	setVec(const LLColor3 &vec, F32 a);	// deprecated -- use set()
+		const LLColor4&	setVec(const F32 *vec);				// deprecated -- use set()
+		const LLColor4&	setVec(const LLColor4U& color4u); 	// deprecated -- use set()
+
+		const LLColor4&	set(F32 r, F32 g, F32 b, F32 a);	// Sets LLColor4 to (r, g, b, a)
+		const LLColor4&	set(F32 r, F32 g, F32 b);	// Sets LLColor4 to (r, g, b) (no change in a)
+		const LLColor4&	set(const LLColor4 &vec);	// Sets LLColor4 to vec
+		const LLColor4&	set(const LLColor3 &vec);	// Sets LLColor4 to LLColor3 vec (no change in alpha)
+		const LLColor4&	set(const LLColor3 &vec, F32 a);	// Sets LLColor4 to LLColor3 vec, with alpha specified
+		const LLColor4&	set(const F32 *vec);			// Sets LLColor4 to vec
+		const LLColor4&	set(const LLColor4U& color4u); // Sets LLColor4 to color4u, rescaled.
 
 
 		const LLColor4&    setAlpha(F32 a);
 
-		F32			magVec() const;				// Returns magnitude of LLColor4
-		F32			magVecSquared() const;		// Returns magnitude squared of LLColor4
-		F32			normVec();					// Normalizes and returns the magnitude of LLColor4
+		F32			magVec() const;				// deprecated -- use length()
+		F32			magVecSquared() const;		// deprecated -- use lengthSquared()
+		F32			normVec();					// deprecated -- use normalize()
+
+		F32			length() const;				// Returns magnitude of LLColor4
+		F32			lengthSquared() const;		// Returns magnitude squared of LLColor4
+		F32			normalize();				// deprecated -- use normalize()
+
 		BOOL		isOpaque() { return mV[VALPHA] == 1.f; }
 
 		F32 operator[](int idx) const { return mV[idx]; }
@@ -289,6 +302,47 @@ inline const LLColor4&	LLColor4::setToWhite(void)
 	return (*this);
 }
 
+inline const LLColor4&	LLColor4::set(F32 x, F32 y, F32 z)
+{
+	mV[VX] = x;
+	mV[VY] = y;
+	mV[VZ] = z;
+
+//  no change to alpha!
+//	mV[VW] = 1.f;  
+
+	return (*this);
+}
+
+inline const LLColor4&	LLColor4::set(F32 x, F32 y, F32 z, F32 a)
+{
+	mV[VX] = x;
+	mV[VY] = y;
+	mV[VZ] = z;
+	mV[VW] = a;  
+	return (*this);
+}
+
+inline const LLColor4&	LLColor4::set(const LLColor4 &vec)
+{
+	mV[VX] = vec.mV[VX];
+	mV[VY] = vec.mV[VY];
+	mV[VZ] = vec.mV[VZ];
+	mV[VW] = vec.mV[VW];
+	return (*this);
+}
+
+
+inline const LLColor4&	LLColor4::set(const F32 *vec)
+{
+	mV[VX] = vec[VX];
+	mV[VY] = vec[VY];
+	mV[VZ] = vec[VZ];
+	mV[VW] = vec[VW];
+	return (*this);
+}
+
+// deprecated
 inline const LLColor4&	LLColor4::setVec(F32 x, F32 y, F32 z)
 {
 	mV[VX] = x;
@@ -301,6 +355,7 @@ inline const LLColor4&	LLColor4::setVec(F32 x, F32 y, F32 z)
 	return (*this);
 }
 
+// deprecated
 inline const LLColor4&	LLColor4::setVec(F32 x, F32 y, F32 z, F32 a)
 {
 	mV[VX] = x;
@@ -310,6 +365,7 @@ inline const LLColor4&	LLColor4::setVec(F32 x, F32 y, F32 z, F32 a)
 	return (*this);
 }
 
+// deprecated
 inline const LLColor4&	LLColor4::setVec(const LLColor4 &vec)
 {
 	mV[VX] = vec.mV[VX];
@@ -320,6 +376,7 @@ inline const LLColor4&	LLColor4::setVec(const LLColor4 &vec)
 }
 
 
+// deprecated
 inline const LLColor4&	LLColor4::setVec(const F32 *vec)
 {
 	mV[VX] = vec[VX];
@@ -337,16 +394,44 @@ inline const LLColor4&	LLColor4::setAlpha(F32 a)
 
 // LLColor4 Magnitude and Normalization Functions
 
+inline F32		LLColor4::length(void) const
+{
+	return fsqrtf(mV[VX]*mV[VX] + mV[VY]*mV[VY] + mV[VZ]*mV[VZ]);
+}
+
+inline F32		LLColor4::lengthSquared(void) const
+{
+	return mV[VX]*mV[VX] + mV[VY]*mV[VY] + mV[VZ]*mV[VZ];
+}
+
+inline F32		LLColor4::normalize(void)
+{
+	F32 mag = fsqrtf(mV[VX]*mV[VX] + mV[VY]*mV[VY] + mV[VZ]*mV[VZ]);
+	F32 oomag;
+
+	if (mag)
+	{
+		oomag = 1.f/mag;
+		mV[VX] *= oomag;
+		mV[VY] *= oomag;
+		mV[VZ] *= oomag;
+	}
+	return (mag);
+}
+
+// deprecated
 inline F32		LLColor4::magVec(void) const
 {
 	return fsqrtf(mV[VX]*mV[VX] + mV[VY]*mV[VY] + mV[VZ]*mV[VZ]);
 }
 
+// deprecated
 inline F32		LLColor4::magVecSquared(void) const
 {
 	return mV[VX]*mV[VX] + mV[VY]*mV[VY] + mV[VZ]*mV[VZ];
 }
 
+// deprecated
 inline F32		LLColor4::normVec(void)
 {
 	F32 mag = fsqrtf(mV[VX]*mV[VX] + mV[VY]*mV[VY] + mV[VZ]*mV[VZ]);
@@ -497,13 +582,13 @@ inline const LLColor4& operator%=(LLColor4 &a, F32 k)
 inline F32		distVec(const LLColor4 &a, const LLColor4 &b)
 {
 	LLColor4 vec = a - b;
-	return (vec.magVec());
+	return (vec.length());
 }
 
 inline F32		distVec_squared(const LLColor4 &a, const LLColor4 &b)
 {
 	LLColor4 vec = a - b;
-	return (vec.magVecSquared());
+	return (vec.lengthSquared());
 }
 
 inline LLColor4 lerp(const LLColor4 &a, const LLColor4 &b, F32 u)
diff --git a/indra/llmath/v4coloru.cpp b/indra/llmath/v4coloru.cpp
index 26f3804209ed5b1f728b747d9cf6e0ddf8b4a72e..17a198b3926975c5119f6b5ed26e1ec329e0bd4a 100644
--- a/indra/llmath/v4coloru.cpp
+++ b/indra/llmath/v4coloru.cpp
@@ -120,6 +120,6 @@ BOOL LLColor4U::parseColor4U(const std::string& buf, LLColor4U* value)
 		}
 	}
 
-	value->setVec( U8(v[0]), U8(v[1]), U8(v[2]), U8(v[3]) );
+	value->set( U8(v[0]), U8(v[1]), U8(v[2]), U8(v[3]) );
 	return TRUE;
 }
diff --git a/indra/llmath/v4coloru.h b/indra/llmath/v4coloru.h
index 1d3f31e9685748f1a35b4f77b8138baa1afc796f..aa830e00352c634a6a7c638bc8580644ad777e92 100644
--- a/indra/llmath/v4coloru.h
+++ b/indra/llmath/v4coloru.h
@@ -97,15 +97,23 @@ class LLColor4U
 	const LLColor4U&	setToBlack();						// zero LLColor4U to (0, 0, 0, 1)
 	const LLColor4U&	setToWhite();						// zero LLColor4U to (0, 0, 0, 1)
 
-	const LLColor4U&	setVec(U8 r, U8 g, U8 b, U8 a);	// Sets LLColor4U to (r, g, b, a)
-	const LLColor4U&	setVec(U8 r, U8 g, U8 b);	// Sets LLColor4U to (r, g, b) (no change in a)
-	const LLColor4U&	setVec(const LLColor4U &vec);	// Sets LLColor4U to vec
-	const LLColor4U&	setVec(const U8 *vec);			// Sets LLColor4U to vec
+	const LLColor4U&	set(U8 r, U8 g, U8 b, U8 a);// Sets LLColor4U to (r, g, b, a)
+	const LLColor4U&	set(U8 r, U8 g, U8 b);		// Sets LLColor4U to (r, g, b) (no change in a)
+	const LLColor4U&	set(const LLColor4U &vec);	// Sets LLColor4U to vec
+	const LLColor4U&	set(const U8 *vec);			// Sets LLColor4U to vec
+
+	const LLColor4U&	setVec(U8 r, U8 g, U8 b, U8 a);	// deprecated -- use set()
+	const LLColor4U&	setVec(U8 r, U8 g, U8 b);		// deprecated -- use set()
+	const LLColor4U&	setVec(const LLColor4U &vec);	// deprecated -- use set()
+	const LLColor4U&	setVec(const U8 *vec);			// deprecated -- use set()
 
 	const LLColor4U&    setAlpha(U8 a);
 
-	F32			magVec() const;				// Returns magnitude of LLColor4U
-	F32			magVecSquared() const;		// Returns magnitude squared of LLColor4U
+	F32			magVec() const;				// deprecated -- use length()
+	F32			magVecSquared() const;		// deprecated -- use lengthSquared()
+
+	F32			length() const;				// Returns magnitude squared of LLColor4U
+	F32			lengthSquared() const;		// Returns magnitude squared of LLColor4U
 
 	friend std::ostream&	 operator<<(std::ostream& s, const LLColor4U &a);		// Print a
 	friend LLColor4U operator+(const LLColor4U &a, const LLColor4U &b);	// Return vector a + b
@@ -199,7 +207,7 @@ inline const LLColor4U&	LLColor4U::setToWhite(void)
 	return (*this);
 }
 
-inline const LLColor4U&	LLColor4U::setVec(const U8 x, const U8 y, const U8 z)
+inline const LLColor4U&	LLColor4U::set(const U8 x, const U8 y, const U8 z)
 {
 	mV[VX] = x;
 	mV[VY] = y;
@@ -211,7 +219,7 @@ inline const LLColor4U&	LLColor4U::setVec(const U8 x, const U8 y, const U8 z)
 	return (*this);
 }
 
-inline const LLColor4U&	LLColor4U::setVec(const U8 r, const U8 g, const U8 b, U8 a)
+inline const LLColor4U&	LLColor4U::set(const U8 r, const U8 g, const U8 b, U8 a)
 {
 	mV[0] = r;
 	mV[1] = g;
@@ -220,7 +228,7 @@ inline const LLColor4U&	LLColor4U::setVec(const U8 r, const U8 g, const U8 b, U8
 	return (*this);
 }
 
-inline const LLColor4U&	LLColor4U::setVec(const LLColor4U &vec)
+inline const LLColor4U&	LLColor4U::set(const LLColor4U &vec)
 {
 	mV[VX] = vec.mV[VX];
 	mV[VY] = vec.mV[VY];
@@ -229,17 +237,49 @@ inline const LLColor4U&	LLColor4U::setVec(const LLColor4U &vec)
 	return (*this);
 }
 
-/*
-inline const LLColor4U&	LLColor4U::setVec(const LLColor4 &vec)
+inline const LLColor4U&	LLColor4U::set(const U8 *vec)
 {
-	mV[VX] = (U8) (llmin(1.f, vec.mV[VX]) * 255.f);
-	mV[VY] = (U8) (llmin(1.f, vec.mV[VY]) * 255.f);
-	mV[VZ] = (U8) (llmin(1.f, vec.mV[VZ]) * 255.f);
-	mV[VW] = (U8) (llmin(1.f, vec.mV[VW]) * 255.f);
+	mV[VX] = vec[VX];
+	mV[VY] = vec[VY];
+	mV[VZ] = vec[VZ];
+	mV[VW] = vec[VW];
 	return (*this);
 }
-*/
 
+// deprecated
+inline const LLColor4U&	LLColor4U::setVec(const U8 x, const U8 y, const U8 z)
+{
+	mV[VX] = x;
+	mV[VY] = y;
+	mV[VZ] = z;
+
+//  no change to alpha!
+//	mV[VW] = 255;  
+
+	return (*this);
+}
+
+// deprecated
+inline const LLColor4U&	LLColor4U::setVec(const U8 r, const U8 g, const U8 b, U8 a)
+{
+	mV[0] = r;
+	mV[1] = g;
+	mV[2] = b;
+	mV[3] = a;  
+	return (*this);
+}
+
+// deprecated
+inline const LLColor4U&	LLColor4U::setVec(const LLColor4U &vec)
+{
+	mV[VX] = vec.mV[VX];
+	mV[VY] = vec.mV[VY];
+	mV[VZ] = vec.mV[VZ];
+	mV[VW] = vec.mV[VW];
+	return (*this);
+}
+
+// deprecated
 inline const LLColor4U&	LLColor4U::setVec(const U8 *vec)
 {
 	mV[VX] = vec[VX];
@@ -256,13 +296,24 @@ inline const LLColor4U&	LLColor4U::setAlpha(U8 a)
 }
 
 // LLColor4U Magnitude and Normalization Functions
-// bookmark
 
+inline F32		LLColor4U::length(void) const
+{
+	return fsqrtf( ((F32)mV[VX]) * mV[VX] + ((F32)mV[VY]) * mV[VY] + ((F32)mV[VZ]) * mV[VZ] );
+}
+
+inline F32		LLColor4U::lengthSquared(void) const
+{
+	return ((F32)mV[VX]) * mV[VX] + ((F32)mV[VY]) * mV[VY] + ((F32)mV[VZ]) * mV[VZ];
+}
+
+// deprecated
 inline F32		LLColor4U::magVec(void) const
 {
 	return fsqrtf( ((F32)mV[VX]) * mV[VX] + ((F32)mV[VY]) * mV[VY] + ((F32)mV[VZ]) * mV[VZ] );
 }
 
+// deprecated
 inline F32		LLColor4U::magVecSquared(void) const
 {
 	return ((F32)mV[VX]) * mV[VX] + ((F32)mV[VY]) * mV[VY] + ((F32)mV[VZ]) * mV[VZ];
@@ -407,13 +458,13 @@ inline const LLColor4U& operator%=(LLColor4U &a, U8 k)
 inline F32		distVec(const LLColor4U &a, const LLColor4U &b)
 {
 	LLColor4U vec = a - b;
-	return (vec.magVec());
+	return (vec.length());
 }
 
 inline F32		distVec_squared(const LLColor4U &a, const LLColor4U &b)
 {
 	LLColor4U vec = a - b;
-	return (vec.magVecSquared());
+	return (vec.lengthSquared());
 }
 
 void LLColor4U::setVecScaleClamp(const LLColor4& color)
diff --git a/indra/llmessage/llcurl.cpp b/indra/llmessage/llcurl.cpp
index c3ffbcc8ed5e405ff0e109de60bc6f74768542c7..8c7392090cb87b15467aa5573b9cb77a3ac8a274 100644
--- a/indra/llmessage/llcurl.cpp
+++ b/indra/llmessage/llcurl.cpp
@@ -265,6 +265,10 @@ LLCurl::Easy* LLCurl::Easy::getEasy()
 		delete easy;
 		return NULL;
 	}
+	
+	// set no DMS caching as default for all easy handles. This prevents them adopting a
+	// multi handles cache if they are added to one.
+	curl_easy_setopt(easy->mCurlEasyHandle, CURLOPT_DNS_CACHE_TIMEOUT, 0);
 	++gCurlEasyCount;
 	return easy;
 }
diff --git a/indra/llmessage/llhttpassetstorage.cpp b/indra/llmessage/llhttpassetstorage.cpp
index 6332c247a9136aaa2b1bfb237da8fe5d79d47490..bf76c17873871c8b64c55cc9a9f33e5cec0f429e 100644
--- a/indra/llmessage/llhttpassetstorage.cpp
+++ b/indra/llmessage/llhttpassetstorage.cpp
@@ -256,6 +256,10 @@ void LLHTTPAssetRequest::setupCurlHandle()
 			// disable use of proxy, which can't handle chunked transfers
 	}
 	mHTTPHeaders = curl_slist_append(mHTTPHeaders, "Pragma:");
+
+	// bug in curl causes DNS to be cached for too long a time, 0 sets it to never cache DNS results internally (to curl)
+	curl_easy_setopt(mCurlHandle, CURLOPT_DNS_CACHE_TIMEOUT, 0);
+	
 	// resist the temptation to explicitly add the Transfer-Encoding: chunked
 	// header here - invokes a libCURL bug
 	curl_easy_setopt(mCurlHandle, CURLOPT_HTTPHEADER, mHTTPHeaders);
diff --git a/indra/llmessage/llnamevalue.cpp b/indra/llmessage/llnamevalue.cpp
index 13dca3e51fc56d35ed08af564b0edfbc6fb88f1c..58755871865add208f3b26e441081c3f1de414a0 100644
--- a/indra/llmessage/llnamevalue.cpp
+++ b/indra/llmessage/llnamevalue.cpp
@@ -896,7 +896,7 @@ void LLNameValue::setVec3(const LLVector3 &a)
 }
 
 
-std::string LLNameValue::printNameValue()
+std::string LLNameValue::printNameValue() const
 {
 	std::string buffer;
 	buffer = llformat("%s %s %s %s ", mName, mStringType, mStringClass, mStringSendto);
@@ -905,7 +905,7 @@ std::string LLNameValue::printNameValue()
 	return buffer;
 }
 
-std::string LLNameValue::printData()
+std::string LLNameValue::printData() const
 {
 	std::string buffer;
 	switch(mType)
diff --git a/indra/llmessage/llnamevalue.h b/indra/llmessage/llnamevalue.h
index f50ed08207ad8a8e1e4f8c1372592c40e0a7b44b..f492015b4a1288f523f1a843d2840b3f8a3c7e3b 100644
--- a/indra/llmessage/llnamevalue.h
+++ b/indra/llmessage/llnamevalue.h
@@ -148,8 +148,8 @@ class LLNameValue
 	BOOL			sendToViewer() const;
 
 	void			callCallback();
-	std::string		printNameValue();
-	std::string		printData();
+	std::string		printNameValue() const;
+	std::string		printData() const;
 	
 	ENameValueType		getTypeEnum() const		{ return mType; }
 	ENameValueClass		getClassEnum() const	{ return mClass; }
diff --git a/indra/llui/lllineeditor.cpp b/indra/llui/lllineeditor.cpp
index bacfe67ad83a5c9d63e279bcde15413038f45ce3..a41b2af2b43c565926c1a67874084a0f180b850c 100644
--- a/indra/llui/lllineeditor.cpp
+++ b/indra/llui/lllineeditor.cpp
@@ -2282,7 +2282,7 @@ LLView* LLLineEditor::fromXML(LLXMLNodePtr node, LLView *parent, LLUICtrlFactory
 }
 
 //static
-void LLLineEditor::cleanupClass()
+void LLLineEditor::cleanupLineEditor()
 {
 	sImage = NULL;
 }
diff --git a/indra/llui/lllineeditor.h b/indra/llui/lllineeditor.h
index c2dbedd3f5b94b70d406b8fe141cd6af827d95a6..98242a493ded6f5fb1044d05ac8d17c9e507a2b2 100644
--- a/indra/llui/lllineeditor.h
+++ b/indra/llui/lllineeditor.h
@@ -82,7 +82,7 @@ class LLLineEditor
 	virtual LLXMLNodePtr getXML(bool save_children = true) const;
 	void setColorParameters(LLXMLNodePtr node);
 	static LLView* fromXML(LLXMLNodePtr node, LLView *parent, LLUICtrlFactory *factory);
-	static void cleanupClass();
+	static void cleanupLineEditor();
 
 	// mousehandler overrides
 	/*virtual*/ BOOL	handleMouseDown(S32 x, S32 y, MASK mask);
diff --git a/indra/llui/llui.cpp b/indra/llui/llui.cpp
index 2b6895aa099646d2924bf617fde593f43efba3d5..f34c48b7297ac4db037dcc80a456876f8d839db6 100644
--- a/indra/llui/llui.cpp
+++ b/indra/llui/llui.cpp
@@ -1575,7 +1575,7 @@ void LLUI::initClass(LLControlGroup* config,
 void LLUI::cleanupClass()
 {
 	sImageProvider->cleanUp();
-	LLLineEditor::cleanupClass();
+	LLLineEditor::cleanupLineEditor();
 }
 
 
diff --git a/indra/lscript/lscript_byteconvert.h b/indra/lscript/lscript_byteconvert.h
index b5e09602c79dae4a6a06a483ac947f70786273e5..9344a1e90ab6cbcf70ae247244ed239349164be8 100644
--- a/indra/lscript/lscript_byteconvert.h
+++ b/indra/lscript/lscript_byteconvert.h
@@ -250,7 +250,7 @@ inline void bytestream2vector(LLVector3 &vector, const U8 *stream, S32 &offset)
 	}
 }
 
-inline void vector2bytestream(U8 *stream, S32 &offset, LLVector3 &vector)
+inline void vector2bytestream(U8 *stream, S32 &offset, const LLVector3 &vector)
 {
 	S32 value = *(S32 *)&vector.mV[VZ];
 	integer2bytestream(stream, offset, value);
@@ -292,7 +292,7 @@ inline void bytestream2quaternion(LLQuaternion &quat, const U8 *stream, S32 &off
 	}
 }
 
-inline void quaternion2bytestream(U8 *stream, S32 &offset, LLQuaternion &quat)
+inline void quaternion2bytestream(U8 *stream, S32 &offset, const LLQuaternion &quat)
 {
 	S32 value = *(S32 *)&quat.mQ[VS];
 	integer2bytestream(stream, offset, value);
@@ -528,7 +528,7 @@ inline void lscript_push(U8 *stream, F32 value)
 	}
 }
 
-inline void lscript_push(U8 *stream, LLVector3 &value)
+inline void lscript_push(U8 *stream, const LLVector3 &value)
 {
 	S32 sp = get_register(stream, LREG_SP);
 	sp -= LSCRIPTDataSize[LST_VECTOR];
@@ -539,7 +539,7 @@ inline void lscript_push(U8 *stream, LLVector3 &value)
 	}
 }
 
-inline void lscript_push(U8 *stream, LLQuaternion &value)
+inline void lscript_push(U8 *stream, const LLQuaternion &value)
 {
 	S32 sp = get_register(stream, LREG_SP);
 	sp -= LSCRIPTDataSize[LST_QUATERNION];
@@ -679,13 +679,13 @@ inline void lscript_local_store(U8 *stream, S32 address, F32 value)
 		float2bytestream(stream, address, value);
 }
 
-inline void lscript_local_store(U8 *stream, S32 address, LLVector3 value)
+inline void lscript_local_store(U8 *stream, S32 address, const LLVector3 value)
 {
 	if (lscript_check_local(stream, address, LSCRIPTDataSize[LST_VECTOR]))
 		vector2bytestream(stream, address, value);
 }
 
-inline void lscript_local_store(U8 *stream, S32 address, LLQuaternion value)
+inline void lscript_local_store(U8 *stream, S32 address, const LLQuaternion value)
 {
 	if (lscript_check_local(stream, address, LSCRIPTDataSize[LST_QUATERNION]))
 		quaternion2bytestream(stream, address, value);
@@ -703,13 +703,13 @@ inline void lscript_global_store(U8 *stream, S32 address, F32 value)
 		float2bytestream(stream, address, value);
 }
 
-inline void lscript_global_store(U8 *stream, S32 address, LLVector3 value)
+inline void lscript_global_store(U8 *stream, S32 address, const LLVector3 value)
 {
 	if (lscript_check_global(stream, address, LSCRIPTDataSize[LST_VECTOR]))
 		vector2bytestream(stream, address, value);
 }
 
-inline void lscript_global_store(U8 *stream, S32 address, LLQuaternion value)
+inline void lscript_global_store(U8 *stream, S32 address, const LLQuaternion value)
 {
 	if (lscript_check_global(stream, address, LSCRIPTDataSize[LST_QUATERNION]))
 		quaternion2bytestream(stream, address, value);
@@ -1125,7 +1125,7 @@ inline void safe_instruction_bytestream2vector(LLVector3 &value, U8 *stream, S32
 	}
 }
 
-inline void safe_instruction_vector2bytestream(U8 *stream, S32 &offset, LLVector3 &value)
+inline void safe_instruction_vector2bytestream(U8 *stream, S32 &offset, const LLVector3 &value)
 {
 	if (safe_instruction_check_address(stream, offset, LSCRIPTDataSize[LST_VECTOR]))
 	{
@@ -1141,7 +1141,7 @@ inline void safe_instruction_bytestream2quaternion(LLQuaternion &value, U8 *stre
 	}
 }
 
-inline void safe_instruction_quaternion2bytestream(U8 *stream, S32 &offset, LLQuaternion &value)
+inline void safe_instruction_quaternion2bytestream(U8 *stream, S32 &offset, const LLQuaternion &value)
 {
 	if (safe_instruction_check_address(stream, offset, LSCRIPTDataSize[LST_QUATERNION]))
 	{
diff --git a/indra/lscript/lscript_byteformat.h b/indra/lscript/lscript_byteformat.h
index 474e8a67a67c38719050fcbc1882c26c660c2507..09033615d4afec36f336e4c68bfa33a70e62f69e 100644
--- a/indra/lscript/lscript_byteformat.h
+++ b/indra/lscript/lscript_byteformat.h
@@ -470,6 +470,7 @@ const U8 LSCRIPTTypeHi4Bits[LST_EOF] =
 	LST_VECTOR << 4,
 	LST_QUATERNION << 4,
 	LST_LIST << 4,
+	LST_UNDEFINED << 4,
 };
 
 const char * const LSCRIPTTypeNames[LST_EOF] = 	/*Flawfinder: ignore*/
diff --git a/indra/newview/CMakeLists.txt b/indra/newview/CMakeLists.txt
index 1e8f37e75f194e1e46c3f69acc00523c7ec3cd05..826538d8e21e9bbb6c4d411be3ed4a8c80de71af 100644
--- a/indra/newview/CMakeLists.txt
+++ b/indra/newview/CMakeLists.txt
@@ -198,6 +198,7 @@ set(viewer_SOURCE_FILES
     llglsandbox.cpp
     llgroupmgr.cpp
     llgroupnotify.cpp
+    llhomelocationresponder.cpp
     llhoverview.cpp
     llhudeffectbeam.cpp
     llhudeffect.cpp
@@ -590,6 +591,7 @@ set(viewer_HEADER_FILES
     llgivemoney.h
     llgroupmgr.h
     llgroupnotify.h
+    llhomelocationresponder.h
     llhoverview.h
     llhudeffect.h
     llhudeffectbeam.h
diff --git a/indra/newview/llagent.cpp b/indra/newview/llagent.cpp
index cb32dfb904734de29f32ecb152757157b1649f19..19a0676374498ef3f47222ab66fd03273b8d49b6 100644
--- a/indra/newview/llagent.cpp
+++ b/indra/newview/llagent.cpp
@@ -80,6 +80,7 @@
 #include "llfloatertools.h"
 #include "llfloaterworldmap.h"
 #include "llgroupmgr.h"
+#include "llhomelocationresponder.h"
 #include "llhudeffectlookat.h"
 #include "llhudmanager.h"
 #include "llinventorymodel.h"
@@ -90,6 +91,7 @@
 #include "llmoveview.h"
 #include "llnotify.h"
 #include "llquantize.h"
+#include "llsdutil.h"
 #include "llselectmgr.h"
 #include "llsky.h"
 #include "llrendersphere.h"
@@ -445,7 +447,7 @@ void LLAgent::init()
 	mCameraFocusOffsetTarget = LLVector4(gSavedSettings.getVector3("CameraOffsetBuild"));
 	mCameraOffsetDefault = gSavedSettings.getVector3("CameraOffsetDefault");
 //	mCameraOffsetNorm = mCameraOffsetDefault;
-//	mCameraOffsetNorm.normVec();
+//	mCameraOffsetNorm.normalize();
 	mCameraCollidePlane.clearVec();
 	mCurrentCameraDistance = mCameraOffsetDefault.magVec();
 	mTargetCameraDistance = mCurrentCameraDistance;
@@ -522,7 +524,7 @@ void LLAgent::resetView(BOOL reset_camera)
 			// leaving mouse-steer mode
 			LLVector3 agent_at_axis = getAtAxis();
 			agent_at_axis -= projected_vec(agent_at_axis, getReferenceUpVector());
-			agent_at_axis.normVec();
+			agent_at_axis.normalize();
 			gAgent.resetAxes(lerp(getAtAxis(), agent_at_axis, LLCriticalDamp::getInterpolant(0.3f)));
 		}
 
@@ -1033,7 +1035,7 @@ void LLAgent::slamLookAt(const LLVector3 &look_at)
 {
 	LLVector3 look_at_norm = look_at;
 	look_at_norm.mV[VZ] = 0.f;
-	look_at_norm.normVec();
+	look_at_norm.normalize();
 	resetAxes(look_at_norm);
 }
 
@@ -1305,7 +1307,7 @@ LLVector3 LLAgent::calcFocusOffset(LLViewerObject *object, S32 x, S32 y)
 
 	LLVector3 obj_dir_abs = obj_pos - LLViewerCamera::getInstance()->getOrigin();
 	obj_dir_abs.rotVec(inv_obj_rot);
-	obj_dir_abs.normVec();
+	obj_dir_abs.normalize();
 	obj_dir_abs.abs();
 
 	LLVector3 object_extents = object->getScale();
@@ -1330,7 +1332,7 @@ LLVector3 LLAgent::calcFocusOffset(LLViewerObject *object, S32 x, S32 y)
 	{
 		normal.setVec(obj_matrix.getUpRow4());
 	}
-	normal.normVec();
+	normal.normalize();
 
 	LLVector3d focus_pt_global;
 	// RN: should we check return value for valid pick?
@@ -1534,7 +1536,7 @@ BOOL LLAgent::calcCameraMinDistance(F32 &obj_min_distance)
 	camera_offset_target_abs_norm.abs();
 	// make sure offset is non-zero
 	camera_offset_target_abs_norm.clamp(0.001f, F32_MAX);
-	camera_offset_target_abs_norm.normVec();
+	camera_offset_target_abs_norm.normalize();
 
 	// find camera position relative to normalized object extents
 	LLVector3 camera_offset_target_scaled = camera_offset_target_abs_norm;
@@ -1580,7 +1582,7 @@ BOOL LLAgent::calcCameraMinDistance(F32 &obj_min_distance)
 	LLVector3 object_split_axis;
 	LLVector3 target_offset_scaled = target_offset_origin;
 	target_offset_scaled.abs();
-	target_offset_scaled.normVec();
+	target_offset_scaled.normalize();
 	target_offset_scaled.mV[VX] /= object_extents.mV[VX];
 	target_offset_scaled.mV[VY] /= object_extents.mV[VY];
 	target_offset_scaled.mV[VZ] /= object_extents.mV[VZ];
@@ -1703,7 +1705,7 @@ void LLAgent::setCameraZoomFraction(F32 fraction)
 	else if (cameraCustomizeAvatar())
 	{
 		LLVector3d camera_offset_dir = mCameraFocusOffsetTarget;
-		camera_offset_dir.normVec();
+		camera_offset_dir.normalize();
 		mCameraFocusOffsetTarget = camera_offset_dir * rescale(fraction, 0.f, 1.f, APPEARANCE_MAX_ZOOM, APPEARANCE_MIN_ZOOM);
 	}
 	else
@@ -1730,7 +1732,7 @@ void LLAgent::setCameraZoomFraction(F32 fraction)
 		}
 
 		LLVector3d camera_offset_dir = mCameraFocusOffsetTarget;
-		camera_offset_dir.normVec();
+		camera_offset_dir.normalize();
 		mCameraFocusOffsetTarget = camera_offset_dir * rescale(fraction, 0.f, 1.f, max_zoom, min_zoom);
 	}
 	startCameraAnimation();
@@ -1777,7 +1779,7 @@ void LLAgent::cameraOrbitOver(const F32 angle)
 	else
 	{
 		LLVector3 camera_offset_unit(mCameraFocusOffsetTarget);
-		camera_offset_unit.normVec();
+		camera_offset_unit.normalize();
 
 		F32 angle_from_up = acos( camera_offset_unit * getReferenceUpVector() );
 
@@ -1812,7 +1814,7 @@ void LLAgent::cameraZoomIn(const F32 fraction)
 	LLVector3d	camera_offset(mCameraFocusOffsetTarget);
 	LLVector3d	camera_offset_unit(mCameraFocusOffsetTarget);
 	F32 min_zoom = LAND_MIN_ZOOM;
-	F32 current_distance = (F32)camera_offset_unit.normVec();
+	F32 current_distance = (F32)camera_offset_unit.normalize();
 	F32 new_distance = current_distance * fraction;
 
 	// Don't move through focus point
@@ -1881,7 +1883,7 @@ void LLAgent::cameraOrbitIn(const F32 meters)
 	{
 		LLVector3d	camera_offset(mCameraFocusOffsetTarget);
 		LLVector3d	camera_offset_unit(mCameraFocusOffsetTarget);
-		F32 current_distance = (F32)camera_offset_unit.normVec();
+		F32 current_distance = (F32)camera_offset_unit.normalize();
 		F32 new_distance = current_distance - meters;
 		F32 min_zoom = LAND_MIN_ZOOM;
 		
@@ -2246,7 +2248,7 @@ void LLAgent::startAutoPilotGlobal(const LLVector3d &target_global, const std::s
 		mAutoPilotUseRotation = TRUE;
 		mAutoPilotTargetFacing = LLVector3::x_axis * *target_rotation;
 		mAutoPilotTargetFacing.mV[VZ] = 0.f;
-		mAutoPilotTargetFacing.normVec();
+		mAutoPilotTargetFacing.normalize();
 	}
 	else
 	{
@@ -2369,8 +2371,8 @@ void LLAgent::autoPilot(F32 *delta_yaw)
 		at.mV[VZ] = 0.f;
 		direction.mV[VZ] = 0.f;
 
-		at.normVec();
-		F32 xy_distance = direction.normVec();
+		at.normalize();
+		F32 xy_distance = direction.normalize();
 
 		F32 yaw = 0.f;
 		if (mAutoPilotTargetDist > mAutoPilotStopDistance)
@@ -3529,7 +3531,7 @@ void LLAgent::setupSitCamera()
 		// slam agent coordinate frame to proper parent local version
 		LLVector3 at_axis = mFrameAgent.getAtAxis();
 		at_axis.mV[VZ] = 0.f;
-		at_axis.normVec();
+		at_axis.normalize();
 		resetAxes(at_axis * ~parent_rot);
 	}
 }
@@ -3665,7 +3667,7 @@ LLVector3d LLAgent::calcCameraPositionTargetGlobal(BOOL *hit_limit)
 				// slam agent coordinate frame to proper parent local version
 				LLVector3 at_axis = mFrameAgent.getAtAxis() * parent_rot;
 				at_axis.mV[VZ] = 0.f;
-				at_axis.normVec();
+				at_axis.normalize();
 				resetAxes(at_axis * ~parent_rot);
 
 				local_camera_offset = local_camera_offset * mFrameAgent.getQuaternion() * parent_rot;
@@ -3686,7 +3688,7 @@ LLVector3d LLAgent::calcCameraPositionTargetGlobal(BOOL *hit_limit)
 					offset_dot_norm = 0.001f;
 				}
 				
-				camera_distance = local_camera_offset.normVec();
+				camera_distance = local_camera_offset.normalize();
 
 				F32 pos_dot_norm = getPosAgentFromGlobal(frame_center_global + head_offset) * plane_normal;
 				
@@ -3710,7 +3712,7 @@ LLVector3d LLAgent::calcCameraPositionTargetGlobal(BOOL *hit_limit)
 			}
 			else
 			{
-				camera_distance = local_camera_offset.normVec();
+				camera_distance = local_camera_offset.normalize();
 			}
 
 			mTargetCameraDistance = llmax(camera_distance, MIN_CAMERA_DISTANCE);
@@ -3745,7 +3747,7 @@ LLVector3d LLAgent::calcCameraPositionTargetGlobal(BOOL *hit_limit)
 				{
 					LLVector3 frame_at_axis = mFrameAgent.getAtAxis();
 					frame_at_axis -= projected_vec(frame_at_axis, getReferenceUpVector());
-					frame_at_axis.normVec();
+					frame_at_axis.normalize();
 
 					//transition smoothly in air mode, to avoid camera pop
 					F32 u = (time_in_air - GROUND_TO_AIR_CAMERA_TRANSITION_START_TIME) / GROUND_TO_AIR_CAMERA_TRANSITION_TIME;
@@ -3932,7 +3934,7 @@ void LLAgent::resetCamera()
 	// Remove any pitch from the avatar
 	LLVector3 at = mFrameAgent.getAtAxis();
 	at.mV[VZ] = 0.f;
-	at.normVec();
+	at.normalize();
 	gAgent.resetAxes(at);
 	// have to explicitly clear field of view zoom now
 	mCameraFOVZoomFactor = 0.f;
@@ -4147,14 +4149,14 @@ void LLAgent::changeCameraToThirdPerson(BOOL animate)
 		LLQuaternion obj_rot = ((LLViewerObject*)mAvatarObject->getParent())->getRenderRotation();
 		at_axis = LLViewerCamera::getInstance()->getAtAxis();
 		at_axis.mV[VZ] = 0.f;
-		at_axis.normVec();
+		at_axis.normalize();
 		resetAxes(at_axis * ~obj_rot);
 	}
 	else
 	{
 		at_axis = mFrameAgent.getAtAxis();
 		at_axis.mV[VZ] = 0.f;
-		at_axis.normVec();
+		at_axis.normalize();
 		resetAxes(at_axis);
 	}
 
@@ -4201,7 +4203,7 @@ void LLAgent::changeCameraToCustomizeAvatar(BOOL avatar_animate, BOOL camera_ani
 	// Remove any pitch from the avatar
 	//LLVector3 at = mFrameAgent.getAtAxis();
 	//at.mV[VZ] = 0.f;
-	//at.normVec();
+	//at.normalize();
 	//gAgent.resetAxes(at);
 
 	if( mCameraMode != CAMERA_MODE_CUSTOMIZE_AVATAR )
@@ -4228,7 +4230,7 @@ void LLAgent::changeCameraToCustomizeAvatar(BOOL avatar_animate, BOOL camera_ani
 				// Remove any pitch from the avatar
 			LLVector3 at = mFrameAgent.getAtAxis();
 			at.mV[VZ] = 0.f;
-			at.normVec();
+			at.normalize();
 			gAgent.resetAxes(at);
 
 			sendAnimationRequest(ANIM_AGENT_CUSTOMIZE, ANIM_REQUEST_START);
@@ -4508,14 +4510,14 @@ void LLAgent::setFocusOnAvatar(BOOL focus_on_avatar, BOOL animate)
 				LLQuaternion obj_rot = ((LLViewerObject*)mAvatarObject->getParent())->getRenderRotation();
 				at_axis = LLViewerCamera::getInstance()->getAtAxis();
 				at_axis.mV[VZ] = 0.f;
-				at_axis.normVec();
+				at_axis.normalize();
 				resetAxes(at_axis * ~obj_rot);
 			}
 			else
 			{
 				at_axis = LLViewerCamera::getInstance()->getAtAxis();
 				at_axis.mV[VZ] = 0.f;
-				at_axis.normVec();
+				at_axis.normalize();
 				resetAxes(at_axis);
 			}
 		}
@@ -4578,7 +4580,7 @@ void LLAgent::lookAtLastChat()
 			{
 				delta_pos = chatter->getPositionAgent() - getPositionAgent();
 			}
-			delta_pos.normVec();
+			delta_pos.normalize();
 
 			setControlFlags(AGENT_CONTROL_STOP);
 
@@ -4586,9 +4588,9 @@ void LLAgent::lookAtLastChat()
 
 			LLVector3 new_camera_pos = mAvatarObject->mHeadp->getWorldPosition();
 			LLVector3 left = delta_pos % LLVector3::z_axis;
-			left.normVec();
+			left.normalize();
 			LLVector3 up = left % delta_pos;
-			up.normVec();
+			up.normalize();
 			new_camera_pos -= delta_pos * 0.4f;
 			new_camera_pos += left * 0.3f;
 			new_camera_pos += up * 0.2f;
@@ -4607,7 +4609,7 @@ void LLAgent::lookAtLastChat()
 		else
 		{
 			delta_pos = chatter->getRenderPosition() - getPositionAgent();
-			delta_pos.normVec();
+			delta_pos.normalize();
 
 			setControlFlags(AGENT_CONTROL_STOP);
 
@@ -4615,9 +4617,9 @@ void LLAgent::lookAtLastChat()
 
 			LLVector3 new_camera_pos = mAvatarObject->mHeadp->getWorldPosition();
 			LLVector3 left = delta_pos % LLVector3::z_axis;
-			left.normVec();
+			left.normalize();
 			LLVector3 up = left % delta_pos;
-			up.normVec();
+			up.normalize();
 			new_camera_pos -= delta_pos * 0.4f;
 			new_camera_pos += left * 0.3f;
 			new_camera_pos += up * 0.2f;
@@ -4631,68 +4633,107 @@ void LLAgent::lookAtLastChat()
 
 const F32 SIT_POINT_EXTENTS = 0.2f;
 
-// Grabs current position
-void LLAgent::setStartPosition(U32 location_id)
-{
-	LLViewerObject		*object;
-
-	if ( !(gAgentID == LLUUID::null) )
-	{
-		// we've got an ID for an agent viewerobject
-		object = gObjectList.findObject(gAgentID);
-		if (object)
-		{
-			// we've got the viewer object
-			// Sometimes the agent can be velocity interpolated off of
-			// this simulator.  Clamp it to the region the agent is
-			// in, a little bit in on each side.
-			const F32 INSET = 0.5f;	//meters
-			const F32 REGION_WIDTH = LLWorld::getInstance()->getRegionWidthInMeters();
-
-			LLVector3 agent_pos = getPositionAgent();
-
-			if (mAvatarObject)
-			{
-				// the z height is at the agent's feet
-				agent_pos.mV[VZ] -= 0.5f * mAvatarObject->mBodySize.mV[VZ];
-			}
-
-			agent_pos.mV[VX] = llclamp( agent_pos.mV[VX], INSET, REGION_WIDTH - INSET );
-			agent_pos.mV[VY] = llclamp( agent_pos.mV[VY], INSET, REGION_WIDTH - INSET );
-
-			// Don't let them go below ground, or too high.
-			agent_pos.mV[VZ] = llclamp( agent_pos.mV[VZ], 
-				mRegionp->getLandHeightRegion( agent_pos ), 
-				LLWorld::getInstance()->getRegionMaxHeight() );
-
-			LLMessageSystem* msg = gMessageSystem;
-			msg->newMessageFast(_PREHASH_SetStartLocationRequest);
-			msg->nextBlockFast( _PREHASH_AgentData);
-			msg->addUUIDFast(_PREHASH_AgentID, getID());
-			msg->addUUIDFast(_PREHASH_SessionID, getSessionID());
-			msg->nextBlockFast( _PREHASH_StartLocationData);
-			// corrected by sim
-			msg->addStringFast(_PREHASH_SimName, "");
-			msg->addU32Fast(_PREHASH_LocationID, location_id);
-			msg->addVector3Fast(_PREHASH_LocationPos, agent_pos);
-			msg->addVector3Fast(_PREHASH_LocationLookAt,mFrameAgent.getAtAxis());
-
-			// Reliable only helps when setting home location.  Last
-			// location is sent on quit, and we don't have time to ack
-			// the packets.
-			msg->sendReliable(mRegionp->getHost());
-
-			const U32 HOME_INDEX = 1;
-			if( HOME_INDEX == location_id )
-			{
-				setHomePosRegion( mRegionp->getHandle(), getPositionAgent() );
-			}
-		}
-		else
-		{
-			llinfos << "setStartPosition - Can't find agent viewerobject id " << gAgentID << llendl;
-		}
-	}
+void LLAgent::setStartPosition( U32 location_id )
+{
+  LLViewerObject          *object;
+
+  if ( !(gAgentID == LLUUID::null) )
+  {
+    // we've got an ID for an agent viewerobject
+    object = gObjectList.findObject(gAgentID);
+    if (object)
+    {
+      // we've got the viewer object
+      // Sometimes the agent can be velocity interpolated off of
+      // this simulator.  Clamp it to the region the agent is
+      // in, a little bit in on each side.
+      const F32 INSET = 0.5f; //meters
+      const F32 REGION_WIDTH = LLWorld::getInstance()->getRegionWidthInMeters();
+
+      LLVector3 agent_pos = getPositionAgent();
+      LLVector3 agent_look_at = mFrameAgent.getAtAxis();
+
+      if (mAvatarObject)
+      {
+	// the z height is at the agent's feet
+	agent_pos.mV[VZ] -= 0.5f * mAvatarObject->mBodySize.mV[VZ];
+      }
+
+      agent_pos.mV[VX] = llclamp( agent_pos.mV[VX], INSET, REGION_WIDTH - INSET );
+      agent_pos.mV[VY] = llclamp( agent_pos.mV[VY], INSET, REGION_WIDTH - INSET );
+
+      // Don't let them go below ground, or too high.
+      agent_pos.mV[VZ] = llclamp( agent_pos.mV[VZ],
+				  mRegionp->getLandHeightRegion( agent_pos ),
+				  LLWorld::getInstance()->getRegionMaxHeight() );
+      // Send the CapReq
+
+      LLSD body;
+
+      std::string url = gAgent.getRegion()->getCapability("HomeLocation");
+      std::ostringstream strBuffer;
+      if( url.empty() )
+      {
+	LLMessageSystem* msg = gMessageSystem;
+	msg->newMessageFast(_PREHASH_SetStartLocationRequest);
+	msg->nextBlockFast( _PREHASH_AgentData);
+	msg->addUUIDFast(_PREHASH_AgentID, getID());
+	msg->addUUIDFast(_PREHASH_SessionID, getSessionID());
+	msg->nextBlockFast( _PREHASH_StartLocationData);
+	// corrected by sim
+	msg->addStringFast(_PREHASH_SimName, "");
+	msg->addU32Fast(_PREHASH_LocationID, location_id);
+	msg->addVector3Fast(_PREHASH_LocationPos, agent_pos);
+	msg->addVector3Fast(_PREHASH_LocationLookAt,mFrameAgent.getAtAxis());
+	
+	// Reliable only helps when setting home location.  Last
+	// location is sent on quit, and we don't have time to ack
+	// the packets.
+	msg->sendReliable(mRegionp->getHost());
+
+	const U32 HOME_INDEX = 1;
+	if( HOME_INDEX == location_id )
+	  {
+	    setHomePosRegion( mRegionp->getHandle(), getPositionAgent() );
+	  }
+      }
+      else
+      {
+	strBuffer << location_id;
+	body["HomeLocation"]["LocationId"] = strBuffer.str();
+
+	strBuffer.str("");
+	strBuffer << agent_pos.mV[VX];
+	body["HomeLocation"]["LocationPos"]["X"] = strBuffer.str();
+
+	strBuffer.str("");
+	strBuffer << agent_pos.mV[VY];
+	body["HomeLocation"]["LocationPos"]["Y"] = strBuffer.str();
+
+	strBuffer.str("");
+	strBuffer << agent_pos.mV[VZ];
+	body["HomeLocation"]["LocationPos"]["Z"] = strBuffer.str();
+
+	strBuffer.str("");
+	strBuffer << agent_look_at.mV[VX];
+	body["HomeLocation"]["LocationLookAt"]["X"] = strBuffer.str();
+
+	strBuffer.str("");
+	strBuffer << agent_look_at.mV[VY];
+	body["HomeLocation"]["LocationLookAt"]["Y"] = strBuffer.str();
+
+	strBuffer.str("");
+	strBuffer << agent_look_at.mV[VZ];
+	body["HomeLocation"]["LocationLookAt"]["Z"] = strBuffer.str();
+
+	LLHTTPClient::post( url, body, new LLHomeLocationResponder() );
+      }
+    }
+    else
+    {
+      llinfos << "setStartPosition - Can't find agent viewerobject id " << gAgentID << llendl;
+    }
+  }
 }
 
 void LLAgent::requestStopMotion( LLMotion* motion )
diff --git a/indra/newview/llappviewer.cpp b/indra/newview/llappviewer.cpp
index 045e7ccf166f96fa94400622ac61e7c186867685..4c8ea54d8d9fab6705180e792e6b020dc4ce3149 100644
--- a/indra/newview/llappviewer.cpp
+++ b/indra/newview/llappviewer.cpp
@@ -1366,8 +1366,7 @@ bool LLAppViewer::cleanup()
 	gImageList.shutdown(); // shutdown again in case a callback added something
 	
 	// This should eventually be done in LLAppViewer
-	LLImageJ2C::closeDSO();
-	LLImageFormatted::cleanupClass();
+	LLImage::cleanupClass();
 	LLVFSThread::cleanupClass();
 	LLLFSThread::cleanupClass();
 
@@ -1435,8 +1434,7 @@ bool LLAppViewer::initThreads()
 	LLAppViewer::sImageDecodeThread = new LLWorkerThread("ImageDecode", enable_threads && true);
 	LLAppViewer::sTextureCache = new LLTextureCache(enable_threads && true);
 	LLAppViewer::sTextureFetch = new LLTextureFetch(LLAppViewer::getTextureCache(), enable_threads && false);
-	LLImageWorker::initClass(LLAppViewer::getImageDecodeThread());
-	LLImageJ2C::openDSO();
+	LLImage::initClass(LLAppViewer::getImageDecodeThread());
 
 	// *FIX: no error handling here!
 	return true;
diff --git a/indra/newview/llhomelocationresponder.cpp b/indra/newview/llhomelocationresponder.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..9eccc18ccdcbd6727d42d0b22487991ee10c0712
--- /dev/null
+++ b/indra/newview/llhomelocationresponder.cpp
@@ -0,0 +1,108 @@
+/** 
+ * @file llhomelocationresponder.cpp
+ * @author Meadhbh Hamrick
+ * @brief Processes responses to the HomeLocation CapReq
+ *
+ * $LicenseInfo:firstyear=2008&license=viewergpl$
+ * 
+ * Copyright (c) 2008, Linden Research, Inc.
+ * 
+ * Second Life Viewer Source Code
+ * The source code in this file ("Source Code") is provided by Linden Lab
+ * to you under the terms of the GNU General Public License, version 2.0
+ * ("GPL"), unless you have obtained a separate licensing agreement
+ * ("Other License"), formally executed by you and Linden Lab.  Terms of
+ * the GPL can be found in doc/GPL-license.txt in this distribution, or
+ * online at http://secondlife.com/developers/opensource/gplv2
+ * 
+ * There are special exceptions to the terms and conditions of the GPL as
+ * it is applied to this Source Code. View the full text of the exception
+ * in the file doc/FLOSS-exception.txt in this software distribution, or
+ * online at http://secondlife.com/developers/opensource/flossexception
+ * 
+ * By copying, modifying or distributing this software, you acknowledge
+ * that you have read and understood your obligations described above,
+ * and agree to abide by those obligations.
+ * 
+ * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
+ * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
+ * COMPLETENESS OR PERFORMANCE.
+ * $/LicenseInfo$
+ */
+
+/* File Inclusions */
+#include "llviewerprecompiledheaders.h"
+
+#include "llhomelocationresponder.h"
+#include "llsdutil.h"
+#include "llagent.h"
+#include "llviewerregion.h"
+
+void LLHomeLocationResponder::result( const LLSD& content )
+{
+  LLVector3 agent_pos;
+  bool      error = true;
+		
+  do {
+	
+    // was the call to /agent/<agent-id>/home-location successful?
+    // If not, we keep error set to true
+    if( ! content.has("success") )
+    {
+      break;
+    }
+		
+    if( 0 != strncmp("true", content["success"].asString().c_str(), 4 ) )
+    {
+      break;
+    }
+		
+    // did the simulator return a "justified" home location?
+    // If no, we keep error set to true
+    if( ! content.has( "HomeLocation" ) )
+    {
+      break;
+    }
+		
+    if( ! content["HomeLocation"].has("LocationPos") )
+    {
+      break;
+    }
+		
+    if( ! content["HomeLocation"]["LocationPos"].has("X") )
+    {
+      break;
+    }
+
+    agent_pos.mV[VX] = content["HomeLocation"]["LocationPos"]["X"].asInteger();
+		
+    if( ! content["HomeLocation"]["LocationPos"].has("Y") )
+    {
+      break;
+    }
+
+    agent_pos.mV[VY] = content["HomeLocation"]["LocationPos"]["Y"].asInteger();
+		
+    if( ! content["HomeLocation"]["LocationPos"].has("Z") )
+    {
+      break;
+    }
+
+    agent_pos.mV[VZ] = content["HomeLocation"]["LocationPos"]["Z"].asInteger();
+		
+    error = false;
+  } while( 0 );
+	
+  if( ! error )
+  {
+    llinfos << "setting home position" << llendl;
+		
+    LLViewerRegion *viewer_region = gAgent.getRegion();
+    gAgent.setHomePosRegion( viewer_region->getHandle(), agent_pos );
+  }
+}
+
+void LLHomeLocationResponder::error( const LLSD& content )
+{
+  llinfos << "received error(" << ll_pretty_print_sd( content ) << ")" << llendl;
+}
diff --git a/indra/newview/llhomelocationresponder.h b/indra/newview/llhomelocationresponder.h
new file mode 100644
index 0000000000000000000000000000000000000000..0851cb8fc19040ed957d67a5dc6f3e910ee46990
--- /dev/null
+++ b/indra/newview/llhomelocationresponder.h
@@ -0,0 +1,47 @@
+/** 
+ * @file llhomelocationresponder.h
+ * @author Meadhbh Hamrick
+ * @brief Processes responses to the HomeLocation CapReq
+ *
+ * $LicenseInfo:firstyear=2008&license=viewergpl$
+ * 
+ * Copyright (c) 2008, Linden Research, Inc.
+ * 
+ * Second Life Viewer Source Code
+ * The source code in this file ("Source Code") is provided by Linden Lab
+ * to you under the terms of the GNU General Public License, version 2.0
+ * ("GPL"), unless you have obtained a separate licensing agreement
+ * ("Other License"), formally executed by you and Linden Lab.  Terms of
+ * the GPL can be found in doc/GPL-license.txt in this distribution, or
+ * online at http://secondlife.com/developers/opensource/gplv2
+ * 
+ * There are special exceptions to the terms and conditions of the GPL as
+ * it is applied to this Source Code. View the full text of the exception
+ * in the file doc/FLOSS-exception.txt in this software distribution, or
+ * online at http://secondlife.com/developers/opensource/flossexception
+ * 
+ * By copying, modifying or distributing this software, you acknowledge
+ * that you have read and understood your obligations described above,
+ * and agree to abide by those obligations.
+ * 
+ * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
+ * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
+ * COMPLETENESS OR PERFORMANCE.
+ * $/LicenseInfo$
+ */
+ 
+ /* Macro Definitions */
+#ifndef LL_LLHOMELOCATIONRESPONDER_H
+#define LL_LLHOMELOCATIONRESPONDER_H
+
+/* File Inclusions */
+#include "llhttpclient.h"
+
+/* Typedef, Enum, Class, Struct, etc. */
+class LLHomeLocationResponder : public LLHTTPClient::Responder
+{
+	virtual void result( const LLSD& content );
+	virtual void error( const LLSD& content );
+};
+
+#endif
diff --git a/indra/newview/llinventorymodel.cpp b/indra/newview/llinventorymodel.cpp
index 9aa7f54fa998d01160ba41d4dd51f3291c74e47a..b890781ab2b425bb8948e67220e2d9aa64e9c082 100644
--- a/indra/newview/llinventorymodel.cpp
+++ b/indra/newview/llinventorymodel.cpp
@@ -73,7 +73,6 @@ F32  LLInventoryModel::sMinTimeBetweenFetches = 0.3f;
 F32  LLInventoryModel::sMaxTimeBetweenFetches = 10.f;
 BOOL LLInventoryModel::sTimelyFetchPending = FALSE;
 LLFrameTimer LLInventoryModel::sFetchTimer;
-LLInventoryModel::cat_map_t LLInventoryModel::sBulkFetchMap;
 S16 LLInventoryModel::sBulkFetchCount = 0;
 
 // RN: for some reason, using std::queue in the header file confuses the compiler which things it's an xmlrpc_queue
@@ -1021,18 +1020,27 @@ void LLInventoryModel::fetchDescendentsOf(const LLUUID& folder_id)
 }
 
 //Initialize statics.
-LLAlertDialog* LLInventoryModel::fetchDescendentsResponder::sRetryDialog=NULL;
-LLSD LLInventoryModel::fetchDescendentsResponder::sRetrySD;
-
 bool LLInventoryModel::isBulkFetchProcessingComplete()
 {
 	return ( (sFetchQueue.empty() 
-			&& sBulkFetchMap.empty() 
-			&& sBulkFetchCount==0)  ?  TRUE : FALSE ) ;
+			&& sBulkFetchCount<=0)  ?  TRUE : FALSE ) ;
 }
 
+class fetchDescendentsResponder: public LLHTTPClient::Responder
+{
+	public:
+		fetchDescendentsResponder(const LLSD& request_sd) : mRequestSD(request_sd) {};
+		//fetchDescendentsResponder() {};
+		void result(const LLSD& content);
+		void error(U32 status, const std::string& reason);
+	public:
+		typedef std::vector<LLViewerInventoryCategory*> folder_ref_t;
+	protected:
+		LLSD mRequestSD;
+};
+
 //If we get back a normal response, handle it here
-void  LLInventoryModel::fetchDescendentsResponder::result(const LLSD& content)
+void  fetchDescendentsResponder::result(const LLSD& content)
 {	
 	if (content.has("folders"))	
 	{
@@ -1049,13 +1057,20 @@ void  LLInventoryModel::fetchDescendentsResponder::result(const LLSD& content)
 			{
 				llwarns << "Got a UpdateInventoryItem for the wrong agent."
 						<< llendl;
-				break;
+				continue;
 			}
 			LLUUID parent_id = folder_sd["folder-id"];
 			LLUUID owner_id = folder_sd["owner-id"];
 			S32    version  = (S32)folder_sd["version"].asInteger();
 			S32    descendents = (S32)folder_sd["descendents"].asInteger();
 			LLPointer<LLViewerInventoryCategory> tcategory = new LLViewerInventoryCategory(owner_id);
+
+	                LLViewerInventoryCategory* pcat = gInventory.getCategory(parent_id);
+			if (!pcat)
+			{
+				continue;
+			}
+
 			for(LLSD::array_const_iterator category_it = folder_sd["categories"].beginArray();
 				category_it != folder_sd["categories"].endArray();
 				++category_it)
@@ -1063,7 +1078,7 @@ void  LLInventoryModel::fetchDescendentsResponder::result(const LLSD& content)
 				LLSD category = *category_it;
 				tcategory->fromLLSD(category); 
 							
-				if (sFullFetchStarted)
+				if (LLInventoryModel::sFullFetchStarted)
 				{
 					sFetchQueue.push_back(tcategory->getUUID());
 				}
@@ -1111,21 +1126,21 @@ void  LLInventoryModel::fetchDescendentsResponder::result(const LLSD& content)
 
 	LLInventoryModel::incrBulkFetch(-1);
 	
-	if (isBulkFetchProcessingComplete())
+	if (LLInventoryModel::isBulkFetchProcessingComplete())
 	{
 		llinfos << "Inventory fetch completed" << llendl;
-		if (sFullFetchStarted)
+		if (LLInventoryModel::sFullFetchStarted)
 		{
-			sAllFoldersFetched = TRUE;
+			LLInventoryModel::sAllFoldersFetched = TRUE;
 		}
-		stopBackgroundFetch();
+		LLInventoryModel::stopBackgroundFetch();
 	}
 	
 	gInventory.notifyObservers();
 }
 
 //If we get back an error (not found, etc...), handle it here
-void LLInventoryModel::fetchDescendentsResponder::error(U32 status, const std::string& reason)
+void fetchDescendentsResponder::error(U32 status, const std::string& reason)
 {
 	llinfos << "fetchDescendentsResponder::error "
 		<< status << ": " << reason << llendl;
@@ -1139,63 +1154,24 @@ void LLInventoryModel::fetchDescendentsResponder::error(U32 status, const std::s
 			++folder_it)
 		{	
 			LLSD folder_sd = *folder_it;
-			sRetrySD["folders"].append(folder_sd);
-		}
-		sMinTimeBetweenFetches = 10.0f; //Add 10 seconds for every time out in this sequence.
-		
-		if (!sRetryDialog)			//The dialog isn't up.  Prompt the resident.
-		{
-			sRetryDialog = gViewerWindow->alertXml("RetryFetchInventoryDescendents", onClickRetry, this);
+			LLUUID folder_id = folder_sd["folder-id"];
+			sFetchQueue.push_front(folder_id);
 		}
 	}
 	else
 	{
-		if (isBulkFetchProcessingComplete())
+		if (LLInventoryModel::isBulkFetchProcessingComplete())
 		{
-			if (sFullFetchStarted)
+			if (LLInventoryModel::sFullFetchStarted)
 			{
-				sAllFoldersFetched = TRUE;
+				LLInventoryModel::sAllFoldersFetched = TRUE;
 			}
-			stopBackgroundFetch();
+			LLInventoryModel::stopBackgroundFetch();
 		}
 	}
 	gInventory.notifyObservers();
 }
 
-void LLInventoryModel::fetchDescendentsResponder::onClickRetry(S32 option, void* userdata)
-{
-	if (option == 0)
-	{
-		std::string url;
-
-		LLViewerRegion * agent_region = gAgent.getRegion();
-		if (agent_region)
-		{
-			url = agent_region->getCapability("FetchInventoryDescendents");
-		}
-
-		if (!url.empty()) //Capability found.  Build up LLSD and use it.
-		{
-			LLSD body = sRetrySD;
-			LLInventoryModel::incrBulkFetch(1);
-			LLHTTPClient::post(url, body, new LLInventoryModel::fetchDescendentsResponder(body),300);
-		}
-	}
-	else
-	{
-		if (isBulkFetchProcessingComplete())
-		{
-			if (sFullFetchStarted)
-			{
-				sAllFoldersFetched = TRUE;
-			}
-			stopBackgroundFetch();
-		}
-	}
-	sRetryDialog=NULL;
-	sRetrySD.clear();
-}
-
 //static   Bundle up a bunch of requests to send all at once.
 void LLInventoryModel::bulkFetch(std::string url)
 {
@@ -1206,7 +1182,7 @@ void LLInventoryModel::bulkFetch(std::string url)
 
 	S16 max_concurrent_fetches=8;
 	F32 new_min_time = 0.5f;			//HACK!  Clean this up when old code goes away entirely.
-	if (sMinTimeBetweenFetches <= new_min_time) sMinTimeBetweenFetches=new_min_time;  //HACK!  See above.
+	if (sMinTimeBetweenFetches < new_min_time) sMinTimeBetweenFetches=new_min_time;  //HACK!  See above.
 	
 	if(gDisconnected 
 	|| sBulkFetchCount > max_concurrent_fetches
@@ -1215,20 +1191,30 @@ void LLInventoryModel::bulkFetch(std::string url)
 		return; // just bail if we are disconnected.
 	}	
 
-	//HACK.  This is inelegant.  We're shuffling a dequeue to a map to get rid of 
-	//redundant requests.  When we get rid of the old code entirely, we can change
-	//the dequeue to a map.  In the new model, there is no benefit to queue order.
 	U32 folder_count=0;
-	U32 max_batch_size=10;
-	while( !(sFetchQueue.empty() ) )
+	U32 max_batch_size=5;
+
+	U32 sort_order = gSavedSettings.getU32("InventorySortOrder") & 0x1;
+
+	LLSD body;
+
+	while( !(sFetchQueue.empty() ) && (folder_count < max_batch_size) )
 	{
 		LLViewerInventoryCategory* cat = gInventory.getCategory(sFetchQueue.front());
 		
 		if (cat)
 		{
-			if ( !gInventory.isCategoryComplete(cat->getUUID()) )	//grab this folder.
+			if ( LLViewerInventoryCategory::VERSION_UNKNOWN == cat->getVersion())
 			{
-				sBulkFetchMap[(cat->getUUID())] = cat;
+				LLSD folder_sd;
+				folder_sd["folder-id"]		= cat->getUUID();
+				folder_sd["owner-id"]		= cat->getOwnerID();
+				folder_sd["sort-order"]		= (LLSD::Integer)sort_order;
+				folder_sd["fetch-folders"]	= (LLSD::Boolean)sFullFetchStarted;
+				folder_sd["fetch-items"]	= (LLSD::Boolean)TRUE;
+				body["folders"].append(folder_sd);
+
+				folder_count++;
 			}
 			else if (sFullFetchStarted)
 			{	//Already have this folder but append child folders to list.
@@ -1249,54 +1235,14 @@ void LLInventoryModel::bulkFetch(std::string url)
 		sFetchQueue.pop_front();
 	}
 		
-
-	if (!sBulkFetchMap.empty())	//There's stuff to fetch.
-	{
-		U32 sort_order = gSavedSettings.getU32("InventorySortOrder") & 0x1;
-
-		LLSD body;
-		
-		cat_map_t::iterator iter=sBulkFetchMap.begin();
-		while( iter!=sBulkFetchMap.end() && (folder_count < max_batch_size) )
-		{
-			LLViewerInventoryCategory* cat = iter->second;
-			
-			if (cat && !gInventory.isCategoryComplete(cat->getUUID()) ) 	//Category exists
-			{
-				BOOL fetchItems=TRUE;
-				if ( sFullFetchStarted 
-					&& gInventory.isCategoryComplete(cat->getUUID()) )
-				{
-					fetchItems=FALSE;
-				}
-				
-				LLSD folder_sd;
-				folder_sd["folder-id"]		= cat->getUUID();
-				folder_sd["owner-id"]		= cat->getOwnerID();
-				folder_sd["sort-order"]		= (LLSD::Integer)sort_order;
-				folder_sd["fetch-folders"]	= (LLSD::Boolean)sFullFetchStarted;
-				folder_sd["fetch-items"]	= (LLSD::Boolean)fetchItems;
-				body["folders"].append(folder_sd);
-
-				folder_count++;
-			}
-			sBulkFetchMap.erase(iter);
-			iter=sBulkFetchMap.begin();
-		}
-	
-		if (iter == sBulkFetchMap.end()) sBulkFetchMap.clear();
-		
 		if (folder_count > 0)
 		{
 			sBulkFetchCount++;
 			
-			LLHTTPClient::post(url, body, new LLInventoryModel::fetchDescendentsResponder(body));
+		LLHTTPClient::post(url, body, new fetchDescendentsResponder(body));
 			sFetchTimer.reset();
 		}
-		
-	}	
-	
-	if (isBulkFetchProcessingComplete())
+	else if (isBulkFetchProcessingComplete())
 	{
 		if (sFullFetchStarted)
 		{
@@ -1365,14 +1311,7 @@ void LLInventoryModel::backgroundFetch(void*)
 	if (sBackgroundFetchActive)
 	{
 		//If we'll be using the capability, we'll be sending batches and the background thing isn't as important.
-		std::string url;
-
-		LLViewerRegion * agent_region = gAgent.getRegion();
-		if (agent_region)
-		{
-			url = agent_region->getCapability("FetchInventoryDescendents");
-		}
-
+		std::string url = gAgent.getRegion()->getCapability("FetchInventoryDescendents");   
 		if (!url.empty()) 
 		{
 			bulkFetch(url);
diff --git a/indra/newview/llinventorymodel.h b/indra/newview/llinventorymodel.h
index 85eb46404b59e3495c113c4194f41361e6fa4ce9..4889d622dc6396db91922b9ad1114a52c23db784 100644
--- a/indra/newview/llinventorymodel.h
+++ b/indra/newview/llinventorymodel.h
@@ -110,21 +110,7 @@ class LLInventoryModel
 	LLInventoryModel();
 	~LLInventoryModel();
 
-	class fetchDescendentsResponder: public LLHTTPClient::Responder
-	{
-		public:
-			fetchDescendentsResponder(const LLSD& request_sd) : mRequestSD(request_sd) {};
-			void result(const LLSD& content);			
-			void error(U32 status, const std::string& reason);
-			static void onClickRetry(S32 option, void* userdata);
-			static void appendRetryList(LLSD retry_sd);
-		public:
-			typedef std::vector<LLViewerInventoryCategory*> folder_ref_t;
-		protected:
-			LLSD mRequestSD;
-			static LLSD sRetrySD;
-			static LLAlertDialog		*sRetryDialog;
-	};
+
 
 	//
 	// Accessors
@@ -364,7 +350,6 @@ class LLInventoryModel
 	// start and stop background breadth-first fetching of inventory contents
 	// this gets triggered when performing a filter-search
 	static void startBackgroundFetch(const LLUUID& cat_id = LLUUID::null); // start fetch process
-	static void stopBackgroundFetch(); // stop fetch process
 	static BOOL backgroundFetchActive();
 	static bool isEverythingFetched();
 	static void backgroundFetch(void*); // background fetch idle function
@@ -413,7 +398,6 @@ class LLInventoryModel
 	static void processInventoryDescendents(LLMessageSystem* msg, void**);
 	static void processMoveInventoryItem(LLMessageSystem* msg, void**);
 	static void processFetchInventoryReply(LLMessageSystem* msg, void**);
-	static bool isBulkFetchProcessingComplete();
 	
 	bool messageUpdateCore(LLMessageSystem* msg, bool do_accounting);
 
@@ -447,11 +431,8 @@ class LLInventoryModel
 	observer_list_t mObservers;
 
 	// completing the fetch once per session should be sufficient
-	static cat_map_t sBulkFetchMap;
 	static BOOL sBackgroundFetchActive;
 	static BOOL sTimelyFetchPending;
-	static BOOL sAllFoldersFetched; 
-	static BOOL sFullFetchStarted;
 	static S32  sNumFetchRetries;
 	static LLFrameTimer sFetchTimer;
 	static F32 sMinTimeBetweenFetches;
@@ -464,6 +445,11 @@ class LLInventoryModel
 public:
 	// *NOTE: DEBUG functionality
 	void dumpInventory();
+	static bool isBulkFetchProcessingComplete();
+	static void stopBackgroundFetch(); // stop fetch process
+
+	static BOOL sFullFetchStarted;
+	static BOOL sAllFoldersFetched; 
 };
 
 // a special inventory model for the agent
diff --git a/indra/newview/llpanelgrouplandmoney.cpp b/indra/newview/llpanelgrouplandmoney.cpp
index 8483e433946085c5c645912d4155f577929fa809..84ba2dd80734fea31f3a7dee61f86069feb14807 100644
--- a/indra/newview/llpanelgrouplandmoney.cpp
+++ b/indra/newview/llpanelgrouplandmoney.cpp
@@ -705,12 +705,13 @@ BOOL LLPanelGroupLandMoney::postBuild()
 	textp = getChild<LLTextEditor>("group_money_planning_text", true);
 	panelp = getChild<LLPanel>("group_money_planning_tab", true);
 
-	if ( !can_view )
+	if ( 1 ) //!can_view
 	{
 		textp->setText(mImplementationp->mCantViewAccountsText);
 	}
 	else
 	{
+		//Temporally disabled for DEV-11287.
 		mImplementationp->mMoneyPlanningTabEHp = 
 			new LLGroupMoneyPlanningTabEventHandler(textp,
 													tabcp,
diff --git a/indra/newview/llsprite.cpp b/indra/newview/llsprite.cpp
index 1348f85201ed3dee1ec45229fa88d246106a2734..c8a3904d9607000343127c2d005678a2febc8af8 100644
--- a/indra/newview/llsprite.cpp
+++ b/indra/newview/llsprite.cpp
@@ -126,8 +126,8 @@ void LLSprite::updateFace(LLFace &face)
 			LLVector3 camera_vec = mPosition - sCameraPosition;
 			mScaledRight = camera_vec % LLVector3(0.f, 0.f, 1.f);
 			mScaledUp = -(camera_vec % mScaledRight);
-			mScaledUp.normVec();
-			mScaledRight.normVec();
+			mScaledUp.normalize();
+			mScaledRight.normalize();
 			mScaledUp *= mHeightDiv2;
 			mScaledRight *= mWidthDiv2;
 
@@ -156,7 +156,7 @@ void LLSprite::updateFace(LLFace &face)
 		else
 		{
 			x_axis = sNormal % LLVector3(0.f, -1.f, 0.f);
-			x_axis.normVec();
+			x_axis.normalize();
 
 			y_axis = sNormal % x_axis;
 		}
diff --git a/indra/newview/llsprite.h b/indra/newview/llsprite.h
index 322150e85b3b373196b5cf420315ceaa4c457c44..03026fd07144f032ed584c99b6329fdf0ee21eb3 100644
--- a/indra/newview/llsprite.h
+++ b/indra/newview/llsprite.h
@@ -73,7 +73,7 @@ class LLSprite
 	void setColor(const LLColor4 &color);
 	void setColor(const F32 r, const F32 g, const F32 b, const F32 a);
 	void setAlpha(const F32 alpha)					{ mColor.mV[VALPHA] = alpha; }
-	void setNormal(const LLVector3 &normal)		{ sNormal = normal; sNormal.normVec();}
+	void setNormal(const LLVector3 &normal)		{ sNormal = normal; sNormal.normalize();}
 
 	F32 getAlpha();
 
diff --git a/indra/newview/llviewermenu.cpp b/indra/newview/llviewermenu.cpp
index 2f8f5a29c54b13dc55275354f7306fd0e9a9d2fe..26d526c98896fd4250aa9f239a4d5bb6341b4090 100644
--- a/indra/newview/llviewermenu.cpp
+++ b/indra/newview/llviewermenu.cpp
@@ -2346,37 +2346,71 @@ class LLAvatarDebug : public view_listener_t
 	}
 };
 
+struct MenuCallbackData
+{
+	bool ban_enabled;
+	LLUUID avatar_id;
+};
+
 void callback_eject(S32 option, void* data)
 {
-	LLUUID* avatar_id = (LLUUID*) data;
+	MenuCallbackData *callback_data = (MenuCallbackData*)data;
+	if (!callback_data)
+	{
+		return;
+	}
+	if (2 == option)
+	{
+		// Cancle button.
+		return;
+	}
+	LLUUID avatar_id = callback_data->avatar_id;
+	bool ban_enabled = callback_data->ban_enabled;
 
-	if (0 == option || 1 == option)
+	if (0 == option)
 	{
+		// Eject button
 		LLMessageSystem* msg = gMessageSystem;
-		LLViewerObject* avatar = gObjectList.findObject(*avatar_id);
+		LLViewerObject* avatar = gObjectList.findObject(avatar_id);
 
 		if (avatar)
 		{
 			U32 flags = 0x0;
-			if (1 == option)
-			{
-				// eject and add to ban list
-				flags |= 0x1;
-			}
+			msg->newMessage("EjectUser");
+			msg->nextBlock("AgentData");
+			msg->addUUID("AgentID", gAgent.getID() );
+			msg->addUUID("SessionID", gAgent.getSessionID() );
+			msg->nextBlock("Data");
+			msg->addUUID("TargetID", avatar_id );
+			msg->addU32("Flags", flags );
+			msg->sendReliable( avatar->getRegion()->getHost() );
+		}
+	}
+	else if (ban_enabled)
+	{
+		// This is tricky. It is similar to say if it is not an 'Eject' button,
+		// and it is also not an 'Cancle' button, and ban_enabled==ture, 
+		// it should be the 'Eject and Ban' button.
+		LLMessageSystem* msg = gMessageSystem;
+		LLViewerObject* avatar = gObjectList.findObject(avatar_id);
 
+		if (avatar)
+		{
+			U32 flags = 0x1;
 			msg->newMessage("EjectUser");
 			msg->nextBlock("AgentData");
 			msg->addUUID("AgentID", gAgent.getID() );
 			msg->addUUID("SessionID", gAgent.getSessionID() );
 			msg->nextBlock("Data");
-			msg->addUUID("TargetID", *avatar_id );
+			msg->addUUID("TargetID", avatar_id );
 			msg->addU32("Flags", flags );
 			msg->sendReliable( avatar->getRegion()->getHost() );
 		}
 	}
 
-	delete avatar_id;
-	avatar_id = NULL;
+
+	delete callback_data;
+	callback_data = NULL;
 }
 
 class LLAvatarEject : public view_listener_t
@@ -2386,23 +2420,50 @@ class LLAvatarEject : public view_listener_t
 		LLVOAvatar* avatar = find_avatar_from_object( LLSelectMgr::getInstance()->getSelection()->getFirstObject() );
 		if( avatar )
 		{
-			LLUUID* avatar_id = new LLUUID( avatar->getID() );
+			MenuCallbackData *data = new MenuCallbackData;
+			(*data).avatar_id = avatar->getID();
 			std::string fullname = avatar->getFullname();
 
-			if (!fullname.empty())
+			const LLVector3d& pos = avatar->getPositionGlobal();
+			LLParcel* parcel = LLViewerParcelMgr::getInstance()->selectParcelAt(pos)->getParcel();
+			
+			if (LLViewerParcelMgr::getInstance()->isParcelOwnedByAgent(parcel,GP_LAND_MANAGE_BANNED))
 			{
-				LLStringUtil::format_map_t args;
-				args["[AVATAR_NAME]"] = fullname;
-				gViewerWindow->alertXml("EjectAvatarFullname",
-							args,
-							callback_eject,
-							(void*)avatar_id);
+				(*data).ban_enabled = true;
+				if (!fullname.empty())
+				{
+					LLStringUtil::format_map_t args;
+					args["[AVATAR_NAME]"] = fullname;
+					gViewerWindow->alertXml("EjectAvatarFullname",
+						args,
+						callback_eject,
+						(void*)data);
+				}
+				else
+				{
+					gViewerWindow->alertXml("EjectAvatar",
+						callback_eject,
+						(void*)data);
+				}
 			}
 			else
 			{
-				gViewerWindow->alertXml("EjectAvatar",
-							callback_eject,
-							(void*)avatar_id);
+				(*data).ban_enabled = false;
+				if (!fullname.empty())
+				{
+					LLStringUtil::format_map_t args;
+					args["[AVATAR_NAME]"] = fullname;
+					gViewerWindow->alertXml("EjectAvatarFullnameNoBan",
+						args,
+						callback_eject,
+						(void*)data);
+				}
+				else
+				{
+					gViewerWindow->alertXml("EjectAvatarNoBan",
+						callback_eject,
+						(void*)data);
+				}
 			}
 		}
 		return true;
@@ -2419,12 +2480,18 @@ class LLAvatarEnableFreezeEject : public view_listener_t
 		if (new_value)
 		{
 			const LLVector3& pos = avatar->getPositionRegion();
+			const LLVector3d& pos_global = avatar->getPositionGlobal();
+			LLParcel* parcel = LLViewerParcelMgr::getInstance()->selectParcelAt(pos_global)->getParcel();
 			LLViewerRegion* region = avatar->getRegion();
 			new_value = (region != NULL);
-
+						
 			if (new_value)
 			{
-				new_value = (region->isOwnedSelf(pos) || region->isOwnedGroup(pos));
+				new_value = region->isOwnedSelf(pos);
+				if (!new_value || region->isOwnedGroup(pos))
+				{
+					new_value = LLViewerParcelMgr::getInstance()->isParcelOwnedByAgent(parcel,GP_LAND_ADMIN);
+				}
 			}
 		}
 
diff --git a/indra/newview/llviewermenufile.cpp b/indra/newview/llviewermenufile.cpp
index b27d33b0e68b855bd5474633de637153464fe615..27badfb1ddccd44c7f1f122ed58e8fe3d638a18b 100644
--- a/indra/newview/llviewermenufile.cpp
+++ b/indra/newview/llviewermenufile.cpp
@@ -503,7 +503,7 @@ void handle_compress_image(void*)
 			}
 			else
 			{
-				llinfos << "Compression failed: " << LLImageBase::getLastError() << llendl;
+				llinfos << "Compression failed: " << LLImage::getLastError() << llendl;
 			}
 
 			infile = picker.getNextFile();
@@ -554,9 +554,9 @@ void upload_new_resource(const std::string& src_filename, std::string name,
 												 IMG_CODEC_BMP ))
 		{
 			error_message = llformat( "Problem with file %s:\n\n%s\n",
-					src_filename.c_str(), LLImageBase::getLastError().c_str());
+					 src_filename.c_str(), LLImage::getLastError().c_str());
 			args["[FILE]"] = src_filename;
-			args["[ERROR]"] = LLImageBase::getLastError();
+			args["[ERROR]"] = LLImage::getLastError();
 			upload_error(error_message, "ProblemWithFile", filename, args);
 			return;
 		}
@@ -569,9 +569,9 @@ void upload_new_resource(const std::string& src_filename, std::string name,
 												 IMG_CODEC_TGA ))
 		{
 			error_message = llformat("Problem with file %s:\n\n%s\n",
-					src_filename.c_str(), LLImageBase::getLastError().c_str());
+					src_filename.c_str(), LLImage::getLastError().c_str());
 			args["[FILE]"] = src_filename;
-			args["[ERROR]"] = LLImageBase::getLastError();
+			args["[ERROR]"] = LLImage::getLastError();
 			upload_error(error_message, "ProblemWithFile", filename, args);
 			return;
 		}
@@ -584,9 +584,9 @@ void upload_new_resource(const std::string& src_filename, std::string name,
 												 IMG_CODEC_JPEG ))
 		{
 			error_message = llformat("Problem with file %s:\n\n%s\n",
-					src_filename.c_str(), LLImageBase::getLastError().c_str());
+					src_filename.c_str(), LLImage::getLastError().c_str());
 			args["[FILE]"] = src_filename;
-			args["[ERROR]"] = LLImageBase::getLastError();
+			args["[ERROR]"] = LLImage::getLastError();
 			upload_error(error_message, "ProblemWithFile", filename, args);
 			return;
 		}
@@ -599,9 +599,9 @@ void upload_new_resource(const std::string& src_filename, std::string name,
  												 IMG_CODEC_PNG ))
  		{
  			error_message = llformat("Problem with file %s:\n\n%s\n",
- 					src_filename.c_str(), LLImageBase::getLastError().c_str());
+ 					src_filename.c_str(), LLImage::getLastError().c_str());
  			args["[FILE]"] = src_filename;
- 			args["[ERROR]"] = LLImageBase::getLastError();
+ 			args["[ERROR]"] = LLImage::getLastError();
  			upload_error(error_message, "ProblemWithFile", filename, args);
  			return;
  		}
diff --git a/indra/newview/llviewerregion.cpp b/indra/newview/llviewerregion.cpp
index b22ca7d2e906bae84af32361aaf6a325765b8da3..f8c7b317f0affa4e3cc2bd0b12e11ea5c7a5a957 100644
--- a/indra/newview/llviewerregion.cpp
+++ b/indra/newview/llviewerregion.cpp
@@ -1389,6 +1389,7 @@ void LLViewerRegion::setSeedCapability(const std::string& url)
 	capabilityNames.append("EventQueueGet");
 	capabilityNames.append("FetchInventoryDescendents");
 	capabilityNames.append("GroupProposalBallot");
+	capabilityNames.append("HomeLocation");
 	capabilityNames.append("MapLayer");
 	capabilityNames.append("MapLayerGod");
 	capabilityNames.append("NewFileAgentInventory");
diff --git a/indra/newview/llvoavatar.cpp b/indra/newview/llvoavatar.cpp
index e9440dc9cbb9c9e3df3eb368cc9e4fee83cc66be..d5d7056ef72fdaa9e8951d758ad3fccf69733af6 100644
--- a/indra/newview/llvoavatar.cpp
+++ b/indra/newview/llvoavatar.cpp
@@ -1131,7 +1131,7 @@ void LLVOAvatar::dumpBakedStatus()
 		}
 
 
-		F64 dist_to_camera = (inst->getPositionGlobal() - camera_pos_global).magVec();
+		F64 dist_to_camera = (inst->getPositionGlobal() - camera_pos_global).length();
 		llcont << " " << dist_to_camera << "m ";
 
 		llcont << " " << inst->mPixelArea << " pixels";
@@ -2684,8 +2684,8 @@ void LLVOAvatar::idleUpdateMisc(bool detailed_update)
 			else
 			{
 				getSpatialExtents(ext[0], ext[1]);
-				if ((ext[1]-mImpostorExtents[1]).magVec() > 0.05f ||
-					(ext[0]-mImpostorExtents[0]).magVec() > 0.05f)
+				if ((ext[1]-mImpostorExtents[1]).length() > 0.05f ||
+					(ext[0]-mImpostorExtents[0]).length() > 0.05f)
 				{
 					mNeedsImpostorUpdate = TRUE;
 				}
@@ -2852,7 +2852,7 @@ void LLVOAvatar::idleUpdateWindEffect()
 		F32 time_delta = mRippleTimer.getElapsedTimeF32() - mRippleTimeLast;
 		mRippleTimeLast = mRippleTimer.getElapsedTimeF32();
 		LLVector3 velocity = getVelocity();
-		F32 speed = velocity.magVec();
+		F32 speed = velocity.length();
 		//RN: velocity varies too much frame to frame for this to work
 		mRippleAccel.clearVec();//lerp(mRippleAccel, (velocity - mLastVel) * time_delta, LLCriticalDamp::getInterpolant(0.02f));
 		mLastVel = velocity;
@@ -2871,7 +2871,7 @@ void LLVOAvatar::idleUpdateWindEffect()
 		}
 
 		wind.mV[VZ] += hover_strength;
-		wind.normVec();
+		wind.normalize();
 
 		wind.mV[VW] = llmin(0.025f + (speed * 0.015f) + hover_strength, 0.5f);
 		F32 interp;
@@ -2994,10 +2994,10 @@ void LLVOAvatar::idleUpdateNameTag(const LLVector3& root_pos_last)
 				LLVector3 pixel_up_vec;
 				LLViewerCamera::getInstance()->getPixelVectors(root_pos_last, pixel_up_vec, pixel_right_vec);
 				LLVector3 camera_to_av = root_pos_last - LLViewerCamera::getInstance()->getOrigin();
-				camera_to_av.normVec();
+				camera_to_av.normalize();
 				LLVector3 local_camera_at = camera_to_av * ~root_rot;
 				LLVector3 local_camera_up = camera_to_av % LLViewerCamera::getInstance()->getLeftAxis();
-				local_camera_up.normVec();
+				local_camera_up.normalize();
 				local_camera_up = local_camera_up * ~root_rot;
 			
 				local_camera_up.scaleVec(mBodySize * 0.5f);
@@ -3456,7 +3456,7 @@ BOOL LLVOAvatar::updateCharacter(LLAgent &agent)
 
 	LLVector3 xyVel = getVelocity();
 	xyVel.mV[VZ] = 0.0f;
-	speed = xyVel.magVec();
+	speed = xyVel.length();
 
 	BOOL throttle = TRUE;
 
@@ -3541,14 +3541,14 @@ BOOL LLVOAvatar::updateCharacter(LLAgent &agent)
 			if (mIsSelf)
 			{
 				primDir = agent.getAtAxis() - projected_vec(agent.getAtAxis(), agent.getReferenceUpVector());
-				primDir.normVec();
+				primDir.normalize();
 			}
 			else
 			{
 				primDir = getRotation().getMatrix3().getFwdRow();
 			}
 			LLVector3 velDir = getVelocity();
-			velDir.normVec();
+			velDir.normalize();
 			if ( mSignaledAnimations.find(ANIM_AGENT_WALK) != mSignaledAnimations.end())
 			{
 				F32 vpD = velDir * primDir;
@@ -3570,13 +3570,13 @@ BOOL LLVOAvatar::updateCharacter(LLAgent &agent)
 					LLVector3 at_axis = LLViewerCamera::getInstance()->getAtAxis();
 					LLVector3 up_vector = gAgent.getReferenceUpVector();
 					at_axis -= up_vector * (at_axis * up_vector);
-					at_axis.normVec();
+					at_axis.normalize();
 					
 					F32 dot = fwdDir * at_axis;
 					if (dot < 0.f)
 					{
 						fwdDir -= 2.f * at_axis * dot;
-						fwdDir.normVec();
+						fwdDir.normalize();
 					}
 				}
 				
@@ -3644,7 +3644,7 @@ BOOL LLVOAvatar::updateCharacter(LLAgent &agent)
 
 			// Now compute the full world space rotation for the whole body (wQv)
 			LLVector3 leftDir = upDir % fwdDir;
-			leftDir.normVec();
+			leftDir.normalize();
 			fwdDir = leftDir % upDir;
 			LLQuaternion wQv( fwdDir, leftDir, upDir );
 
@@ -4253,7 +4253,7 @@ U32 LLVOAvatar::renderImpostor(LLColor4U color)
 
 	LLVector3 pos(getRenderPosition()+mImpostorOffset);
 	LLVector3 at = (pos - LLViewerCamera::getInstance()->getOrigin());
-	at.normVec();
+	at.normalize();
 	LLVector3 left = LLViewerCamera::getInstance()->getUpAxis() % at;
 	LLVector3 up = at%left;
 
@@ -5784,7 +5784,7 @@ void LLVOAvatar::setPixelAreaAndAngle(LLAgent &agent)
 	}
 	else
 	{
-		F32 radius = size.magVec();
+		F32 radius = size.length();
 		mAppAngle = (F32) atan2( radius, range) * RAD_TO_DEG;
 	}
 
@@ -5953,7 +5953,7 @@ void LLVOAvatar::updateShadowFaces()
 			sprite.setPosition(shadow_pos_agent);
 
 			LLVector3 foot_to_knee = mKneeLeftp->getWorldPosition() - joint_world_pos;
-			//foot_to_knee.normVec();
+			//foot_to_knee.normalize();
 			foot_to_knee -= projected_vec(foot_to_knee, sun_vec);
 			sprite.setYaw(azimuth(sun_vec - foot_to_knee));
 		
@@ -5986,7 +5986,7 @@ void LLVOAvatar::updateShadowFaces()
 			sprite.setPosition(shadow_pos_agent);
 
 			LLVector3 foot_to_knee = mKneeRightp->getWorldPosition() - joint_world_pos;
-			//foot_to_knee.normVec();
+			//foot_to_knee.normalize();
 			foot_to_knee -= projected_vec(foot_to_knee, sun_vec);
 			sprite.setYaw(azimuth(sun_vec - foot_to_knee));
 	
@@ -6355,7 +6355,7 @@ void LLVOAvatar::getOffObject()
 		LLVector3 at_axis = LLVector3::x_axis;
 		at_axis = at_axis * av_rot;
 		at_axis.mV[VZ] = 0.f;
-		at_axis.normVec();
+		at_axis.normalize();
 		gAgent.resetAxes(at_axis);
 
 		//reset orientation
@@ -9861,7 +9861,7 @@ void LLVOAvatar::getImpostorValues(LLVector3* extents, LLVector3& angle, F32& di
 	extents[1] = ext[1];
 
 	LLVector3 at = LLViewerCamera::getInstance()->getOrigin()-(getRenderPosition()+mImpostorOffset);
-	distance = at.normVec();
+	distance = at.normalize();
 	F32 da = 1.f - (at*LLViewerCamera::getInstance()->getAtAxis());
 	angle.mV[0] = LLViewerCamera::getInstance()->getYaw()*da;
 	angle.mV[1] = LLViewerCamera::getInstance()->getPitch()*da;
diff --git a/indra/newview/llvograss.cpp b/indra/newview/llvograss.cpp
index cc7d73e37a85d3fcd3e2b3ece077ddf280a1ecc6..c7326688a0131c1aad2ba09eca120d87859f4954 100644
--- a/indra/newview/llvograss.cpp
+++ b/indra/newview/llvograss.cpp
@@ -273,9 +273,9 @@ U32 LLVOGrass::processUpdateMessage(LLMessageSystem *mesgsys,
 
 	updateSpecies();
 
-	if (  (getVelocity().magVecSquared() > 0.f)
-		||(getAcceleration().magVecSquared() > 0.f)
-		||(getAngularVelocity().magVecSquared() > 0.f))
+	if (  (getVelocity().lengthSquared() > 0.f)
+		||(getAcceleration().lengthSquared() > 0.f)
+		||(getAngularVelocity().lengthSquared() > 0.f))
 	{
 		llinfos << "ACK! Moving grass!" << llendl;
 		setVelocity(LLVector3::zero);
@@ -322,7 +322,7 @@ void LLVOGrass::setPixelAreaAndAngle(LLAgent &agent)
 {
 	// This should be the camera's center, as soon as we move to all region-local.
 	LLVector3 relative_position = getPositionAgent() - agent.getCameraPositionAgent();
-	F32 range = relative_position.magVec();
+	F32 range = relative_position.length();
 
 	F32 max_scale = getMaxScale();
 
@@ -501,7 +501,7 @@ void LLVOGrass::getGeometry(S32 idx,
 
 		LLVector3 normal1 = (v1-v2) % (v2-v3);
 		normal1.mV[VZ] = 0.75f;
-		normal1.normVec();
+		normal1.normalize();
 		LLVector3 normal2 = -normal1;
 		normal2.mV[VZ] = -normal2.mV[VZ];
 
diff --git a/indra/newview/llvopartgroup.cpp b/indra/newview/llvopartgroup.cpp
index 6cc61e36e0039a3d5776d3ad0724a7e5f3ec905c..3724a94edd8ffd991b4942c773a8c81b0cfcbc1c 100644
--- a/indra/newview/llvopartgroup.cpp
+++ b/indra/newview/llvopartgroup.cpp
@@ -95,7 +95,7 @@ void LLVOPartGroup::setPixelAreaAndAngle(LLAgent &agent)
 {
 	// mPixelArea is calculated during render
 	F32 mid_scale = getMidScale();
-	F32 range = (getRenderPosition()-LLViewerCamera::getInstance()->getOrigin()).magVec();
+	F32 range = (getRenderPosition()-LLViewerCamera::getInstance()->getOrigin()).length();
 
 	if (range < 0.001f || isHUDAttachment())		// range == zero
 	{
@@ -189,7 +189,7 @@ BOOL LLVOPartGroup::updateGeometry(LLDrawable *drawable)
 		LLVector3 part_pos_agent(part->mPosAgent);
 		at = part_pos_agent - camera_agent;
 
-		F32 camera_dist_squared = at.magVecSquared();
+		F32 camera_dist_squared = at.lengthSquared();
 		F32 inv_camera_dist_squared;
 		if (camera_dist_squared > 1.f)
 			inv_camera_dist_squared = 1.f / camera_dist_squared;
@@ -283,26 +283,26 @@ void LLVOPartGroup::getGeometry(S32 idx,
 	LLVector3 up, right;
 
 	right = at % LLVector3(0.f, 0.f, 1.f);
-	right.normVec();
+	right.normalize();
 	up = right % at;
-	up.normVec();
+	up.normalize();
 
 	if (part.mFlags & LLPartData::LL_PART_FOLLOW_VELOCITY_MASK)
 	{
 		LLVector3 normvel = part.mVelocity;
-		normvel.normVec();
+		normvel.normalize();
 		LLVector2 up_fracs;
 		up_fracs.mV[0] = normvel*right;
 		up_fracs.mV[1] = normvel*up;
-		up_fracs.normVec();
+		up_fracs.normalize();
 		LLVector3 new_up;
 		LLVector3 new_right;
 		new_up = up_fracs.mV[0] * right + up_fracs.mV[1]*up;
 		new_right = up_fracs.mV[1] * right - up_fracs.mV[0]*up;
 		up = new_up;
 		right = new_right;
-		up.normVec();
-		right.normVec();
+		up.normalize();
+		right.normalize();
 	}
 
 	right *= 0.5f*part.mScale.mV[0];
diff --git a/indra/newview/llvosky.cpp b/indra/newview/llvosky.cpp
index 330d5c370d4775a8607a6828588940aa53107b2e..e619ca17548fc595cebbd4a829a4cffc70610156 100644
--- a/indra/newview/llvosky.cpp
+++ b/indra/newview/llvosky.cpp
@@ -528,7 +528,7 @@ void LLVOSky::initSkyTextureDirs(const S32 side, const S32 tile)
 			coeff[x_coef] = F32((x<<1) + 1) * inv_res - 1.f;
 			coeff[y_coef] = F32((y<<1) + 1) * inv_res - 1.f;
 			LLVector3 dir(coeff[0], coeff[1], coeff[2]);
-			dir.normVec();
+			dir.normalize();
 			mSkyTex[side].setDir(dir, x, y);
 			mShinyTex[side].setDir(dir, x, y);
 		}
@@ -762,7 +762,7 @@ void LLVOSky::calcSkyColorWLVert(LLVector3 & Pn, LLColor3 & vary_HazeColor, LLCo
 		Pn *= (-32000.f / Pn[1]);
 	}
 
-	Plen = Pn.magVec();
+	Plen = Pn.length();
 	Pn /= Plen;
 
 	// Initialize temp variables
@@ -1082,7 +1082,7 @@ BOOL LLVOSky::updateSky()
 			const static F32 COLOR_CHANGE_THRESHOLD = 0.01f;
 
 			LLVector3 direction = mSun.getDirection();
-			direction.normVec();
+			direction.normalize();
 			const F32 dot_lighting = direction * mLastLightingDirection;
 
 			LLColor3 delta_color;
@@ -1092,7 +1092,7 @@ BOOL LLVOSky::updateSky()
 
 			if ( mForceUpdate 
 				 || ((dot_lighting < LIGHT_DIRECTION_THRESHOLD)
-				 || (delta_color.magVec() > COLOR_CHANGE_THRESHOLD)
+				 || (delta_color.length() > COLOR_CHANGE_THRESHOLD)
 				 || !mInitialized)
 				&& !direction.isExactlyZero())
 			{
@@ -1336,8 +1336,8 @@ BOOL LLVOSky::updateGeometry(LLDrawable *drawable)
 	const LLVector3 &look_at = LLViewerCamera::getInstance()->getAtAxis();
 	LLVector3 right = look_at % LLVector3::z_axis;
 	LLVector3 up = right % look_at;
-	right.normVec();
-	up.normVec();
+	right.normalize();
+	up.normalize();
 
 	const static F32 elevation_factor = 0.0f/sResolution;
 	const F32 cos_max_angle = cosHorizon(elevation_factor);
@@ -1417,8 +1417,8 @@ BOOL LLVOSky::updateHeavenlyBodyGeometry(LLDrawable *drawable, const S32 f, cons
 
 	LLVector3 hb_right = to_dir % LLVector3::z_axis;
 	LLVector3 hb_up = hb_right % to_dir;
-	hb_right.normVec();
-	hb_up.normVec();
+	hb_right.normalize();
+	hb_up.normalize();
 
 	//const static F32 cos_max_turn = sqrt(3.f) / 2; // 30 degrees
 	//const F32 cos_turn_right = 1. / (llmax(cos_max_turn, hb_right * right));
@@ -1601,8 +1601,8 @@ void LLVOSky::updateSunHaloGeometry(LLDrawable *drawable )
 
 	const LLVector3 right = 2 * (v_corner[2] - v_corner[0]);
 	LLVector3 up = 2 * (v_corner[2] - v_corner[3]);
-	up.normVec();
-	F32 size = right.magVec();
+	up.normalize();
+	F32 size = right.length();
 	up = size * up;
 	const LLVector3 draw_pos = 0.25 * (v_corner[0] + v_corner[1] + v_corner[2] + v_corner[3]);
 	
@@ -1654,7 +1654,7 @@ void LLVOSky::updateSunHaloGeometry(LLDrawable *drawable )
 F32 dtReflection(const LLVector3& p, F32 cos_dir_from_top, F32 sin_dir_from_top, F32 diff_angl_dir)
 {
 	LLVector3 P = p;
-	P.normVec();
+	P.normalize();
 
 	const F32 cos_dir_angle = -P.mV[VZ];
 	const F32 sin_dir_angle = sqrt(1 - cos_dir_angle * cos_dir_angle);
@@ -1679,9 +1679,9 @@ F32 dtClip(const LLVector3& v0, const LLVector3& v1, F32 far_clip2)
 {
 	F32 dt_clip;
 	const LLVector3 otrezok = v1 - v0;
-	const F32 A = otrezok.magVecSquared();
+	const F32 A = otrezok.lengthSquared();
 	const F32 B = v0 * otrezok;
-	const F32 C = v0.magVecSquared() - far_clip2;
+	const F32 C = v0.lengthSquared() - far_clip2;
 	const F32 det = sqrt(B*B - A*C);
 	dt_clip = (-B - det) / A;
 	if ((dt_clip < 0) || (dt_clip > 1))
@@ -1701,16 +1701,16 @@ void LLVOSky::updateReflectionGeometry(LLDrawable *drawable, F32 H,
 	LLVector3 hb_pos = to_dir * (HORIZON_DIST - 10);
 	LLVector3 to_dir_proj = to_dir;
 	to_dir_proj.mV[VZ] = 0;
-	to_dir_proj.normVec();
+	to_dir_proj.normalize();
 
 	LLVector3 Right = to_dir % LLVector3::z_axis;
 	LLVector3 Up = Right % to_dir;
-	Right.normVec();
-	Up.normVec();
+	Right.normalize();
+	Up.normalize();
 
 	// finding angle between  look direction and sprite.
 	LLVector3 look_at_right = look_at % LLVector3::z_axis;
-	look_at_right.normVec();
+	look_at_right.normalize();
 
 	const static F32 cos_horizon_angle = cosHorizon(0.0f/sResolution);
 	//const static F32 horizon_angle = acos(cos_horizon_angle);
@@ -1745,7 +1745,7 @@ void LLVOSky::updateReflectionGeometry(LLDrawable *drawable, F32 H,
 	else
 		dt_hor = llmax(0.0f, llmin(1.0f, dt_hor));
 
-	top_hb.normVec();
+	top_hb.normalize();
 	const F32 cos_angle_of_view = fabs(top_hb.mV[VZ]);
 	const F32 extension = llmin (5.0f, 1.0f / cos_angle_of_view);
 
@@ -1762,11 +1762,11 @@ void LLVOSky::updateReflectionGeometry(LLDrawable *drawable, F32 H,
 	F32 cos_dir_from_top[2];
 
 	LLVector3 dir = stretch_corner[0];
-	dir.normVec();
+	dir.normalize();
 	cos_dir_from_top[0] = dir.mV[VZ];
 
 	dir = stretch_corner[1];
-	dir.normVec();
+	dir.normalize();
 	cos_dir_from_top[1] = dir.mV[VZ];
 
 	const F32 sin_dir_from_top = sqrt(1 - cos_dir_from_top[0] * cos_dir_from_top[0]);
@@ -1789,7 +1789,7 @@ void LLVOSky::updateReflectionGeometry(LLDrawable *drawable, F32 H,
 	for (vtx = 0; vtx < 2; ++vtx)
 	{
 		LLVector3 light_proj = v_corner[vtx];
-		light_proj.normVec();
+		light_proj.normalize();
 
 		const F32 z = light_proj.mV[VZ];
 		const F32 sin_angle = sqrt(1 - z * z);
@@ -1813,9 +1813,9 @@ void LLVOSky::updateReflectionGeometry(LLDrawable *drawable, F32 H,
 	S32 side = 0;
 	LLVector3 refl_corn_norm[2];
 	refl_corn_norm[0] = v_refl_corner[1];
-	refl_corn_norm[0].normVec();
+	refl_corn_norm[0].normalize();
 	refl_corn_norm[1] = v_refl_corner[3];
-	refl_corn_norm[1].normVec();
+	refl_corn_norm[1].normalize();
 
 	F32 cos_refl_look_at[2];
 	cos_refl_look_at[0] = refl_corn_norm[0] * look_at;
@@ -1833,13 +1833,13 @@ void LLVOSky::updateReflectionGeometry(LLDrawable *drawable, F32 H,
 	F32 dt_clip;
 	F32 vtx_near2, vtx_far2;
 
-	if ((vtx_far2 = v_refl_corner[side].magVecSquared()) > far_clip2)
+	if ((vtx_far2 = v_refl_corner[side].lengthSquared()) > far_clip2)
 	{
 		// whole thing is sprite: reflection is beyond far clip plane.
 		dt_clip = 1.1f;
 		quads = 1;
 	}
-	else if ((vtx_near2 = v_refl_corner[side+1].magVecSquared()) > far_clip2)
+	else if ((vtx_near2 = v_refl_corner[side+1].lengthSquared()) > far_clip2)
 	{
 		// part is reflection, the rest is sprite.
 		dt_clip = dtClip(v_refl_corner[side + 1], v_refl_corner[side], far_clip2);
@@ -1903,7 +1903,7 @@ void LLVOSky::updateReflectionGeometry(LLDrawable *drawable, F32 H,
 		{
 			for (S32 vtx = 0; vtx < 4; ++vtx)
 			{
-				F32 ratio = far_clip / v_refl_corner[vtx].magVec();
+				F32 ratio = far_clip / v_refl_corner[vtx].length();
 				*(verticesp++) = v_refl_corner[vtx] = ratio * v_refl_corner[vtx] + mCameraPosAgent;
 			}
 			const LLVector3 draw_pos = 0.25 *
@@ -1912,10 +1912,10 @@ void LLVOSky::updateReflectionGeometry(LLDrawable *drawable, F32 H,
 		}
 		else
 		{
-			F32 ratio = far_clip / v_refl_corner[1].magVec();
+			F32 ratio = far_clip / v_refl_corner[1].length();
 			v_sprite_corner[1] = v_refl_corner[1] * ratio;
 
-			ratio = far_clip / v_refl_corner[3].magVec();
+			ratio = far_clip / v_refl_corner[3].length();
 			v_sprite_corner[3] = v_refl_corner[3] * ratio;
 
 			v_refl_corner[1] = (1 - dt_clip) * v_refl_corner[1] + dt_clip * v_refl_corner[0];
@@ -2039,20 +2039,20 @@ void LLVOSky::updateFog(const F32 distance)
 	LLVector3 tosun = getToSunLast();
 	const F32 tosun_z = tosun.mV[VZ];
 	tosun.mV[VZ] = 0.f;
-	tosun.normVec();
+	tosun.normalize();
 	LLVector3 perp_tosun;
 	perp_tosun.mV[VX] = -tosun.mV[VY];
 	perp_tosun.mV[VY] = tosun.mV[VX];
 	LLVector3 tosun_45 = tosun + perp_tosun;
-	tosun_45.normVec();
+	tosun_45.normalize();
 
 	F32 delta = 0.06f;
 	tosun.mV[VZ] = delta;
 	perp_tosun.mV[VZ] = delta;
 	tosun_45.mV[VZ] = delta;
-	tosun.normVec();
-	perp_tosun.normVec();
-	tosun_45.normVec();
+	tosun.normalize();
+	perp_tosun.normalize();
+	tosun_45.normalize();
 
 	// Sky colors, just slightly above the horizon in the direction of the sun, perpendicular to the sun, and at a 45 degree angle to the sun.
 	initAtmospherics();
@@ -2202,8 +2202,8 @@ F32 azimuth(const LLVector3 &v)
 
 void LLVOSky::initSunDirection(const LLVector3 &sun_dir, const LLVector3 &sun_ang_velocity)
 {
-	LLVector3 sun_direction = (sun_dir.magVec() == 0) ? LLVector3::x_axis : sun_dir;
-	sun_direction.normVec();
+	LLVector3 sun_direction = (sun_dir.length() == 0) ? LLVector3::x_axis : sun_dir;
+	sun_direction.normalize();
 	mSun.setDirection(sun_direction);
 	mSun.renewDirection();
 	mSun.setAngularVelocity(sun_ang_velocity);
@@ -2222,8 +2222,8 @@ void LLVOSky::initSunDirection(const LLVector3 &sun_dir, const LLVector3 &sun_an
 
 void LLVOSky::setSunDirection(const LLVector3 &sun_dir, const LLVector3 &sun_ang_velocity)
 {
-	LLVector3 sun_direction = (sun_dir.magVec() == 0) ? LLVector3::x_axis : sun_dir;
-	sun_direction.normVec();
+	LLVector3 sun_direction = (sun_dir.length() == 0) ? LLVector3::x_axis : sun_dir;
+	sun_direction.normalize();
 
 	// Push the sun "South" as it approaches directly overhead so that we can always see bump mapping
 	// on the upward facing faces of cubes.
@@ -2239,7 +2239,7 @@ void LLVOSky::setSunDirection(const LLVector3 &sun_dir, const LLVector3 &sun_ang
 	// Blend between normal sun dir and adjusted sun dir based on how close we are
 	// to having the sun overhead.
 	mBumpSunDir = adjustedDir * sunDot + newDir * (1.0f - sunDot);
-	mBumpSunDir.normVec();
+	mBumpSunDir.normalize();
 
 	F32 dp = mLastLightingDirection * sun_direction;
 	mSun.setDirection(sun_direction);
diff --git a/indra/newview/llvotextbubble.cpp b/indra/newview/llvotextbubble.cpp
index b48a5a989ccb7fd2dba80c7ea4044de04bbf916d..952c3c9a87eace73d63af5ac7d97fc0a4eef2381 100644
--- a/indra/newview/llvotextbubble.cpp
+++ b/indra/newview/llvotextbubble.cpp
@@ -126,7 +126,7 @@ void LLVOTextBubble::updateTextures(LLAgent &agent)
 
 	LLVector3 position_local = getPositionAgent() - agent.getCameraPositionAgent();
 	F32 dot_product = position_local * agent.getFrameAgent().getAtAxis();
-	F32 cos_angle = dot_product / position_local.magVec();
+	F32 cos_angle = dot_product / position_local.length();
 
 	if (cos_angle > 1.f)
 	{
diff --git a/indra/newview/llvotree.cpp b/indra/newview/llvotree.cpp
index 97a1ed162d4c17eddb30152844d1e80d2c51d7c9..0c9b524f7f4ffb40f0489732367b1ce1d0bcecef 100644
--- a/indra/newview/llvotree.cpp
+++ b/indra/newview/llvotree.cpp
@@ -273,9 +273,9 @@ U32 LLVOTree::processUpdateMessage(LLMessageSystem *mesgsys,
 	// Do base class updates...
 	U32 retval = LLViewerObject::processUpdateMessage(mesgsys, user_data, block_num, update_type, dp);
 
-	if (  (getVelocity().magVecSquared() > 0.f)
-		||(getAcceleration().magVecSquared() > 0.f)
-		||(getAngularVelocity().magVecSquared() > 0.f))
+	if (  (getVelocity().lengthSquared() > 0.f)
+		||(getAcceleration().lengthSquared() > 0.f)
+		||(getAngularVelocity().lengthSquared() > 0.f))
 	{
 		llinfos << "ACK! Moving tree!" << llendl;
 		setVelocity(LLVector3::zero);
@@ -359,14 +359,14 @@ BOOL LLVOTree::idleUpdate(LLAgent &agent, LLWorld &world, const F64 &time)
 	mTrunkBend += mTrunkVel;
 	mTrunkVel *= 0.99f;									//  Add damping
 
-	if (mTrunkBend.magVec() > 1.f)
+	if (mTrunkBend.length() > 1.f)
 	{
-		mTrunkBend.normVec();
+		mTrunkBend.normalize();
 	}
 
-	if (mTrunkVel.magVec() > 1.f)
+	if (mTrunkVel.length() > 1.f)
 	{
-		mTrunkVel.normVec();
+		mTrunkVel.normalize();
 	}
 
 	return TRUE;
@@ -391,7 +391,7 @@ void LLVOTree::setPixelAreaAndAngle(LLAgent &agent)
 	
 	// This should be the camera's center, as soon as we move to all region-local.
 	LLVector3 relative_position = getPositionAgent() - agent.getCameraPositionAgent();
-	F32 range = relative_position.magVec();				// ugh, square root
+	F32 range = relative_position.length();				// ugh, square root
 
 	F32 max_scale = mBillboardScale * getMaxScale();
 	F32 area = max_scale * (max_scale*mBillboardRatio);
@@ -713,9 +713,9 @@ BOOL LLVOTree::updateGeometry(LLDrawable *drawable)
 				LLVector2 tc;
 				// This isn't totally accurate.  Should compute based on slope as well.
 				start_radius = r0 * (1.f + 1.2f*fabs(z - 0.66f*height)/height);
-				nvec.setVec(	cos(nangle * DEG_TO_RAD)*start_radius*nvec_scale, 
-								sin(nangle * DEG_TO_RAD)*start_radius*nvec_scale, 
-								z*nvec_scalez); 
+				nvec.set(	cos(nangle * DEG_TO_RAD)*start_radius*nvec_scale, 
+							sin(nangle * DEG_TO_RAD)*start_radius*nvec_scale, 
+							z*nvec_scalez); 
 				// First and last slice at 0 radius (to bring in top/bottom of structure)
 				radius = start_radius + turbulence3((F32*)&nvec.mV, (F32)fractal_depth)*noise_scale;
 
@@ -918,7 +918,7 @@ void LLVOTree::updateRadius()
 
 void LLVOTree::updateSpatialExtents(LLVector3& newMin, LLVector3& newMax)
 {
-	F32 radius = getScale().magVec()*0.05f;
+	F32 radius = getScale().length()*0.05f;
 	LLVector3 center = getRenderPosition();
 
 	F32 sz = mBillboardScale*mBillboardRatio*radius*0.5f; 
@@ -926,8 +926,8 @@ void LLVOTree::updateSpatialExtents(LLVector3& newMin, LLVector3& newMax)
 
 	center += LLVector3(0, 0, size.mV[2]) * getRotation();
 	
-	newMin.setVec(center-size);
-	newMax.setVec(center+size);
+	newMin.set(center-size);
+	newMax.set(center+size);
 	mDrawable->setPositionGroup(center);
 }
 
diff --git a/indra/newview/llvovolume.cpp b/indra/newview/llvovolume.cpp
index 225d9a18b26ff673dca0bb542385698c0d4ee7a6..c6a7e9e28dee2bb677853c87bb8f84bb890f40bc 100644
--- a/indra/newview/llvovolume.cpp
+++ b/indra/newview/llvovolume.cpp
@@ -89,7 +89,7 @@ LLVOVolume::LLVOVolume(const LLUUID &id, const LLPCode pcode, LLViewerRegion *re
 	mLOD = MIN_LOD;
 	mSculptLevel = -2;
 	mTextureAnimp = NULL;
-	mVObjRadius = LLVector3(1,1,0.5f).magVec();
+	mVObjRadius = LLVector3(1,1,0.5f).length();
 	mNumFaces = 0;
 	mLODChanged = FALSE;
 	mSculptChanged = FALSE;
@@ -570,7 +570,7 @@ F32 LLVOVolume::getTextureVirtualSize(LLFace* face)
 
 	//get area of circle in texture space
 	LLVector2 tdim = face->mTexExtents[1] - face->mTexExtents[0];
-	F32 texel_area = (tdim * 0.5f).magVecSquared()*3.14159f;
+	F32 texel_area = (tdim * 0.5f).lengthSquared()*3.14159f;
 	if (texel_area <= 0)
 	{
 		// Probably animated, use default
@@ -821,7 +821,7 @@ BOOL LLVOVolume::calcLOD()
 
 	S32 cur_detail = 0;
 	
-	F32 radius = getVolume()->mLODScaleBias.scaledVec(getScale()).magVec();
+	F32 radius = getVolume()->mLODScaleBias.scaledVec(getScale()).length();
 	F32 distance = mDrawable->mDistanceWRTCamera;
 	distance *= sDistanceFactor;
 			
@@ -1680,7 +1680,7 @@ void LLVOVolume::generateSilhouette(LLSelectNode* nodep, const LLVector3& view_p
 
 		//transform view vector into volume space
 		view_vector -= getRenderPosition();
-		mDrawable->mDistanceWRTCamera = view_vector.magVec();
+		mDrawable->mDistanceWRTCamera = view_vector.length();
 		LLQuaternion worldRot = getRenderRotation();
 		view_vector = view_vector * ~worldRot;
 		if (!isVolumeGlobal())
@@ -1721,7 +1721,7 @@ void LLVOVolume::updateRadius()
 		return;
 	}
 	
-	mVObjRadius = getScale().magVec();
+	mVObjRadius = getScale().length();
 	mDrawable->setRadius(mVObjRadius);
 }
 
@@ -1834,7 +1834,7 @@ F32 LLVOVolume::getBinRadius()
 	}
 	else if (shrink_wrap)
 	{
-		radius = (ext[1]-ext[0]).magVec()*0.5f;
+		radius = (ext[1]-ext[0]).length()*0.5f;
 	}
 	else if (mDrawable->isStatic())
 	{
@@ -1956,13 +1956,13 @@ BOOL LLVOVolume::lineSegmentIntersect(const LLVector3& start, const LLVector3& e
 			if (normal != NULL)
 			{
 				*normal = volumeDirectionToAgent(*normal);
-				(*normal).normVec();
+				(*normal).normalize();
 			}
 
 			if (bi_normal != NULL)
 			{
 				*bi_normal = volumeDirectionToAgent(*bi_normal);
-				(*bi_normal).normVec();
+				(*bi_normal).normalize();
 			}
 
 			
diff --git a/indra/newview/pipeline.cpp b/indra/newview/pipeline.cpp
index b9facb28b259ff164833901a00266f5ff51d2d1a..f3168be46c2762446f08853e8852941ee431675b 100644
--- a/indra/newview/pipeline.cpp
+++ b/indra/newview/pipeline.cpp
@@ -3089,7 +3089,7 @@ void LLPipeline::setupAvatarLights(BOOL for_edit)
 		camera_rot.invert();
 		LLVector4 light_pos = light_pos_cam * camera_rot;
 		
-		light_pos.normVec();
+		light_pos.normalize();
 
 		mHWLightColors[1] = diffuse;
 		glLightfv(GL_LIGHT1, GL_DIFFUSE,  diffuse.mV);
@@ -3107,7 +3107,7 @@ void LLPipeline::setupAvatarLights(BOOL for_edit)
 		LLVector3 opposite_pos = -1.f * mSunDir;
 		LLVector3 orthog_light_pos = mSunDir % LLVector3::z_axis;
 		LLVector4 backlight_pos = LLVector4(lerp(opposite_pos, orthog_light_pos, 0.3f), 0.0f);
-		backlight_pos.normVec();
+		backlight_pos.normalize();
 			
 		LLColor4 light_diffuse = mSunDiffuse;
 		LLColor4 backlight_diffuse(1.f - light_diffuse.mV[VRED], 1.f - light_diffuse.mV[VGREEN], 1.f - light_diffuse.mV[VBLUE], 1.f);
@@ -5172,11 +5172,11 @@ void LLPipeline::generateImpostor(LLVOAvatar* avatar)
 
 	LLVector3 left = camera.getLeftAxis();
 	left *= left;
-	left.normVec();
+	left.normalize();
 
 	LLVector3 up = camera.getUpAxis();
 	up *= up;
-	up.normVec();
+	up.normalize();
 
 	tdim.mV[0] = fabsf(half_height * left);
 	tdim.mV[1] = fabsf(half_height * up);