]> git.sesse.net Git - vlc/commitdiff
* src/ft2_font.cpp: initialize some members to avoid a segfault in the
authorCyril Deguet <asmax@videolan.org>
Sun, 7 Mar 2004 11:47:50 +0000 (11:47 +0000)
committerCyril Deguet <asmax@videolan.org>
Sun, 7 Mar 2004 11:47:50 +0000 (11:47 +0000)
    destructor when the font cannot be opened. drawString() now returns
    NULL if the initialization failed.
  * all: check if drawString() returns NULL

modules/gui/skins2/controls/ctrl_list.cpp
modules/gui/skins2/controls/ctrl_text.cpp
modules/gui/skins2/src/ft2_font.cpp
modules/gui/skins2/src/tooltip.cpp

index ea4056d7e6db893710fa6a0616bc63e51932f3f7..9603c2bb5e50d77b7929e8492a54fc6084fa7932 100644 (file)
@@ -2,7 +2,7 @@
  * ctrl_list.cpp
  *****************************************************************************
  * Copyright (C) 2003 VideoLAN
- * $Id: ctrl_list.cpp,v 1.3 2004/02/29 16:49:55 asmax Exp $
+ * $Id$
  *
  * Authors: Cyril Deguet     <asmax@via.ecp.fr>
  *          Olivier Teulière <ipkiss@via.ecp.fr>
@@ -372,6 +372,10 @@ void CtrlList::makeImage()
 
         // Draw the text
         GenericBitmap *pText = m_rFont.drawString( *pStr, color, width );
+        if( !pText )
+        {
+            return;
+        }
         yPos += itemHeight - pText->getHeight();
         int ySrc = 0;
         if( yPos < 0 )
index e7259ef7eb178ecc25516cf0bee6cc0c1c5b539c..687c9013fbc5e4265f641185154c378bb2b1d363 100755 (executable)
@@ -2,7 +2,7 @@
  * ctrl_text.cpp
  *****************************************************************************
  * Copyright (C) 2003 VideoLAN
- * $Id: ctrl_text.cpp,v 1.2 2004/02/29 16:49:55 asmax Exp $
+ * $Id$
  *
  * Authors: Cyril Deguet     <asmax@via.ecp.fr>
  *          Olivier Teulière <ipkiss@via.ecp.fr>
@@ -193,6 +193,10 @@ void CtrlText::displayText( const UString &rText )
         delete m_pImg;
     }
     m_pImg = m_rFont.drawString( rText, m_color );
+    if( !m_pImg )
+    {
+        return;
+    }
     // 'Double' image
     const UString doubleStringWithSep = rText + SEPARATOR_STRING + rText;
     if( m_pImgDouble )
@@ -212,7 +216,7 @@ void CtrlText::displayText( const UString &rText )
 
 void CtrlText::onChangePosition()
 {
-    if( getPosition() )
+    if( m_pImg && getPosition() )
     {
         if( m_pImg->getWidth() < getPosition()->getWidth() )
         {
@@ -252,7 +256,8 @@ void CtrlText::transManualMoving( SkinObject *pCtrl )
 
     // Start the automatic movement, but only if the text is wider than the
     // control
-    if( pThis->m_pImg->getWidth() >= pThis->getPosition()->getWidth() )
+    if( pThis->m_pImg && 
+        pThis->m_pImg->getWidth() >= pThis->getPosition()->getWidth() )
     {
         // The current image may have been set incorrectly in displayText(), so
         // set the correct value
@@ -276,7 +281,8 @@ void CtrlText::transMove( SkinObject *pCtrl )
     EvtMouse *pEvtMouse = (EvtMouse*)pThis->m_pEvt;
 
     // Do nothing if the text fits in the control
-    if( pThis->m_pImg->getWidth() >= pThis->getPosition()->getWidth() )
+    if( pThis->m_pImg &&
+        pThis->m_pImg->getWidth() >= pThis->getPosition()->getWidth() )
     {
         // The current image may have been set incorrectly in displayText(), so
         // we set the correct value
@@ -308,6 +314,10 @@ void CtrlText::adjust( int &position )
     // {m_pImgDouble->getWidth()  - m_pImg->getWidth()} is the period of the
     // bitmap; remember that the string used to generate m_pImgDouble is of the
     // form: "foo  foo", the number of spaces being a parameter
+    if( !m_pImg )
+    {
+        return;
+    }
     position %= m_pImgDouble->getWidth()  - m_pImg->getWidth();
     if( position > 0 )
     {
index ae8ab9ea9c373f77f837029a2d93f9bd7f1abbe3..020ea793f5c45ac24e9cbbb5a469434de460c77e 100644 (file)
@@ -2,7 +2,7 @@
  * ft2_font.cpp
  *****************************************************************************
  * Copyright (C) 2003 VideoLAN
- * $Id: ft2_font.cpp,v 1.2 2004/02/27 13:24:12 gbazin Exp $
+ * $Id$
  *
  * Authors: Cyril Deguet     <asmax@via.ecp.fr>
  *          Olivier Teulière <ipkiss@via.ecp.fr>
 
 
 FT2Font::FT2Font( intf_thread_t *pIntf, const string &rName, int size ):
-    GenericFont( pIntf ), m_name( rName ), m_buffer( NULL ), m_size( size )
+    GenericFont( pIntf ), m_name( rName ), m_buffer( NULL ), m_size( size ),
+    m_lib( NULL ), m_face( NULL ), m_dotGlyph( NULL )
 {
 }
 
 
 FT2Font::~FT2Font()
 {
-
-    FT_Done_Glyph( m_dotGlyph );
-    FT_Done_Face( m_face );
-    FT_Done_FreeType( m_lib );
+    if( m_dotGlyph )
+    {
+        FT_Done_Glyph( m_dotGlyph );
+    }
+    if( m_face )
+    {
+        FT_Done_Face( m_face );
+    }
+    if( m_lib )
+    {
+        FT_Done_FreeType( m_lib );
+    }
     if( m_buffer )
     {
         free( m_buffer );
@@ -138,6 +147,12 @@ GenericBitmap *FT2Font::drawString( const UString &rString, uint32_t color,
     int yMin = 0, yMax = 0;
     uint32_t *pString = (uint32_t*)rString.u_str();
 
+    // Check if freetype has been initialized
+    if( !m_face )
+    {
+        return NULL;
+    }
+
     // Get the length of the string
     int len = rString.length();
 
index 2d8b455585277dc2b9ce6a9cfb46ffe62b33bddf..b23571dd8831b09bd9e0cad17c76d1f512f691a8 100644 (file)
@@ -2,7 +2,7 @@
  * tooltip.cpp
  *****************************************************************************
  * Copyright (C) 2003 VideoLAN
- * $Id: tooltip.cpp,v 1.3 2004/01/25 11:44:19 asmax Exp $
+ * $Id$
  *
  * Authors: Cyril Deguet     <asmax@via.ecp.fr>
  *          Olivier Teulière <ipkiss@via.ecp.fr>
@@ -98,6 +98,10 @@ void Tooltip::makeImage( const UString &rText )
 {
     // Render the text on a bitmap
     GenericBitmap *pBmpTip = m_rFont.drawString( rText, 0 );
+    if( !pBmpTip )
+    {
+        return;
+    }
     int w = pBmpTip->getWidth() + 10;
     int h = m_rFont.getSize() + 8;