Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Crash and test failure during test_font_styles on win-amd64-py2.7 #933

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 8, 2012

Conversation

mdboom
Copy link
Member

@mdboom mdboom commented Jun 8, 2012

This issue was first reported on the matplotlib-devel mailing list at http://www.mail-archive.com/[email protected]/msg09076.html.

The latest github v1.1.x (and probably also the master) branch segfaults during the matplotlib.tests.test_text.test_font_styles.test on win-amd64-py2.7 when using the PDF backend:

Python 2.7.3 (default, Apr 10 2012, 23:24:47) [MSC v.1500 64 bit 
(AMD64)] on win32
>>> import matplotlib as mpl
>>> mpl.use("agg")
>>> mpl.test(verbosity=2)
<snip>
matplotlib.tests.test_mathtext.mathtext_stixsans_65_test.test ... ok
matplotlib.tests.test_mathtext.mathtext_stixsans_65_test.test ... ok
matplotlib.tests.test_mathtext.mathtext_stixsans_65_test.test ... 
KNOWNFAIL: Cannot compare svg files on this system
matplotlib.tests.test_mathtext.test_fontinfo ... ok
matplotlib.tests.test_text.test_antialiasing.test ... ok
matplotlib.tests.test_text.test_font_styles.test ... ok
matplotlib.tests.test_text.test_font_styles.test ... <crash>

The crash is in line 229 of ttconv/pprdrv_tt2.cpp during a back() call on an empty std::list. https://github.com/matplotlib/matplotlib/blob/v1.1.x/ttconv/pprdrv_tt2.cpp#L229

On win32-py2.7 the test fails but doesn't crash. The failure is that bold font styles are not rendered bold:

Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)] on win32
<snip>
======================================================================
FAIL: matplotlib.tests.test_text.test_font_styles.test
----------------------------------------------------------------------
Traceback (most recent call last):
  File "X:\Python27\lib\site-packages\nose\case.py", line 197, in runTest
    self.test(*self.arg)
  File "X:\Python27\lib\site-packages\matplotlib\testing\decorators.py", line 36, in failer
    result = f(*args, **kwargs)
  File "X:\Python27\lib\site-packages\matplotlib\testing\decorators.py", line 140, in do_test
    '(RMS %(rms).3f)'%err)
ImageComparisonFailure: images not close: test\result_images\test_text\font_styles.png vs.
 test\result_images\test_text\expected-font_styles.png (RMS 47.138)

======================================================================
FAIL: matplotlib.tests.test_text.test_font_styles.test
----------------------------------------------------------------------
Traceback (most recent call last):
  File "X:\Python27\lib\site-packages\nose\case.py", line 197, in runTest
    self.test(*self.arg)
  File "X:\Python27\lib\site-packages\matplotlib\testing\decorators.py", line 36, in failer
    result = f(*args, **kwargs)
  File "X:\Python27\lib\site-packages\matplotlib\testing\decorators.py", line 140, in do_test
    '(RMS %(rms).3f)'%err)
ImageComparisonFailure: images not close: test\result_images\test_text\font_styles_pdf.png vs.
 test\result_images\test_text\expected-font_styles_pdf.png (RMS 23.409)

----------------------------------------------------------------------
Ran 1068 tests in 231.978s

FAILED (KNOWNFAIL=268, failures=2) 

PR #905 is probably related.

@cgohlke
Copy link
Contributor Author

cgohlke commented Jun 7, 2012

The most significant part of the call stack from the debugger:

    msvcr90.dll!__crt_debugger_hook(int _Reserved=2162504)  Line 65 C
    msvcr90.dll!_invoke_watson(const wchar_t * pszExpression=0x0000000000000002, const wchar_t * pszFunction=0x000000001880919b, const wchar_t * pszFile=0x0000000000000001, unsigned int nLine=2002137114, unsigned __int64 pReserved=0)  Line 233 C++
    msvcr90.dll!_invalid_parameter(const wchar_t * pszExpression=0x000000001429f820, const wchar_t * pszFunction=0x0000000000000001, const wchar_t * pszFile=0x0000000035001c50, unsigned int nLine=0, unsigned __int64 pReserved=0)  Line 115  C++
    msvcr90.dll!_invalid_parameter_noinfo()  Line 126   C++
