Re: [Matplotlib-users] MathTextParser, maxdict ... Assertion failed!

2009-10-18 Thread Michael Droettboom
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





--
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] MathTextParser, maxdict ... Assertion failed!

2009-10-18 Thread Cédrick FAURY
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







--
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] MathTextParser, maxdict ... Assertion failed!

2009-10-17 Thread Cédrick FAURY

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




Demonstrates how to convert mathtext to a wx.Bitmap for display in various
controls on wxPython.


import matplotlib
matplotlib.use(WxAgg)
from numpy import arange, sin, pi, cos, log
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas
from matplotlib.backends.backend_wx import NavigationToolbar2Wx
from matplotlib.figure import Figure

import wx

IS_GTK = 'wxGTK' in wx.PlatformInfo
IS_WIN = 'wxMSW' in wx.PlatformInfo
IS_MAC = 'wxMac' in wx.PlatformInfo


# This is where the magic happens.
from matplotlib.mathtext import MathTextParser
mathtext_parser = MathTextParser(Bitmap)
def mathtext_to_wxbitmap(s):
ftimage, depth = mathtext_parser.parse(s, 150)
return wx.BitmapFromBufferRGBA(
ftimage.get_width(), ftimage.get_height(),
ftimage.as_rgba_str())


functions = []
for i in range(250):
functions.append((r'$\frac{x}{%d}$' % i, lambda x: x))


class CanvasFrame(wx.Frame):
def __init__(self, parent, title):
wx.Frame.__init__(self, parent, -1, title, size=(550, 350))
self.SetBackgroundColour(wx.NamedColor(WHITE))

self.scroll = wx.ScrolledWindow(self, -1)
self.scroll.SetScrollRate(20,20)

self.sizer = wx.BoxSizer(wx.VERTICAL)

for f in functions:
self.sizer.Add(wx.StaticBitmap(self.scroll, -1, 
mathtext_to_wxbitmap(f[0])))
self.scroll.FitInside()

self.scroll.SetSizer(self.sizer)


class MyApp(wx.App):
def OnInit(self):
frame = CanvasFrame(None, wxPython mathtext demo app)
self.SetTopWindow(frame)
frame.Show(True)
return True

app = MyApp()
app.MainLoop()




--
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] MathTextParser, maxdict ... Assertion failed!

2009-10-12 Thread Michael Droettboom

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-de...@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

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


Demonstrates how to convert mathtext to a wx.Bitmap for display in various
controls on wxPython.


import matplotlib
matplotlib.use(WxAgg)
from numpy import arange, sin, pi, cos, log
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas
from matplotlib.backends.backend_wx import NavigationToolbar2Wx
from matplotlib.figure import Figure

import wx

IS_GTK = 'wxGTK' in wx.PlatformInfo
IS_WIN = 'wxMSW' in wx.PlatformInfo
IS_MAC = 'wxMac' in wx.PlatformInfo


# This is where the magic happens.
from matplotlib.mathtext import MathTextParser
mathtext_parser = MathTextParser(Bitmap)
def mathtext_to_wxbitmap(s):
ftimage, depth = mathtext_parser.parse(s, 150)
return wx.BitmapFromBufferRGBA(
ftimage.get_width(), ftimage.get_height(),
ftimage.as_rgba_str())


functions = []
for i in range(150):
functions.append((r'$\frac{x}{%d}$' % i, lambda x: x))

class CanvasFrame(wx.Frame):
def __init__(self, parent, title):
wx.Frame.__init__(self, parent, -1, title, size=(550, 350))
self.SetBackgroundColour(wx.NamedColor(WHITE))

self.figure = Figure()
self.axes = self.figure.add_subplot(111)
self.change_plot(0)

self.canvas = FigureCanvas(self, -1, self.figure)

self.sizer = wx.BoxSizer(wx.VERTICAL)
self.add_buttonbar()
self.sizer.Add(self.canvas, 1, wx.LEFT | wx.TOP | wx.GROW)
self.add_toolbar()  # comment this out for no toolbar

menuBar = wx.MenuBar()

# File Menu
menu = wx.Menu()
menu.Append(wx.ID_EXIT, Exit\tAlt-X, Exit this simple sample)
menuBar.Append(menu, File)

