Closed
Description
Bug report
Bug summary
With the "TkAgg" backend, calling figure.canvas.blit
on a closed Figure
instance crashes the Python interpreter with "segmentation fault." An easy workaround is to check if the figure is closed using plt.fignum_exists(figure.number)
before attempting the blit operation.
I tried a couple other backends and they didn't crash.
Code for reproduction
import numpy as np
import matplotlib.pyplot as plt
fig, axes = plt.subplots()
axes.imshow(np.zeros((1000, 1000, 3), dtype=np.uint8))
fig.canvas.draw()
plt.close(fig.number)
fig.canvas.blit(axes.bbox)
Actual outcome
zsh: segmentation fault (core dumped) python segfault2.py
Expected outcome
I'm not really sure, but segfaulting the interpreter isn't it. I think an acceptable alternative would be raising a Python exception from within matplotlib.
Matplotlib version
- Operating system: Ubuntu 18.04.4
- Matplotlib version: 3.1.3
- Matplotlib backend: TkAgg
- Python version: 3.6.9
matplotlib was installed from pip in a virtualenv.