>   ttconv.pyd!GlyphToType3::PSConvert(TTStreamWriter & stream={...})  Line 229 + 0x34 bytes    C++
    ttconv.pyd!GlyphToType3::GlyphToType3(TTStreamWriter & stream={...}, TTFONT * font=0x0000000000210ba8, int charindex=0, bool embedded=false)  Line 840 + 0xb bytes  C++
    ttconv.pyd!tt_type3_charproc(TTStreamWriter & stream={...}, TTFONT * font=0x0000000000000001, int charindex=890305360)  Line 861    C++
    ttconv.pyd!get_pdf_charprocs(const char * filename=0x0000000000000000, std::vector<int,std::allocator<int> > & glyph_ids=[25708120](...,...), TTDictionaryCallback & dict={...})  Line 1389 C++
    ttconv.pyd!py_get_pdf_charprocs(_object * self=0x00000000339847c8, _object * args=0x0000000000000000, _object * kwds=0x0000000094fd6ab0)  Line 214 + 0x14 bytes C++
    python27.dll!PyCFunction_Call(_object * func=0x0000000000000002, _object * arg=0x0000000001ee7a80, _object * kw=0x0000000005d8f108)  Line 85 + 0x8 bytes    C
    python27.dll!call_function(_object * * * pp_stack=0x0000000000000000, int oparg=131)  Line 4021 + 0xaf bytes    C

@mdboom
Copy link
Member

mdboom commented Jun 7, 2012

This is a shot in the dark, since I can't detect anything wrong on Linux, but does the following resolve the issue?

--- a/ttconv/pprdrv_tt2.cpp
+++ b/ttconv/pprdrv_tt2.cpp
@@ -214,6 +214,10 @@ void GlyphToType3::PSConvert(TTStreamWriter& stream)
         // on-path point midway between them.
         std::list<FlaggedPoint> points;

+        if (epts_ctr[k] == 0) {
+            continue;
+        }
+
         // Represent flags and x/y coordinates as a C++ list
         for (; j <= epts_ctr[k]; j++)
         {

@cgohlke
Copy link
Contributor Author

cgohlke commented Jun 8, 2012

That will likely not work because it will create an endless loop.
But this seems to work (all tests pass on win-amd64):

diff --git a/ttconv/pprdrv_tt2.cpp b/ttconv/pprdrv_tt2.cpp
index 1302382..6d309c4 100644
--- a/ttconv/pprdrv_tt2.cpp
+++ b/ttconv/pprdrv_tt2.cpp
@@ -226,6 +226,21 @@ void GlyphToType3::PSConvert(TTStreamWriter& stream)

         // For any two consecutive off-path points, insert the implied
         // on-path point.
+
+        if (points.size() == 0) {
+            k=nextinctr(i,k);
+
+            if (k==NOMOREINCTR)
+            {
+                i=k=nextoutctr(i);
+            }
+
+            if (i==NOMOREOUTCTR)
+            {
+                break;
+            }
+            continue;
+        }
         FlaggedPoint prev = points.back();
         for (std::list<FlaggedPoint>::iterator it = points.begin();
              it != points.end();

@mdboom
Copy link
Member

mdboom commented Jun 8, 2012

I've included your solution as a PR here. Tested on Linux and seems to work fine.

Does this also resolve the second part of the issue -- that bold fonts aren't bold?

@cgohlke
Copy link
Contributor Author

cgohlke commented Jun 8, 2012

Yes, all tests pass on win-amd64 and win32. The bold font problem disappeared after deleting the font cache.

@mdboom
Copy link
Member

mdboom commented Jun 8, 2012

Ok. Great. Merging.

mdboom added a commit that referenced this pull request Jun 8, 2012
Crash and test failure during test_font_styles on win-amd64-py2.7
@mdboom mdboom merged commit 3c6a107 into matplotlib:v1.1.x Jun 8, 2012
@jkseppan jkseppan mentioned this pull request Jun 9, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants