From 2695f29be0db63ff92e377ee9ed2dcc1e74344da Mon Sep 17 00:00:00 2001 From: Calum Robinson Date: Tue, 13 Apr 2021 13:25:12 +0100 Subject: [PATCH] Fix bounds for empty text nodes _lineCount can be 0, so we get underflow if the alignment is one of the *_BOTTOM_BASE_LINE. --- src/osgText/TextBase.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/osgText/TextBase.cpp b/src/osgText/TextBase.cpp index a45e25b7b..3acb80c16 100644 --- a/src/osgText/TextBase.cpp +++ b/src/osgText/TextBase.cpp @@ -484,6 +484,14 @@ void TextBase::computePositions() void TextBase::computePositionsImplementation() { + _normal = osg::Vec3(0.0f,0.0f,1.0f); + + if (_text.empty()) + { + _offset = Vec3(); + return; + } + switch(_alignment) { case LEFT_TOP: _offset.set(_textBB.xMin(),_textBB.yMax(),_textBB.zMin()); break; @@ -506,8 +514,6 @@ void TextBase::computePositionsImplementation() case CENTER_BOTTOM_BASE_LINE: _offset.set((_textBB.xMax()+_textBB.xMin())*0.5f,-_characterHeight*(1.0 + _lineSpacing)*(_lineCount-1),0.0f); break; case RIGHT_BOTTOM_BASE_LINE: _offset.set(_textBB.xMax(),-_characterHeight*(1.0 + _lineSpacing)*(_lineCount-1),0.0f); break; } - - _normal = osg::Vec3(0.0f,0.0f,1.0f); } bool TextBase::computeMatrix(osg::Matrix& matrix, osg::State* state) const