8000 Merge pull request #25104 from anntzer/tkc · matplotlib/matplotlib@1ad6cbf · GitHub
[go: up one dir, main page]

Skip to content

Commit 1ad6cbf

Browse files
authored
Merge pull request #25104 from anntzer/tkc
tk blitting to destroyed canvases should be a noop, not a segfault.
2 parents a30c0b1 + 91f6f6c commit 1ad6cbf

File tree

2 files changed

+7
-1
lines changed
8000

2 files changed

+7
-1
lines changed

lib/matplotlib/backends/_backend_tk.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ def _blit(argsid):
6161
the ``_blit_args`` dict, since arguments cannot be passed directly.
6262
"""
6363
photoimage, dataptr, offsets, bboxptr, comp_rule = _blit_args.pop(argsid)
64+
if not photoimage.tk.call("info", "commands", photoimage):
65+
return
6466
_tkagg.blit(photoimage.tk.interpaddr(), str(photoimage), dataptr,
6567
comp_rule, offsets, bboxptr)
6668

lib/matplotlib/tests/test_backend_tk.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def test_blit():
7171
import matplotlib.pyplot as plt
7272
import numpy as np
7373
import matplotlib.backends.backend_tkagg # noqa
74-
from matplotlib.backends import _tkagg
74+
from matplotlib.backends import _backend_tk, _tkagg
7575

7676
fig, ax = plt.subplots()
7777
photoimage = fig.canvas._tkphoto
@@ -93,6 +93,10 @@ def test_blit():
9393
except ValueError:
9494
print("success")
9595

96+
# Test blitting to a destroyed canvas.
97+
plt.close(fig)
98+
_backend_tk.blit(photoimage, data, (0, 1, 2, 3))
99+
96100

97101
@_isolated_tk_test(success_count=1)
98102
def test_figuremanager_preserves_host_mainloop():

0 commit comments

Comments
 (0)
0