MathTextParser, maxdict ... Assertion failed!

Hello,

I did an application that uses bitmaps constructed with MathTextParser
as described in the example http://matplotlib.sourceforge.net/examples/user_interfaces/mathtext_wx.html

(I work with Windows XP, python 2.5, Matplotlib 0.98.5 and wxPython
2.8.10.1)

After making a lot of these bitmaps (from about 50 to 150…) the
program crash as described in the thread

[matplotlib-devel]
Fontcache problem on windows
.

I spent hours on this problem … and I found this :

It seems to come from the maxdict(50) instance used by the
MathTextParser as “cache” : if I replace it by a simple dict, my
program works fine … but the cache never stop to grow up !

Has anyone (among developpers ?) an idea for doing things better.

Thanks by advance

Cédrick

PS : Please, be indulgent with my English …

C�drick FAURY wrote:

Hello,

I did an application that uses bitmaps constructed with MathTextParser as described in the example http://matplotlib.sourceforge.net/examples/user_interfaces/mathtext_wx.html
(I work with Windows XP, python 2.5, Matplotlib 0.98.5 and wxPython 2.8.10.1)

After making a lot of these bitmaps (from about 50 to 150...) the program crash as described in the thread
[matplotlib-devel] Fontcache problem on windows <http://www.mail-archive.com/matplotlib-devel@lists.sourceforge.net/msg02353.html>.

I don't think these problems are related. One is a cache of math expression images, the other is a cache of fonts.

