From: sarajammal Date: Wed, 17 Aug 2022 11:59:06 +0000 (+0300) Subject: Fix nullptr for the text geometry. X-Git-Tag: dali_2.1.37~5^2 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=commitdiff_plain;h=9d379104c45c7979f7dcd1ef2f9df84e8cc902c1 Fix nullptr for the text geometry. Added if statement for handling the null values of glyph and characters. That happens when the function GetTextGeometry is called before lay-outing. Change-Id: I5faa96349c7da69d261902e1b6c14cfbacdaa159 --- diff --git a/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp b/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp index b95f6c7..fac21a0 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp @@ -5124,6 +5124,44 @@ int utcDaliTextEditorGeometryOneGlyph(void) END_TEST; } +int utcDaliTextEditorGeometryNullPtr(void) +{ + ToolkitTestApplication application; + tet_infoline("utcDaliTextEditorGeometryNullPtr"); + + TextEditor editor = TextEditor::New(); + DALI_TEST_CHECK(editor); + + application.GetScene().Add(editor); + + editor.SetProperty(TextEditor::Property::POINT_SIZE, 7.f); + editor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f)); + editor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT); + editor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT); + editor.SetProperty(TextEditor::Property::ENABLE_MARKUP, true); + editor.SetProperty(TextEditor::Property::TEXT, ""); + + // Avoid a crash when core load gl resources. + application.GetGlAbstraction().SetCheckFramebufferStatusResult(GL_FRAMEBUFFER_COMPLETE); + + unsigned int expectedCount = 0; + unsigned int startIndex = 0; + unsigned int endIndex = 0; + + Vector positionsList = DevelTextEditor::GetTextPosition(editor, startIndex, endIndex); + Vector sizeList = DevelTextEditor::GetTextSize(editor, startIndex, endIndex); + + // Render and notify + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS(positionsList.Size(), expectedCount, TEST_LOCATION); + DALI_TEST_EQUALS(sizeList.Size(), expectedCount, TEST_LOCATION); + + END_TEST; +} + + int utcDaliTextEditorSelectionClearedSignal(void) { ToolkitTestApplication application; diff --git a/automated-tests/src/dali-toolkit/utc-Dali-TextField.cpp b/automated-tests/src/dali-toolkit/utc-Dali-TextField.cpp index f762e8d..df1c60b 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-TextField.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-TextField.cpp @@ -513,7 +513,7 @@ int UtcDaliToolkitTextFieldCopyConstructorP(void) TextField copy(textField); DALI_TEST_CHECK(copy); - DALI_TEST_CHECK(copy.GetProperty(TextLabel::Property::TEXT) == textField.GetProperty(TextLabel::Property::TEXT)); + DALI_TEST_CHECK(copy.GetProperty(TextField::Property::TEXT) == textField.GetProperty(TextField::Property::TEXT)); END_TEST; } @@ -4875,6 +4875,44 @@ int utcDaliTextFieldGeometryGlyphMiddle(void) END_TEST; } + +int utcDaliTextFieldGeometryNullPtr(void) +{ + ToolkitTestApplication application; + tet_infoline("utcDaliTextFieldGeometryNullPtr"); + + TextField field = TextField::New(); + DALI_TEST_CHECK(field); + + application.GetScene().Add(field); + + field.SetProperty(TextField::Property::POINT_SIZE, 7.f); + field.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f)); + field.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT); + field.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT); + field.SetProperty(TextField::Property::ENABLE_MARKUP, true); + field.SetProperty(TextField::Property::TEXT, ""); + + // Avoid a crash when core load gl resources. + application.GetGlAbstraction().SetCheckFramebufferStatusResult(GL_FRAMEBUFFER_COMPLETE); + + unsigned int expectedCount = 0; + unsigned int startIndex = 0; + unsigned int endIndex = 0; + + Vector positionsList = DevelTextField::GetTextPosition(field, startIndex, endIndex); + Vector sizeList = DevelTextField::GetTextSize(field, startIndex, endIndex); + + // Render and notify + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS(positionsList.Size(), expectedCount, TEST_LOCATION); + DALI_TEST_EQUALS(sizeList.Size(), expectedCount, TEST_LOCATION); + + END_TEST; +} + int utcDaliTextFieldSelectionClearedSignal(void) { ToolkitTestApplication application; diff --git a/automated-tests/src/dali-toolkit/utc-Dali-TextLabel.cpp b/automated-tests/src/dali-toolkit/utc-Dali-TextLabel.cpp index 0ece717..4245217 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-TextLabel.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-TextLabel.cpp @@ -2637,6 +2637,44 @@ int utcDaliTextLabelGeometryOneGlyph(void) END_TEST; } + +int utcDaliTextLabelGeometryNullPtr(void) +{ + ToolkitTestApplication application; + tet_infoline("utcDaliTextLabelGeometryNullPtr"); + + TextLabel label = TextLabel::New(); + DALI_TEST_CHECK(label); + + application.GetScene().Add(label); + + label.SetProperty(TextLabel::Property::POINT_SIZE, 7.f); + label.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f)); + label.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT); + label.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT); + label.SetProperty(TextLabel::Property::ENABLE_MARKUP, true); + label.SetProperty(TextLabel::Property::TEXT, ""); + + // Avoid a crash when core load gl resources. + application.GetGlAbstraction().SetCheckFramebufferStatusResult(GL_FRAMEBUFFER_COMPLETE); + + unsigned int expectedCount = 0; + unsigned int startIndex = 0; + unsigned int endIndex = 0; + + Vector positionsList = DevelTextLabel::GetTextPosition(label, startIndex, endIndex); + Vector sizeList = DevelTextLabel::GetTextSize(label, startIndex, endIndex); + + // Render and notify + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS(positionsList.Size(), expectedCount, TEST_LOCATION); + DALI_TEST_EQUALS(sizeList.Size(), expectedCount, TEST_LOCATION); + + END_TEST; +} + int UtcDaliToolkitTextlabelEllipsisPositionProperty(void) { ToolkitTestApplication application; diff --git a/dali-toolkit/internal/text/text-geometry.cpp b/dali-toolkit/internal/text/text-geometry.cpp index 6c90665..6f173cb 100644 --- a/dali-toolkit/internal/text/text-geometry.cpp +++ b/dali-toolkit/internal/text/text-geometry.cpp @@ -68,14 +68,29 @@ void GetTextGeometry(ModelPtr textModel, CharacterIndex startIndex, CharacterInd const CharacterIndex* const glyphToCharacterBuffer = visualModel->mGlyphsToCharacters.Begin(); const CharacterDirection* const modelCharacterDirectionsBuffer = (0u != logicalModel->mCharacterDirections.Count()) ? logicalModel->mCharacterDirections.Begin() : NULL; + //Clear the lists + sizesList.Clear(); + positionsList.Clear(); + + if(charactersToGlyphBuffer == nullptr || glyphsPerCharacterBuffer == nullptr || charactersPerGlyphBuffer == nullptr || glyphToCharacterBuffer == nullptr ) + { + return; + } + if(startIndex >= logicalModel->mText.Count() && endIndex >= logicalModel->mText.Count()) + { return; + } if(startIndex >= logicalModel->mText.Count()) + { startIndex = logicalModel->mText.Count() - 1; + } if(endIndex >= logicalModel->mText.Count()) + { endIndex = logicalModel->mText.Count() - 1; + } if(startIndex > endIndex) {