Ticket #4116: 4116-v1.patch

File 4116-v1.patch, 8.7 KB (added by danielk, 16 years ago)

fix for OSDTypeText memory corruption

  • libs/libmythtv/osdtypes.cpp

     
    660660
    661661OSDTypeText::OSDTypeText(const QString &name, TTFFont *font,
    662662                         const QString &text, QRect displayrect,
    663                          float wmult, float hmult)
    664            : OSDType(name)
    665 {
    666     m_message = text;
    667     m_default_msg = text;
    668     m_font = font;
     663                         float wmult, float hmult) :
     664    OSDType(name),
     665    m_lock(true),
     666    m_displaysize(displayrect),
     667    m_screensize(displayrect),
     668    m_unbiasedsize(unbias(m_screensize, wmult, hmult)),
     669    m_message(QDeepCopy<QString>(text)),
     670    m_default_msg(QDeepCopy<QString>(text)),
    669671
    670     m_altfont = NULL;
    671    
    672     m_displaysize = displayrect;
    673     m_screensize = displayrect;
    674     m_multiline = false;
    675     m_centered = false;
    676     m_right = false;
    677     m_usingalt = false;
     672    m_font(font),
     673    m_altfont(NULL),
    678674
    679     m_selected  = false;
    680     m_button    = false;
    681     m_entrynum  = -1;
    682     m_cursorpos = 0;
     675    m_centered(false),
     676    m_right(false),
    683677
    684     m_scroller = false;
    685     m_scrollx = m_scrolly = 0;
    686     m_scrollinit = false;
     678    m_multiline(false),
     679    m_usingalt(false),
    687680
    688     m_linespacing = 1.5;
     681    m_selected(false),
     682    m_button(false),
     683    m_entrynum(-1),
     684    m_cursorpos(0),
    689685
    690     m_unbiasedsize = unbias(m_screensize, wmult, hmult);
     686    m_scroller(false),
     687    m_scrollx(0),
     688    m_scrolly(0),
    691689
    692     m_draw_info_str = "";
    693     m_draw_info_len = 0;
     690    m_scrollinit(false),
     691
     692    m_linespacing(1.5f),
     693
     694    m_draw_info_str(""),
     695    m_draw_info_len(0)
     696{
    694697}
    695698
    696 OSDTypeText::OSDTypeText(const OSDTypeText &other)
    697            : OSDType(other.m_name)
     699OSDTypeText::OSDTypeText(const OSDTypeText &other) :
     700    OSDType(other.m_name),
     701    m_draw_info_str(""),
     702    m_draw_info_len(0)
    698703{
    699     m_message = other.m_message;
    700     m_default_msg = other.m_default_msg;
     704    QMutexLocker locker(&other.m_lock);
     705
     706    m_displaysize = other.m_displaysize;
     707    m_screensize = other.m_screensize;
     708    m_unbiasedsize = other.m_unbiasedsize;
     709
     710    m_message = QDeepCopy<QString>(other.m_message);
     711    m_default_msg = QDeepCopy<QString>(other.m_default_msg);
     712
    701713    m_font = other.m_font;
    702 
    703714    m_altfont = other.m_altfont;
    704715
    705     m_displaysize = other.m_displaysize;
    706     m_screensize = other.m_screensize;
    707     m_multiline = other.m_multiline;
    708716    m_centered = other.m_centered;
    709717    m_right = other.m_right;
    710     m_usingalt = other.m_usingalt;
    711    
    712     m_selected = other.m_selected;
    713     m_button   = other.m_button;
    714     m_entrynum = other.m_entrynum;
    715     m_cursorpos = other.m_cursorpos;
    716  
     718
     719    m_multiline = other.m_multiline;
     720    m_usingalt = other.m_usingalt;
     721
     722    m_selected = other.m_selected;
     723    m_button   = other.m_button;
     724    m_entrynum = other.m_entrynum;
     725    m_cursorpos = other.m_cursorpos;
     726
    717727    m_scroller = other.m_scroller;
    718728    m_scrollx = other.m_scrollx;
    719729    m_scrolly = other.m_scrolly;
     730
    720731    m_scrollinit = other.m_scrollinit;
    721732
    722733    m_linespacing = other.m_linespacing;
    723 
    724     m_unbiasedsize = other.m_unbiasedsize;
    725 
    726     m_draw_info_str = "";
    727     m_draw_info_len = 0;
    728734}
    729735
    730736OSDTypeText::~OSDTypeText()
     
    733739
    734740void OSDTypeText::SetAltFont(TTFFont *font)
    735741{
     742    QMutexLocker locker(&m_lock);
    736743    m_altfont = font;
    737744}
    738745
     
    777784        }
    778785    }
    779786
    780     m_message = rtl_string_composer.join("");
    781 
     787    QMutexLocker locker(&m_lock);
     788    m_message = QDeepCopy<QString>(rtl_string_composer.join(""));
    782789    m_cursorpos = text.length();
    783790    m_scrollinit = false;
    784791}
    785792
     793QString OSDTypeText::GetText(void) const
     794{
     795    QMutexLocker locker(&m_lock);
     796    return QDeepCopy<QString>(m_message);
     797}
     798
    786799void OSDTypeText::SetDefaultText(const QString &text)
    787800{
    788     m_message = text;
    789     m_default_msg = text;
    790     m_scrollinit = false;
     801    QMutexLocker locker(&m_lock);
     802    m_message     = QDeepCopy<QString>(text);
     803    m_default_msg = QDeepCopy<QString>(text);
     804    m_scrollinit  = false;
    791805}
    792806
     807QString OSDTypeText::GetDefaultText(void) const
     808{
     809    QMutexLocker locker(&m_lock);
     810    return QDeepCopy<QString>(m_default_msg);
     811}
     812
     813void OSDTypeText::SetMultiLine(bool multi)
     814{
     815    QMutexLocker locker(&m_lock);
     816    m_multiline = multi;
     817}
     818
     819void OSDTypeText::SetCentered(bool docenter)
     820{
     821    QMutexLocker locker(&m_lock);
     822    m_centered = docenter;
     823}
     824
     825void OSDTypeText::SetRightJustified(bool right)
     826{
     827    QMutexLocker locker(&m_lock);
     828    m_right = right;
     829}
     830
     831void OSDTypeText::SetScrolling(int x, int y)
     832{
     833    QMutexLocker locker(&m_lock);
     834    m_scroller = true;
     835    m_scrollx = x;
     836    m_scrolly = y;
     837}
     838
     839void OSDTypeText::SetLineSpacing(float linespacing)
     840{
     841    QMutexLocker locker(&m_lock);
     842    m_linespacing = linespacing;
     843}
     844
    793845void OSDTypeText::Reinit(float wmult, float hmult)
    794846{
     847    QMutexLocker locker(&m_lock);
    795848    m_displaysize = m_screensize = bias(m_unbiasedsize, wmult, hmult);
    796849}
    797850
    798851void OSDTypeText::Draw(OSDSurface *surface, int fade, int maxfade, int xoff,
    799852                       int yoff)
    800853{
     854    QMutexLocker locker(&m_lock);
     855
     856    // initialize regular expressions once, this is a very slow operation
     857    static QMutex regexp_lock;
     858    static QRegExp br("%BR%");
     859    static QRegExp nl("\n");
     860
    801861    int textlength = 0;
    802862
    803863    if (m_message == QString::null)
     
    815875
    816876    if (m_multiline)
    817877    {
    818         QString tmp_msg = m_message;
    819         tmp_msg.replace(QRegExp("%BR%"), "\n");
    820         tmp_msg.replace(QRegExp("\n")," \n ");
     878        QString tmp_msg = QDeepCopy<QString>(m_message);
     879        regexp_lock.lock();
     880        tmp_msg.replace(br, "\n");
     881        tmp_msg.replace(nl," \n ");
     882        regexp_lock.unlock();
    821883
    822884        QStringList wordlist = QStringList::split(" ", tmp_msg);
    823885        int length = 0;
     
    9441006                                   const QString &text, int fade, int maxfade,
    9451007                                   int xoff, int yoff, bool double_size)
    9461008{
     1009    QMutexLocker locker(&m_lock);
     1010
    9471011    if (m_draw_info_str != text)
    9481012    {
    9491013        m_draw_info_str = QDeepCopy<QString>(text);
     
    10571121                             const QString &text, int fade, int maxfade,
    10581122                             int xoff, int yoff, bool doubl)
    10591123{
     1124    QMutexLocker locker(&m_lock);
     1125
    10601126    if (m_centered || m_right)
    10611127    {
    10621128        int textlength = 0;
     
    11091175
    11101176bool OSDTypeText::MoveCursor(int dir)
    11111177{
     1178    QMutexLocker locker(&m_lock);
     1179
    11121180    if (!IsEntry() || IsButton())
    11131181        return false;
    11141182
     
    11191187
    11201188bool OSDTypeText::Delete(int dir)
    11211189{
     1190    QMutexLocker locker(&m_lock);
     1191
    11221192    if (!IsEntry() || IsButton())
    11231193        return false;
    11241194
     
    11411211
    11421212void OSDTypeText::InsertCharacter(QChar ch)
    11431213{
     1214    QMutexLocker locker(&m_lock);
     1215
    11441216    if (!IsEntry() || IsButton())
    11451217        return;
    11461218
  • libs/libmythtv/osdtypes.h

     
    202202    void SetUseAlt(bool usealt) { m_usingalt = usealt; }
    203203
    204204    void SetText(const QString &text);
    205     QString GetText() { return m_message; }
     205    QString GetText(void) const;
    206206
    207207    void SetDefaultText(const QString &text);
    208     QString GetDefaultText() { return m_default_msg; }
     208    QString GetDefaultText(void) const;
    209209
    210     void SetMultiLine(bool multi) { m_multiline = multi; }
    211     bool GetMultiLine() { return m_multiline; }
     210    void SetMultiLine(bool multi);
     211    bool GetMultiLine(void) const { return m_multiline; }
    212212
    213     void SetCentered(bool docenter) { m_centered = docenter; }
    214     bool GetCentered() { return m_centered; }
     213    void SetCentered(bool docenter);
     214    bool GetCentered(void) const { return m_centered; }
    215215
    216     void SetRightJustified(bool right) { m_right = right; }
    217     bool GetRightJustified() { return m_right; }
     216    void SetRightJustified(bool right);
     217    bool GetRightJustified(void) const { return m_right; }
    218218
    219     void SetScrolling(int x, int y) { m_scroller = true; m_scrollx = x;
    220                                       m_scrolly = y; }
     219    void SetScrolling(int x, int y);
    221220
    222     void SetLineSpacing(float linespacing) { m_linespacing = linespacing; }
    223     float GetLineSpacing() { return m_linespacing; }
     221    void SetLineSpacing(float linespacing);
     222    float GetLineSpacing(void) const { return m_linespacing; }
    224223
    225224    void Draw(OSDSurface *surface, int fade, int maxfade, int xoff, int yoff);
    226225    bool MoveCursor(int dir);
     
    245244                          const QString &text, int fade, int maxfade,
    246245                          int xoff, int yoff, bool double_size = false);
    247246
     247    mutable QMutex m_lock;
     248
    248249    QRect m_displaysize;
    249250    QRect m_screensize;
    250251    QRect m_unbiasedsize;