diff --git a/indra/newview/llnotificationhandler.h b/indra/newview/llnotificationhandler.h
index d2b10557a2..bc600e4b03 100644
--- a/indra/newview/llnotificationhandler.h
+++ b/indra/newview/llnotificationhandler.h
@@ -81,6 +81,7 @@ typedef enum e_notification_type
// - signal, that emits ID of the notification that is being processed
//
class LLEventHandler
+ : public LLScreenChannelBase::LLScreenChannelObserver // derive from observer, so we get notified when the Channel we hold dies.
{
public:
virtual ~LLEventHandler() {};
@@ -110,6 +111,10 @@ protected:
LLScreenChannelBase* mChannel;
e_notification_type mType;
+ // Channel is dead, remove it. Yay for mChannel being protected so every derived class just mucks with the pointer as it wishes. Otherwise we could register an observer as soon as mChannel is set.
+ virtual void observeDestruction( LLScreenChannelBase *)
+ { mChannel = 0; }
+ //
};
// LLSysHandler and LLChatHandler are more specific base classes
@@ -256,6 +261,7 @@ protected:
* Handler for offers notices.
* It manages life time of offer notices.
*/
+
class LLOfferHandler : public LLSysHandler
{
public:
@@ -265,6 +271,7 @@ public:
// base interface functions
virtual bool processNotification(const LLSD& notify);
+
protected:
virtual void onDeleteToast(LLToast* toast);
virtual void initChannel();
diff --git a/indra/newview/llnotificationofferhandler.cpp b/indra/newview/llnotificationofferhandler.cpp
index 59c6abe825..de46246963 100644
--- a/indra/newview/llnotificationofferhandler.cpp
+++ b/indra/newview/llnotificationofferhandler.cpp
@@ -51,11 +51,20 @@ LLOfferHandler::LLOfferHandler(e_notification_type type, const LLSD& id)
LLScreenChannel* channel = dynamic_cast(mChannel);
if(channel)
channel->setOnRejectToastCallback(boost::bind(&LLOfferHandler::onRejectToast, this, _1));
+
+ // Register with observer so we notice when mChannel diees
+ if( mChannel )
+ mChannel->setObserver( this );
+ //
}
//--------------------------------------------------------------------------
LLOfferHandler::~LLOfferHandler()
{
+ // Where are dead. In case we still hold a channel unregister
+ if( mChannel )
+ mChannel->setObserver( 0 );
+ //
}
//--------------------------------------------------------------------------
diff --git a/indra/newview/llscreenchannel.cpp b/indra/newview/llscreenchannel.cpp
index 8d59aeb3f5..02e62dce55 100644
--- a/indra/newview/llscreenchannel.cpp
+++ b/indra/newview/llscreenchannel.cpp
@@ -125,6 +125,16 @@ LLScreenChannelBase::LLScreenChannelBase(const Params& p)
setMouseOpaque( false );
setVisible(FALSE);
+
+ mObserver = 0; // Observerable
+}
+
+LLScreenChannelBase::~LLScreenChannelBase()
+{
+ // Notofiy our observer that we're going down
+ if( mObserver )
+ mObserver->observeDestruction( this );
+ //
}
BOOL LLScreenChannelBase::postBuild()
@@ -233,7 +243,6 @@ void LLScreenChannel::init(S32 channel_left, S32 channel_right)
//--------------------------------------------------------------------------
LLScreenChannel::~LLScreenChannel()
{
-
}
std::list LLScreenChannel::findToasts(const Matcher& matcher)
diff --git a/indra/newview/llscreenchannel.h b/indra/newview/llscreenchannel.h
index c9f8855fe6..3e22603b4f 100644
--- a/indra/newview/llscreenchannel.h
+++ b/indra/newview/llscreenchannel.h
@@ -52,6 +52,7 @@ typedef enum e_channel_alignment
class LLScreenChannelBase : public LLUICtrl
{
friend class LLChannelManager;
+
public:
struct Params : public LLInitParam::Block
{
@@ -69,6 +70,7 @@ public:
};
LLScreenChannelBase(const Params&);
+ virtual ~LLScreenChannelBase();
BOOL postBuild();
@@ -142,6 +144,22 @@ protected:
LLView* mFloaterSnapRegion;
LLView* mChicletRegion;
+
+ // Oberserver for ScreenChannelBase destruction
+public:
+ class LLScreenChannelObserver
+ {
+ public:
+ virtual ~LLScreenChannelObserver() {}
+ virtual void observeDestruction( LLScreenChannelBase *) = 0;
+ };
+
+ void setObserver( LLScreenChannelObserver *aObserver )
+ { mObserver = aObserver; }
+
+private:
+ LLScreenChannelObserver *mObserver;
+ //
};
@@ -151,6 +169,7 @@ protected:
class LLScreenChannel : public LLScreenChannelBase
{
friend class LLChannelManager;
+
public:
LLScreenChannel(const Params&);
virtual ~LLScreenChannel();