From: Vadim Zeitlin Date: Wed, 17 Oct 2012 23:06:07 +0000 (+0000) Subject: Fix crash in wxDC::GetMultiLineTextExtent() after last commit. X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/bb996f289574defb0ae4339ae8e46ff3cf6fa54c Fix crash in wxDC::GetMultiLineTextExtent() after last commit. Don't call wxTextMeasure::DoGetTextExtent() with NULL width pointer, it now supposes that both width and height pointers are non-NULL. Add at least a trivial unit test for GetMultiLineTextExtent(). git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@72700 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/src/common/textmeasurecmn.cpp b/src/common/textmeasurecmn.cpp index bb16ac048a..cc8f7489be 100644 --- a/src/common/textmeasurecmn.cpp +++ b/src/common/textmeasurecmn.cpp @@ -101,7 +101,8 @@ void wxTextMeasureBase::GetMultiLineTextExtent(const wxString& text, if ( !heightLineDefault ) { // but we don't know it yet - choose something reasonable - DoGetTextExtent(wxS("W"), NULL, &heightLineDefault); + int dummy; + DoGetTextExtent(wxS("W"), &dummy, &heightLineDefault); } heightTextTotal += heightLineDefault; diff --git a/tests/graphics/measuring.cpp b/tests/graphics/measuring.cpp index dbf032bee0..a45d45032d 100644 --- a/tests/graphics/measuring.cpp +++ b/tests/graphics/measuring.cpp @@ -95,6 +95,13 @@ void MeasuringTextTestCase::DCGetTextExtent() wxClientDC dc(wxTheApp->GetTopWindow()); DoTestGetTextExtent(dc); + + int w; + dc.GetMultiLineTextExtent("Good\nbye", &w, NULL); + const wxSize sz = dc.GetTextExtent("Good"); + CPPUNIT_ASSERT_EQUAL( sz.x, w ); + + CPPUNIT_ASSERT( dc.GetMultiLineTextExtent("Good\nbye").y >= 2*sz.y ); } void MeasuringTextTestCase::WindowGetTextExtent()