I am unable to reproduce this on Matplotlib 0.98.5.3 on Linux (don't have a Windows box handy). Can you run the attached script (which is just a modification of mathtext_wx.py to generate 60 different math expressions, and let me know if that crashes for you? If not, we need to track down the difference between what this script does and what yours does that causes the crash. Can you share a minimal script that reproduces the bug? It would also be useful to see a traceback (you may need to run your script from the commandline in Windows rather than double-clicking, in order to get the full traceback output).

Thanks,
Mike

mathtext_wx.py (3.8 KB)

···

--
Michael Droettboom
Science Software Branch
Operations and Engineering Division
Space Telescope Science Institute
Operated by AURA for NASA

Thank you for responding so quickly !!

I don't think these problems are related. One is a cache of math expression images, the other is a cache of fonts.

I know ... and i found a lot of way to reproduce the same crash...

I am unable to reproduce this on Matplotlib 0.98.5.3 on Linux (don't have a Windows box handy). Can you run the attached script (which is just a modification of mathtext_wx.py to generate 60 different math expressions, and let me know if that crashes for you?

This script does'nt work (it causes a PyAssertion error : invalid stock id)

But with this more simple attached script :
For 50 bitmaps, the crash occurs after the window is closed (with the "cross").
For 250, the crash occurs before the apparition of the window

In the Command prompt :
Assertion failed: ob_refcnt == 0, file CXX\cxx_extensions.cxx, line 1128
This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.

No more traceback ...

Cédrick

mathtext_wx.py (1.76 KB)

C�drick FAURY wrote:

Thank you for responding so quickly !!

I don't think these problems are related. One is a cache of math expression images, the other is a cache of fonts.

I know ... and i found a lot of way to reproduce the same crash...

I am unable to reproduce this on Matplotlib 0.98.5.3 on Linux (don't have a Windows box handy). Can you run the attached script (which is just a modification of mathtext_wx.py to generate 60 different math expressions, and let me know if that crashes for you?

This script does'nt work (it causes a PyAssertion error : invalid stock id)

If it's a PyAssertion error, it should have a traceback. Is there not one?

Mike

···

--
Michael Droettboom
Science Software Branch
Operations and Engineering Division
Space Telescope Science Institute
Operated by AURA for NASA

This script does'nt work (it causes a PyAssertion error : invalid stock id)

If it's a PyAssertion error, it should have a traceback. Is there not one?

No, this problem is not related with Matplotlib : the PyAssertion error occurs when creating the wx.Menu ...

Cédrick

Hello,

I restate the problem :

With the attached script "test_mathtext_wx.py" :
50 functions (line 31) : the 50 bitmaps are generated correctly, by when I close the application an error appears in the console :

Assertion failed: ob_refcnt == 0, file CXX\cxx_extensions.cxx, line 1128
This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.

250 functions : the window never appears and the crash occurs (same message)

However, if in mathtext.py (mpl 0.98.5 win32 py2.5) line 2765 in MathTextParser, I put "self._cache = dict()" instead of "self._cache = maxdict(50)", the behavior of "test_mathtext_wx.py" is significantly different.
50 functions : error on console after closing the application (no difference here)
250 functions : NO CRASH (but error after closing the application)

And now, my questions :
Is this proof that "maxdict" is the cause of the problem ?
Is there a known way to avoid the problem?
Can someone tell me more about maxdict ?

Hoping to have been quite clear,
Cédrick

mathtext_wx.py (1.76 KB)

I don't think maxdict is the problem though it may be changing how the problem manifests itself. What is happening is that when maxdict is used, those C++ extension objects are deleted after the first 50 math expressions. When using a dict, they aren't deleted until closing the application, so it just delays the problem.

All that said, I'm not sure as to the real cause of the error.

I was able to reproduce it on Windows XP with:

    mpl 0.98.5, wx 2.8.10.6, python 2.5.4

however, the following seems to work:

    mpl 0.98.5, wx 2.8.10.6, python 2.6.3

Are you able to update to Python 2.6? That might be one solution to the problem.

I have to say I'm completely stumped as to the root cause of this one.

Mike

···

On 10/17/2009 08:44 AM, C�drick FAURY wrote:

Hello,

I restate the problem :

With the attached script "test_mathtext_wx.py" :
50 functions (line 31) : the 50 bitmaps are generated correctly, by when I close the application an error appears in the console :

Assertion failed: ob_refcnt == 0, file CXX\cxx_extensions.cxx, line 1128
This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.

250 functions : the window never appears and the crash occurs (same message)

However, if in mathtext.py (mpl 0.98.5 win32 py2.5) line 2765 in MathTextParser, I put "self._cache = dict()" instead of "self._cache = maxdict(50)", the behavior of "test_mathtext_wx.py" is significantly different.
50 functions : error on console after closing the application (no difference here)
250 functions : NO CRASH (but error after closing the application)

And now, my questions :
Is this proof that "maxdict" is the cause of the problem ?
Is there a known way to avoid the problem?
Can someone tell me more about maxdict ?

Hoping to have been quite clear,
C�drick

Thank you very much !!
With python 2.6... There is no error, no crash...

Michael Droettboom a écrit :

···

I don't think maxdict is the problem though it may be changing how the problem manifests itself. What is happening is that when maxdict is used, those C++ extension objects are deleted after the first 50 math expressions. When using a dict, they aren't deleted until closing the application, so it just delays the problem.

All that said, I'm not sure as to the real cause of the error.

I was able to reproduce it on Windows XP with:

   mpl 0.98.5, wx 2.8.10.6, python 2.5.4

however, the following seems to work:

   mpl 0.98.5, wx 2.8.10.6, python 2.6.3

Are you able to update to Python 2.6? That might be one solution to the problem.

I have to say I'm completely stumped as to the root cause of this one.

Mike

On 10/17/2009 08:44 AM, Cédrick FAURY wrote:

Hello,

I restate the problem :

With the attached script "test_mathtext_wx.py" :
50 functions (line 31) : the 50 bitmaps are generated correctly, by when I close the application an error appears in the console :

Assertion failed: ob_refcnt == 0, file CXX\cxx_extensions.cxx, line 1128
This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.

250 functions : the window never appears and the crash occurs (same message)

However, if in mathtext.py (mpl 0.98.5 win32 py2.5) line 2765 in MathTextParser, I put "self._cache = dict()" instead of "self._cache = maxdict(50)", the behavior of "test_mathtext_wx.py" is significantly different.
50 functions : error on console after closing the application (no difference here)
250 functions : NO CRASH (but error after closing the application)

And now, my questions :
Is this proof that "maxdict" is the cause of the problem ?
Is there a known way to avoid the problem?
Can someone tell me more about maxdict ?

Hoping to have been quite clear,
Cédrick