Skip to content
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

Segfault when blitting multiple subplots with the gtk3agg backend #2810

Closed
timovwb opened this issue Feb 13, 2014 · 1 comment · Fixed by #2813
Closed

Segfault when blitting multiple subplots with the gtk3agg backend #2810

timovwb opened this issue Feb 13, 2014 · 1 comment · Fixed by #2813

Comments

@timovwb
Copy link
Contributor

timovwb commented Feb 13, 2014

I'm running latest master of matplotlib to enable animations with the Agg backend through cairocffi, but am having issues with multiple subplots.

Here is some modified code from the examples to show the issue:

# Modified example from http://matplotlib.org/examples/animation/simple_anim.html
import numpy as np
import matplotlib as mpl
import matplotlib.animation as animation
from matplotlib.backends.backend_gtk3agg import FigureCanvasGTK3Agg as FigureCanvas

from gi.repository import Gtk

class TestWindow(Gtk.Window):
    def __init__(self):
        Gtk.Window.__init__(self)
        self.resize(600, 400)

        figure = mpl.figure.Figure()
        canvas = FigureCanvas(figure)
        self.add(canvas)
        self.show_all()

        x = np.arange(0, 2*np.pi, 0.01)

        ax1 = figure.add_subplot(121)
        line1, = ax1.plot(x, np.sin(x))

        ax2 = figure.add_subplot(122)
        line2, = ax2.plot(x, np.sin(x))

        def animate(i):
            line1.set_ydata(np.sin(x+i/10.0))
            line2.set_ydata(np.sin(x+i/10.0))
            return line1,# line2

        def init():
            line1.set_ydata(np.ma.array(x, mask=True))
            line2.set_ydata(np.ma.array(x, mask=True))
            return line1,# line2

        self.ani = animation.FuncAnimation(figure, animate, np.arange(1, 200), init_func=init,
                                           interval=25, blit=True)

if __name__ == "__main__":
    win = TestWindow()
    win.connect("delete-event", Gtk.main_quit)
    Gtk.main()

This works until the init() and animate() functions return more than one line (uncomment the return values to checck).
I could trace the call back to FigureCanvasGTK3Agg.blit() in backend_gtk3agg.py. Line 90 is the last one called and throws a segmentation fault.

This happens on Ubuntu 12.04, 13.10 and 14.04. Both with Python 2 and Python 3.

@timovwb
Copy link
Contributor Author

timovwb commented Feb 14, 2014

I found and fixed the issue. Matplotlib tried to convert the original GTK cairo context to the cairocffi context for each bbox in the queue. So it worked for just one subplot, but failed on multiple subplots because the context was already converted. The pull request fixes this by just converting it once in the draw_event, instead of the loop.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant