Fixed crash when Visual model positions < glyphs 78/36578/3
authorPaul Wisbey <p.wisbey@samsung.com>
Tue, 10 Mar 2015 08:25:42 +0000 (08:25 +0000)
committerPaul Wisbey <p.wisbey@samsung.com>
Tue, 10 Mar 2015 08:40:01 +0000 (08:40 +0000)
Change-Id: I61398d876cc3614d97487a5c02c0dd51201f3420

dali-toolkit/internal/text/text-view.cpp
dali-toolkit/internal/text/visual-model.cpp
dali-toolkit/internal/text/visual-model.h

index 235f534..d12c697 100644 (file)
@@ -55,7 +55,14 @@ Length View::GetNumberOfGlyphs() const
 {
   if( mImpl->mVisualModel )
   {
 {
   if( mImpl->mVisualModel )
   {
-    return mImpl->mVisualModel->GetNumberOfGlyphs();
+    VisualModel& model = *mImpl->mVisualModel;
+
+    Length glyphCount = model.GetNumberOfGlyphs();
+    Length positionCount = model.GetNumberOfGlyphPositions();
+
+    DALI_ASSERT_DEBUG( positionCount <= glyphCount && "Invalid glyph positions in Model" );
+
+    return (positionCount < glyphCount) ? positionCount : glyphCount;
   }
 
   return 0;
   }
 
   return 0;
index ab183e4..abf4f65 100644 (file)
@@ -157,6 +157,11 @@ void VisualModel::SetGlyphPositions( const Vector2* glyphPositions,
   memcpy( modelPositions.Begin(), glyphPositions, numberOfGlyphs * sizeof( Vector2 ) );
 }
 
   memcpy( modelPositions.Begin(), glyphPositions, numberOfGlyphs * sizeof( Vector2 ) );
 }
 
+Length VisualModel::GetNumberOfGlyphPositions() const
+{
+  return mImpl->mGlyphPositions.Count();
+}
+
 void VisualModel::GetGlyphPositions( Vector2* glyphPositions,
                                      GlyphIndex glyphIndex,
                                      Length numberOfGlyphs ) const
 void VisualModel::GetGlyphPositions( Vector2* glyphPositions,
                                      GlyphIndex glyphIndex,
                                      Length numberOfGlyphs ) const
index ad2a137..ac3b096 100644 (file)
@@ -178,6 +178,14 @@ public:
                           Length numberOfGlyphs );
 
   /**
                           Length numberOfGlyphs );
 
   /**
+   * Retrieves the number of glyph positions set.
+   *
+   * @note This may be less than the number of glyphs in the model.
+   * @return The number of glyphs.
+   */
+  Length GetNumberOfGlyphPositions() const;
+
+  /**
    * @brief Retrieves the glyph positions.
    *
    * @pre The size of the @p positions buffer needs to be big enough to copy the @p numberOfGlyphs positions.
    * @brief Retrieves the glyph positions.
    *
    * @pre The size of the @p positions buffer needs to be big enough to copy the @p numberOfGlyphs positions.