Skip to content

matplotlib crashes on OS X when saving to JPEG and then displaying the plot #4194

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

Closed
netheril96 opened this issue Mar 5, 2015 · 11 comments
Closed

Comments

@netheril96
Copy link

Here is the minimal code to produce the crash on OS X Yosemite, with Python 2.7.9 compiled by homebrew.

# -*- coding: utf-8 -*-
import numpy
import matplotlib.pyplot as plt
plt.plot(numpy.linspace(0, 1, 1000), numpy.random.randn(1000))
plt.savefig('test.jpg')
plt.show()

The error message is

Assertion failed: (s->stack->next != NULL), function CGGStackRestore, file Context/CGGStack.c, line 77.

The crash does not happen if the savefig and show call are swapped, or when saving to png/pdf/svg file. It only happens when pyplot is called in this sequence, and when the format is jpg.

@tacaswell tacaswell added this to the unassigned milestone Mar 5, 2015
@tacaswell
Copy link
Member

What backend are you using? I suspect the OSX backend from the error. Is that the full error message you get?

I can not reproduce this on py3 + linux + qtagg

attn @mdehoon

@netheril96
Copy link
Author

@tacaswell

Yes, it is the MacOSX backend, and the error message is all that I get.

If I manually specify the agg backend, it works normally as well. So this is a bug specific to OSX backend.

@jenshnielsen
Copy link
Member

Which Matplotlib version do you use? I could not reproduce this on master (1.5.dev1)

@netheril96
Copy link
Author

@jenshnielsen

matplotlib (1.4.3)
Python 2.7.9
Mac OS X backend

@mdehoon
Copy link
Contributor

mdehoon commented Mar 6, 2015

I could not reproduce this with Python 2.7.9 and matplotlib 1.4.3 on Mac OS X 10.9 or 10.10.
Can you try changing backend_macosx.py to return immediately from _print_bitmap ?
So

        def _print_bitmap(self, filename, *args, **kwargs):
            return

Then, with some luck, we can find out exactly where the problem is occurring.

@netheril96
Copy link
Author

@mdehoon

The error message goes away, and obviously the jpg is never created.

I took the liberty of poking around in that function, and the error occurs in the call

self.write_bitmap(filename, width, height, dpi)

Even weirder is that running this script in ipdb line by line does not produce any error, and does produce a correct jpeg file.

@mdehoon
Copy link
Contributor

mdehoon commented Mar 6, 2015

I am guessing that these two lines:

    [image release];
    [resizedImage release];

in the function FigureCanvas_write_bitmap in _macosx.m are causing the problem. Can you try moving these two lines down to just before

    [pool release];

, recompile, and see if the problem still occurs?

@netheril96
Copy link
Author

@mdehoon

The problem still occurs after the change and recompile/reinstallation.

Deleting that two release calls doesn't help, either.

@netheril96
Copy link
Author

@mdehoon

I also tried recompiling python as well as installing matplotlib from this git repository. The assertion failure is still there.

@mdehoon
Copy link
Contributor

mdehoon commented Mar 6, 2015

Sorry, there is not much I can do as I cannot reproduce this error. I would suggest to remove more of the code in FigureCanvas_write_bitmap and see if the problem disappears at some point.

@mdboom
Copy link
Member

mdboom commented Mar 21, 2016

Possibly fixed by #6178, but since we're having trouble reproducing, it's hard to say.

@QuLogic QuLogic modified the milestones: 2.0 (style change major release), unassigned Mar 28, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants