Add the protected code and fix the crash issue 35/162535/8
authorSeoyeon Kim <seoyeon2.kim@samsung.com>
Mon, 4 Dec 2017 05:59:08 +0000 (14:59 +0900)
committerSeoyeon Kim <seoyeon2.kim@samsung.com>
Wed, 6 Dec 2017 02:54:36 +0000 (11:54 +0900)
- When visualModel->mLines.Begin() is NULL, then do nothing in GetCursorPosition().
- When the user tries to input some texts in TextField, and its size is fitted
  to its parent, which size is (0,0) by Relayout, then set mTextUpdateInfo.mNumberOfCharactersToAdd
  as the current text for UpdateModel().

Change-Id: Iea0a251ba2061389bf7a00476bf126d9669da50c
Signed-off-by: Seoyeon Kim <seoyeon2.kim@samsung.com>
dali-toolkit/internal/text/cursor-helper-functions.cpp
dali-toolkit/internal/text/text-controller.cpp

index 91b6a40..f437b8d 100644 (file)
@@ -467,6 +467,13 @@ CharacterIndex GetClosestCursorIndex( VisualModelPtr visualModel,
 void GetCursorPosition( GetCursorPositionParameters& parameters,
                         CursorInfo& cursorInfo )
 {
+  const LineRun* const modelLines = parameters.visualModel->mLines.Begin();
+  if( NULL == modelLines )
+  {
+    // Nothing to do.
+    return;
+  }
+
   // Whether the logical cursor position is at the end of the whole text.
   const bool isLastPosition = parameters.logicalModel->mText.Count() == parameters.logical;
 
@@ -476,8 +483,6 @@ void GetCursorPosition( GetCursorPositionParameters& parameters,
   // Whether the cursor is in the last position and the last position is a new paragraph character.
   const bool isLastNewParagraph = parameters.isMultiline && isLastPosition && TextAbstraction::IsNewParagraph( *( parameters.logicalModel->mText.Begin() + characterOfLine ) );
 
-  const LineRun* const modelLines = parameters.visualModel->mLines.Begin();
-
   const LineIndex lineIndex = parameters.visualModel->GetLineOfCharacter( characterOfLine );
   const LineRun& line = *( modelLines + lineIndex );
 
@@ -665,7 +670,6 @@ void GetCursorPosition( GetCursorPositionParameters& parameters,
     // Set the primary cursor's height.
     cursorInfo.primaryCursorHeight = cursorInfo.isSecondaryCursor ? 0.5f * glyphMetrics.fontHeight : glyphMetrics.fontHeight;
 
-
     cursorInfo.glyphOffset = line.ascender - glyphMetrics.ascender;
     // Set the primary cursor's position.
     cursorInfo.primaryPosition.x = -glyphMetrics.xBearing + primaryPosition.x + glyphAdvance;
index 1c15e22..15e7b8b 100755 (executable)
@@ -2146,6 +2146,13 @@ Controller::UpdateTextType Controller::Relayout( const Size& size )
   {
     DALI_LOG_INFO( gLogFilter, Debug::Verbose, "new size (previous size %f,%f)\n", mImpl->mModel->mVisualModel->mControlSize.width, mImpl->mModel->mVisualModel->mControlSize.height );
 
+    if( ( 0 == mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd ) &&
+        ( 0 == mImpl->mTextUpdateInfo.mPreviousNumberOfCharacters ) &&
+        ( ( mImpl->mModel->mVisualModel->mControlSize.width < Math::MACHINE_EPSILON_1000 ) || ( mImpl->mModel->mVisualModel->mControlSize.height < Math::MACHINE_EPSILON_1000 ) ) )
+    {
+      mImpl->mTextUpdateInfo.mNumberOfCharactersToAdd = mImpl->mModel->mLogicalModel->mText.Count();
+    }
+
     // Layout operations that need to be done if the size changes.
     mImpl->mOperationsPending = static_cast<OperationsMask>( mImpl->mOperationsPending |
                                                              LAYOUT                    |