Skip to content

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

Closed

Description

@netheril96

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.

Activity

  1. added this to the milestone on Mar 5, 2015
  2. tacaswell commented on Mar 5, 2015

    @tacaswell
    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

  3. netheril96 commented on Mar 5, 2015

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

  4. jenshnielsen commented on Mar 5, 2015

    @jenshnielsen
    Member

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

  5. netheril96 commented on Mar 5, 2015

    @netheril96
    Author

    @jenshnielsen

    matplotlib (1.4.3)
    Python 2.7.9
    Mac OS X backend

  6. mdehoon commented on Mar 6, 2015

    @mdehoon
    Contributor

    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.

  7. netheril96 commented on Mar 6, 2015

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

  8. mdehoon commented on Mar 6, 2015

    @mdehoon
    Contributor

    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?

  9. netheril96 commented on Mar 6, 2015

    @netheril96
    Author

    @mdehoon

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

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

  10. netheril96 commented on Mar 6, 2015

    @netheril96
    Author

    @mdehoon

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

  11. mdehoon commented on Mar 6, 2015

    @mdehoon
    Contributor

    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.

  12. mdboom commented on Mar 21, 2016

    @mdboom
    Member

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

  13. modified the milestones: , on Mar 28, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions