Repository navigation
Closed
Description
Bug summary
Python with the 'TkAgg' backend crashes out when figure windows are moved around between multiple monitors.
How to reproduce
Create a few figures e.g.:
from matplotlib import pyplot as plt
import numpy as np
def foo():
plt.figure()
plt.plot(np.random.randn(1000), np.random.randn(1000), 'k.')
for n in range(4):
foo()
plt.show()Move the figures between windows, rearrange them, swap between desktops, perhaps close the windows and rerun the script and repeat. There is a very high probability that Python will crash.
Actual outcome
IPython crashes with
2017-01-04 13:01:00.136 python[13315:466208] *** Assertion failure in -[_NSCGSWindow setFrame:], /Library/Caches/com.apple.xbs/Sources/AppKit/AppKit-1504.76/CGS.subproj/NSCGSWindow.m:663
2017-01-04 13:01:00.141 python[13315:466208] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid parameter not satisfying: CGRectContainsRect(CGRectMake((CGFloat)INT_MIN, (CGFloat)INT_MIN, (CGFloat)INT_MAX - (CGFloat)INT_MIN, (CGFloat)INT_MAX - (CGFloat)INT_MIN), frame)'
*** First throw call stack:
(
0 CoreFoundation 0x00007fff89111e7b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x00007fff9dceccad objc_exception_throw + 48
2 CoreFoundation 0x00007fff89116b82 +[NSException raise:format:arguments:] + 98
3 Foundation 0x00007fff8ab60d50 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 195
4 AppKit 0x00007fff86d2f519 -[_NSCGSWindow setFrame:] + 252
5 AppKit 0x00007fff86dac644 _NXCreateWindowWithStyleMask + 157
6 AppKit 0x00007fff86dac4c2 _NSCreateWindow + 184
7 AppKit 0x00007fff86df5fe4 -[NSWindow _commonAwake] + 1465
8 AppKit 0x00007fff874a92d6 -[NSWindow _resolveAutomaticEnterFullScreenFlags] + 51
9 AppKit 0x00007fff86df58cf -[NSWindow makeKeyAndOrderFront:] + 31
10 Tk 0x0000000106761487 XMapWindow + 164
11 Tk 0x00000001066d2c9d Tk_MapWindow + 178
12 Tk 0x00000001066db3c5 TkInstallFrameMenu + 271
13 Tcl 0x000000010664ea57 TclServiceIdle + 77
14 Tcl 0x0000000106635619 Tcl_DoOneEvent + 350
15 _tkinter.so 0x00000001065ab48d _tkinter_tkapp_mainloop + 445
16 libpython3.5m.dylib 0x000000010004ff38 PyCFunction_Call + 280
17 libpython3.5m.dylib 0x00000001000bd2df PyEval_EvalFrameEx + 22431
18 libpython3.5m.dylib 0x00000001000c10c3 _PyEval_EvalCodeWithName + 1779
19 libpython3.5m.dylib 0x00000001000c19ae fast_function + 334
20 libpython3.5m.dylib 0x00000001000bd434 PyEval_EvalFrameEx + 22772
21 libpython3.5m.dylib 0x00000001000c192f fast_function + 207
22 libpython3.5m.dylib 0x00000001000bd434 PyEval_EvalFrameEx + 22772
23 libpython3.5m.dylib 0x00000001000c10c3 _PyEval_EvalCodeWithName + 1779
24 libpython3.5m.dylib 0x00000001000b7b1e PyEval_EvalCodeEx + 78
25 libpython3.5m.dylib 0x000000010003430f function_call + 351
26 libpython3.5m.dylib 0x000000010000fd73 PyObject_Call + 99
27 libpython3.5m.dylib 0x000000010002130d method_call + 141
28 libpython3.5m.dylib 0x000000010000fd73 PyObject_Call + 99
29 libpython3.5m.dylib 0x0000000100064c55 slot_tp_call + 117
30 libpython3.5m.dylib 0x000000010000fd73 PyObject_Call + 99
31 libpython3.5m.dylib 0x00000001000bdec8 PyEval_EvalFrameEx + 25480
32 libpython3.5m.dylib 0x00000001000c10c3 _PyEval_EvalCodeWithName + 1779
33 libpython3.5m.dylib 0x00000001000c19ae fast_function + 334
34 libpython3.5m.dylib 0x00000001000bd434 PyEval_EvalFrameEx + 22772
35 libpython3.5m.dylib 0x00000001000c10c3 _PyEval_EvalCodeWithName + 1779
36 libpython3.5m.dylib 0x00000001000b7ac1 PyEval_EvalCode + 81
37 libpython3.5m.dylib 0x00000001000b52ab builtin_exec + 555
38 libpython3.5m.dylib 0x000000010004ff38 PyCFunction_Call + 280
39 libpython3.5m.dylib 0x00000001000bd2df PyEval_EvalFrameEx + 22431
40 libpython3.5m.dylib 0x00000001000c10c3 _PyEval_EvalCodeWithName + 1779
41 libpython3.5m.dylib 0x00000001000c19ae fast_function + 334
42 libpython3.5m.dylib 0x00000001000bd434 PyEval_EvalFrameEx + 22772
43 libpython3.5m.dylib 0x00000001000c10c3 _PyEval_EvalCodeWithName + 1779
44 libpython3.5m.dylib 0x00000001000c19ae fast_function + 334
45 libpython3.5m.dylib 0x00000001000bd434 PyEval_EvalFrameEx + 22772
46 libpython3.5m.dylib 0x00000001000c10c3 _PyEval_EvalCodeWithName + 1779
47 libpython3.5m.dylib 0x00000001000c19ae fast_function + 334
48 libpython3.5m.dylib 0x00000001000bd434 PyEval_EvalFrameEx + 22772
49 libpython3.5m.dylib 0x00000001000c10c3 _PyEval_EvalCodeWithName + 1779
50 libpython3.5m.dylib 0x00000001000c19ae fast_function + 334
51 libpython3.5m.dylib 0x00000001000bd434 PyEval_EvalFrameEx + 22772
52 libpython3.5m.dylib 0x00000001000c10c3 _PyEval_EvalCodeWithName + 1779
53 libpython3.5m.dylib 0x00000001000c19ae fast_function + 334
54 libpython3.5m.dylib 0x00000001000bd434 PyEval_EvalFrameEx + 22772
55 libpython3.5m.dylib 0x00000001000c192f fast_function + 207
56 libpython3.5m.dylib 0x00000001000bd434 PyEval_EvalFrameEx + 22772
57 libpython3.5m.dylib 0x00000001000c10c3 _PyEval_EvalCodeWithName + 1779
58 libpython3.5m.dylib 0x00000001000b7b1e PyEval_EvalCodeEx + 78
59 libpython3.5m.dylib 0x000000010003430f function_call + 351
60 libpython3.5m.dylib 0x000000010000fd73 PyObject_Call + 99
61 libpython3.5m.dylib 0x00000001000bdec8 PyEval_EvalFrameEx + 25480
62 libpython3.5m.dylib 0x00000001000c10c3 _PyEval_EvalCodeWithName + 1779
63 libpython3.5m.dylib 0x00000001000c19ae fast_function + 334
64 libpython3.5m.dylib 0x00000001000bd434 PyEval_EvalFrameEx + 22772
65 libpython3.5m.dylib 0x00000001000c10c3 _PyEval_EvalCodeWithName + 1779
66 libpython3.5m.dylib 0x00000001000b7ac1 PyEval_EvalCode + 81
67 libpython3.5m.dylib 0x00000001000e6937 PyRun_FileExFlags + 215
68 libpython3.5m.dylib 0x00000001000e60ea PyRun_SimpleFileExFlags + 842
69 libpython3.5m.dylib 0x00000001000fcc5b Py_Main + 3355
70 python 0x0000000100000dc7 main + 215
71 python 0x0000000100000ce4 start + 52
72 ??? 0x0000000000000002 0x0 + 2
)
libc++abi.dylib: terminating with uncaught exception of type NSException
Abort trap: 6
This is the most common form of stack trace, though more terse errors, such as
called Tcl_FindHashEntry on deleted table
Abort trap: 6
may be encountered.
Expected outcome
This kind of crash should not occur when we simply move windows from one monitor to the other.
Matplotlib version
- matplotlib.version = 1.5.3 (installed via miniconda)
- matplotlib.get_backend() == 'TkAgg'
- Python 3.5.2 |Continuum Analytics, Inc.| (default, Jul 2 2016, 17:52:12)
- IPython 5.1.0
- Darwin MacBook-Pro.local 16.3.0 Darwin Kernel Version 16.3.0: Thu Nov 17 20:23:58 PST 2016; root:xnu-3789.31.2~1/RELEASE_X86_64 x86_64
Activity
efiring commentedon Jan 4, 2017
I very much doubt this is a matplotlib-specific bug. I suspect it is a problem with tkinter, or more likely, with the tk-tcl build itself.
dopplershift commentedon Jan 4, 2017
On Python 3.4 (it's what I had readily available) on the same version of macOS, I couldn't replicate--but I was using the packages from conda-forge.
Can you try to replicate in a new environment with the conda-forge channel? I'm wondering if something's off with Continuum's packages:
kghose commentedon Jan 4, 2017
Hi @dopplershift I could replicate with this environment too. I have three monitors that are different in size and differently oriented which may be part of it. Here is a screencast of the crash, but I don't know if it will help. I just drag the windows to my other monitor (not shown in the cast) back and forth.
efiring commentedon Jan 4, 2017
Try testing without matplotlib. In ipython, test the tkinter minimal example:
Resize the window, and then try dragging it among your monitors. You can try it with plain ipython and with "ipython --gui=tk" to see if there is any difference. (With the later it doesn't exit properly on my machine--I have to use ctrl-C.)
efiring commentedon Jan 4, 2017
If the problem does turn out to be matplotlib-specific, I imagine it is related to the window size in pixels getting out of sync with the agg buffer being written to the window. Something like that.
I note, however, that there is no sign of matplotlib in the traceback.
efiring commentedon Jan 4, 2017
Also, if your test with the minimal tk window doesn't yield a crash, then try your matplotlib example with empty figure windows--no calls to "plot".
tacaswell commentedon Jan 5, 2017
Can you also try with the 2.0.0rc2?
lowderchris commentedon Jan 18, 2017
I'm running into something similar with matplotlib 2.0.0 on macOS Sierra 10.12.2, with the macosx backend. If I create a plot window and plot something simple onto it, and then drag the plot window to a separate desktop on an external monitor... the plot window will erase itself. All that's left at this point is a grey background.
If I try to save the figure, the resulting file does contain the original plot. If I try to plot a new object, the entire original plot will reappear and update itself. I haven't run into any crashes yet, just plots having a bit of amnesia.
dopplershift commentedon Jan 18, 2017
Can you try running the script with
pythonwinstead ofpython?lowderchris commentedon Jan 18, 2017
@dopplershift Importing only matplotlib and pylab to handle plotting, that still appears to run into the same problem.
4 remaining items
rainbean commentedon Dec 25, 2017
The issue still reproducible, just drop window to secondary screen and hoover mouse over navigation toolbar.
In matplotlib/lib/matplotlib/backends/backend_tkagg.py, ToolTip() class, line 825-826,
winfo_rootx() function might return negative value according to screens' placement, and resulting crash.
rainbean commentedon Dec 25, 2017
Root cause might be related to macOS window management mapping multiple screens into a big hyper-screen, see the bug at TK dev. forum.
Pyxidis224 commentedon Aug 13, 2019
This has nothing to do with mathplotlib ! It's a bug in tkinter !
I have this bug on macOS, without any additional library, just with tkinter !
[@tacaswell edited to remove (elided) explicates]
tacaswell commentedon Aug 13, 2019
Might be related to #14999 which causes the whole window manager to crash....
Pyxidis224 commentedon Aug 13, 2019
What's the problem with Apple ? They update their OS, and as soon as they do it, something is going wrong !
HDembinski commentedon Aug 13, 2019
Yes, Apple is the worst.
anntzer commentedon Aug 13, 2019
Unless I am mistaken, this is a bug between osx and tkinter and there isn't anything to do on our side. Closing, but feel free to reopen with something actionable.