Skip to content

Commit 377d9a9

Browse files
committed
#3140 Crash trying to clone LLInlineViewSegment
LLInlineViewSegment does not support cloning, affects #2559
1 parent b944975 commit 377d9a9

File tree

2 files changed

+25
-10
lines changed

2 files changed

+25
-10
lines changed

indra/llui/lltextbase.cpp

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -923,19 +923,30 @@ S32 LLTextBase::insertStringNoUndo(S32 pos, const LLWString &wstr, LLTextBase::s
923923
S32 new_seg_start = pos + (S32)i;
924924
segment_set_t::iterator cur_seg_iter = getSegIterContaining(new_seg_start);
925925
LLStyleSP new_style;
926+
std::string tooltip;
926927
if (cur_seg_iter != mSegments.end()) // Should be 100%
927928
{
928-
// Use font EmojiLarge but preserve the target font style
929+
// Use font EmojiLarge but preserve the target font style and tooltip if present
929930
new_style = (*cur_seg_iter)->getStyle()->clone();
930931
U8 font_style = new_style->getFont()->getFontDesc().getStyle();
931932
new_style->setFont(LLFontGL::getFont(LLFontDescriptor("Emoji", "Large", font_style)));
933+
if (!(*cur_seg_iter)->getToken())
934+
{
935+
tooltip = (*cur_seg_iter)->getToolTip();
936+
}
932937
}
933938
else // Very unlikely
934939
{
935940
new_style = new LLStyle(getStyleParams());
936941
new_style->setFont(LLFontGL::getFontEmojiLarge());
937942
}
938-
insertSegment(new LLEmojiTextSegment(new_style, new_seg_start, new_seg_start + 1, *this));
943+
LLTextSegmentPtr new_seg = new LLEmojiTextSegment(new_style, new_seg_start, new_seg_start + 1, *this);
944+
945+
if (!tooltip.empty())
946+
{
947+
new_seg->setToolTip(tooltip);
948+
}
949+
insertSegment(new_seg);
939950
}
940951
}
941952
}
@@ -1066,18 +1077,19 @@ void LLTextBase::insertSegment(LLTextSegmentPtr segment_to_insert)
10661077
S32 old_segment_end = cur_segmentp->getEnd();
10671078
// split old at start point for new segment
10681079
cur_segmentp->setEnd(segment_to_insert->getStart());
1069-
// insert new segment before remainder of old segment
1070-
mSegments.insert(cur_seg_iter, segment_to_insert);
10711080
// advance to next segment
10721081
// insert remainder of old segment
1073-
if (segment_to_insert->getEnd() < old_segment_end)
1082+
LLStyleConstSP sp = cur_segmentp->getStyle();
1083+
LLTextSegmentPtr remainder_segment = new LLNormalTextSegment(sp, segment_to_insert->getStart(), old_segment_end, *this);
1084+
mSegments.insert(cur_seg_iter, remainder_segment);
1085+
std::string tooltip = segment_to_insert->getToolTip();
1086+
if (!tooltip.empty())
10741087
{
1075-
LLTextSegmentPtr remainder_segment = cur_segmentp->clone(*this);
1076-
remainder_segment->setStart(segment_to_insert->getEnd());
1077-
remainder_segment->setEnd(old_segment_end);
1078-
mSegments.insert(cur_seg_iter, remainder_segment);
1079-
remainder_segment->linkToDocument(this);
1088+
remainder_segment->setToolTip(tooltip);
10801089
}
1090+
remainder_segment->linkToDocument(this);
1091+
// insert new segment before remainder of old segment
1092+
mSegments.insert(cur_seg_iter, segment_to_insert);
10811093

10821094
segment_to_insert->linkToDocument(this);
10831095
// at this point, there will be two overlapping segments owning the text
@@ -3310,6 +3322,7 @@ void LLTextSegment::setStyle(LLStyleConstSP style) {}
33103322
void LLTextSegment::setToken( LLKeywordToken* token ) {}
33113323
LLKeywordToken* LLTextSegment::getToken() const { return NULL; }
33123324
void LLTextSegment::setToolTip( const std::string &msg ) {}
3325+
std::string LLTextSegment::getToolTip() const { return std::string(); }
33133326
void LLTextSegment::dump() const {}
33143327
bool LLTextSegment::handleMouseDown(S32 x, S32 y, MASK mask) { return false; }
33153328
bool LLTextSegment::handleMouseUp(S32 x, S32 y, MASK mask) { return false; }

indra/llui/lltextbase.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ class LLTextSegment
9696
virtual void setToken( LLKeywordToken* token );
9797
virtual LLKeywordToken* getToken() const;
9898
virtual void setToolTip(const std::string& tooltip);
99+
virtual std::string getToolTip() const;
99100
virtual void dump() const;
100101

101102
// LLMouseHandler interface
@@ -147,6 +148,7 @@ class LLNormalTextSegment : public LLTextSegment
147148
/*virtual*/ void setToken( LLKeywordToken* token ) { mToken = token; }
148149
/*virtual*/ LLKeywordToken* getToken() const { return mToken; }
149150
/*virtual*/ void setToolTip(const std::string& tooltip);
151+
/*virtual*/ std::string getToolTip() const { return mTooltip; }
150152
/*virtual*/ void dump() const;
151153

152154
/*virtual*/ bool handleHover(S32 x, S32 y, MASK mask);

0 commit comments

Comments
 (0)