if IS_GTK or IS_WIN:
# Equation Menu
menu = wx.Menu()
for i, (mt, func) in enumerate(functions):
bm = mathtext_to_wxbitmap(mt)
item = wx.MenuItem(menu, 1000 + i, )
item.SetBitmap(bm)
menu.AppendItem(item)
self.Bind(wx.EVT_MENU, self.OnChangePlot, item)
menuBar.Append(menu, Functions)

self.SetMenuBar(menuBar)

self.SetSizer(self.sizer)
self.Fit()

def add_buttonbar(self):
self.button_bar = wx.Panel(self)
self.button_bar_sizer = wx.BoxSizer(wx.HORIZONTAL)
self.sizer.Add(self.button_bar, 0, wx.LEFT | wx.TOP | wx.GROW)

for i, (mt, func) in enumerate(functions):
bm = mathtext_to_wxbitmap(mt)
button = wx.BitmapButton(self.button_bar, 1000 + i, bm)
self.button_bar_sizer.Add(button, 1, wx.GROW)
self.Bind(wx.EVT_BUTTON, self.OnChangePlot, button)

self.button_bar.SetSizer(self.button_bar_sizer)

def add_toolbar(self):
Copied verbatim from embedding_wx2.py
self.toolbar = NavigationToolbar2Wx(self.canvas)
self.toolbar.Realize()
if IS_MAC:
self.SetToolBar(self.toolbar)
else:
tw, th = self.toolbar.GetSizeTuple()
fw, fh = self.canvas.GetSizeTuple()
self.toolbar.SetSize(wx.Size(fw, th))
self.sizer.Add(self.toolbar, 0, wx.LEFT | wx.EXPAND)
self.toolbar.update()

def OnPaint(self, event):
self.canvas.draw()

def OnChangePlot(self, event):
self.change_plot(event.GetId() - 1000)

def change_plot(self, plot_number):
t = arange(1.0,3.0,0.01)
s = functions[plot_number][1](t)
  

Re: [Matplotlib-users] MathTextParser, maxdict ... Assertion failed!

2009-10-12 Thread Cédrick FAURY

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



Demonstrates how to convert mathtext to a wx.Bitmap for display in various
controls on wxPython.


import matplotlib
matplotlib.use(WxAgg)
from numpy import arange, sin, pi, cos, log
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas
from matplotlib.backends.backend_wx import NavigationToolbar2Wx
from matplotlib.figure import Figure

import wx

IS_GTK = 'wxGTK' in wx.PlatformInfo
IS_WIN = 'wxMSW' in wx.PlatformInfo
IS_MAC = 'wxMac' in wx.PlatformInfo


# This is where the magic happens.
from matplotlib.mathtext import MathTextParser
mathtext_parser = MathTextParser(Bitmap)
def mathtext_to_wxbitmap(s):
ftimage, depth = mathtext_parser.parse(s, 150)
return wx.BitmapFromBufferRGBA(
ftimage.get_width(), ftimage.get_height(),
ftimage.as_rgba_str())


functions = []
for i in range(250):
functions.append((r'$\frac{x}{%d}$' % i, lambda x: x))


class CanvasFrame(wx.Frame):
def __init__(self, parent, title):
wx.Frame.__init__(self, parent, -1, title, size=(550, 350))
self.SetBackgroundColour(wx.NamedColor(WHITE))

self.scroll = wx.ScrolledWindow(self, -1)
self.scroll.SetScrollRate(20,20)

self.sizer = wx.BoxSizer(wx.VERTICAL)

for f in functions:
self.sizer.Add(wx.StaticBitmap(self.scroll, -1, 
mathtext_to_wxbitmap(f[0])))
self.scroll.FitInside()

self.scroll.SetSizer(self.sizer)


class MyApp(wx.App):
def OnInit(self):
frame = CanvasFrame(None, wxPython mathtext demo app)
self.SetTopWindow(frame)
frame.Show(True)
return True

app = MyApp()
app.MainLoop()




--
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] MathTextParser, maxdict ... Assertion failed!

2009-10-12 Thread Michael Droettboom
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


--
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] MathTextParser, maxdict ... Assertion failed!

2009-10-12 Thread Cédrick FAURY

 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

--
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users