diff --git a/indra/llappearance/llwearable.cpp b/indra/llappearance/llwearable.cpp
index 8ffd62f36d..523c4f73c8 100755
--- a/indra/llappearance/llwearable.cpp
+++ b/indra/llappearance/llwearable.cpp
@@ -60,6 +60,9 @@ LLWearable::LLWearable()
// virtual
LLWearable::~LLWearable()
{
+ for (std::set< LLWearableObserver* >::iterator itr = mObservers.begin(); itr != mObservers.end(); ++itr )
+ (*itr)->onDestroyed( this );
+
for (visual_param_index_map_t::iterator vpIter = mVisualParamIndexMap.begin(); vpIter != mVisualParamIndexMap.end(); ++vpIter)
{
LLVisualParam* vp = vpIter->second;
diff --git a/indra/llappearance/llwearable.h b/indra/llappearance/llwearable.h
index 82634b733c..a63b38361b 100755
--- a/indra/llappearance/llwearable.h
+++ b/indra/llappearance/llwearable.h
@@ -42,6 +42,21 @@ class LLAvatarAppearance;
// Abstract class.
class LLWearable
{
+ // Try to see if this fixes the crash in LLPanelEditWearable::isDirty, that is the wearable dets destroyed before the panel
+public:
+ class LLWearableObserver
+ {
+ public:
+ virtual void onDestroyed(LLWearable const * ) = 0;
+ };
+
+public:
+ void registerObserver(LLWearableObserver *aObserver){ mObservers.insert(aObserver); }
+ void unregisterObserver(LLWearableObserver *aObserver){ mObservers.erase(aObserver); }
+private:
+ std::set< LLWearableObserver* > mObservers;
+ //
+
//--------------------------------------------------------------------
// Constructors and destructors
//--------------------------------------------------------------------
diff --git a/indra/newview/llpaneleditwearable.cpp b/indra/newview/llpaneleditwearable.cpp
index 4087f6f63f..041acea8ea 100755
--- a/indra/newview/llpaneleditwearable.cpp
+++ b/indra/newview/llpaneleditwearable.cpp
@@ -653,7 +653,8 @@ LLPanelEditWearable::LLPanelEditWearable()
//virtual
LLPanelEditWearable::~LLPanelEditWearable()
{
-
+ if (mWearablePtr)
+ mWearablePtr->unregisterObserver(this);
}
bool LLPanelEditWearable::changeHeightUnits(const LLSD& new_value)
@@ -883,7 +884,11 @@ void LLPanelEditWearable::setVisible(BOOL visible)
void LLPanelEditWearable::setWearable(LLViewerWearable *wearable, BOOL disable_camera_switch)
{
showWearable(mWearablePtr, FALSE, disable_camera_switch);
- mWearablePtr = wearable;
+ if (mWearablePtr)
+ mWearablePtr->unregisterObserver(this);
+ mWearablePtr = wearable;
+ if( mWearablePtr )
+ mWearablePtr->registerObserver( this );
showWearable(mWearablePtr, TRUE, disable_camera_switch);
}
diff --git a/indra/newview/llpaneleditwearable.h b/indra/newview/llpaneleditwearable.h
index 6a8c019647..26983ad2fa 100755
--- a/indra/newview/llpaneleditwearable.h
+++ b/indra/newview/llpaneleditwearable.h
@@ -33,6 +33,7 @@
#include "llavatarappearancedefines.h"
#include "llwearabletype.h"
+#include "llwearable.h" // for LLWearable::LLWearableObserver
class LLAccordionCtrl;
class LLCheckBoxCtrl;
class LLViewerWearable;
@@ -45,8 +46,12 @@ class LLAccordionCtrlTab;
class LLJoint;
class LLLineEditor;
-class LLPanelEditWearable : public LLPanel
+class LLPanelEditWearable : public LLPanel, public LLWearable::LLWearableObserver
{
+ // Try to see if this fixes the crash in LLPanelEditWearable::isDirty, that is the wearable dets destroyed before the panel
+ virtual void onDestroyed(LLWearable const *) { mWearablePtr = NULL; }
+ //
+
public:
LLPanelEditWearable( );
virtual ~LLPanelEditWearable();