Bug summary
I use matplotlib version 3.0.3 and while testing sample code for multicursor, everything is OK and
window opens and multicursor works fine. But if I maximize plotting window, and move mouse cursor on plot, python crashes and exists with code: -1073741819 (0xC0000005)
It took me about a minute of interacting with the plot to reproduce the crash with mpl-3.1.
The crash is in Python's tcl86t.dll. Unfortunately there are not debug symbols for that DLL.
Faulthandler:
alloc: invalid block: 0000018D61935390: a7 fc
Windows fatal exception: code 0x80000003
Current thread 0x00000bf8 (most recent call first):
File "X:\Python37\lib\tkinter\__init__.py", line 3507 in __del__
File "X:\Python37\lib\site-packages\matplotlib\backends\_backend_tk.py", line 252 in resize
File "X:\Python37\lib\tkinter\__init__.py", line 1705 in __call__
File "X:\Python37\lib\tkinter\__init__.py", line 1283 in mainloop
File "X:\Python37\lib\site-packages\matplotlib\backends\_backend_tk.py", line 977 in mainloop
File "X:\Python37\lib\site-packages\matplotlib\backend_bases.py", line 3302 in show
File "X:\Python37\lib\site-packages\matplotlib\cbook\deprecation.py", line 413 in wrapper
File "X:\Python37\lib\site-packages\matplotlib\pyplot.py", line 263 in show
File "mpl_crash.py", line 14 in <module>
Stack trace:
tcl86t.dll!00007ffec5fd735d() Unknown
tcl86t.dll!00007ffec5fd7392() Unknown
tcl86t.dll!00007ffec5ff6032() Unknown
tk86t.dll!00007ffec1d09b67() Unknown
tk86t.dll!00007ffec1cfd2eb() Unknown
tk86t.dll!00007ffec1cfc765() Unknown
tcl86t.dll!00007ffec5f09cac() Unknown
> _tkinter.pyd!Tkapp_Call(_object * selfptr=0x0000018d638854b0, _object * args=0x0000018d63a06240) Line 1508 C
python37.dll!_PyMethodDef_RawFastCallKeywords(PyMethodDef * method=0x0000000000000000, _object * self=0x0000018d638854b0, _object * const * args=0x0000018d64a771c8, __int64 nargs=3, _object * kwnames) Line 694 C
[Inline Frame] python37.dll!_PyMethodDescr_FastCallKeywords(_object *) Line 288 C
python37.dll!call_function(_object * * * pp_stack=0x0000007637fec138, __int64 oparg, _object * kwnames=0x0000000000000000) Line 4593 C
python37.dll!_PyEval_EvalFrameDefault(_frame * f=0x0000018d64a77048, int throwflag=1769722600) Line 3111 C
<snip>
Windows fatal exception: access violation
Current thread 0x000041f0 (most recent call first):
File "X:\Python38\lib\site-packages\matplotlib\backends\_backend_tk.py", line 79 in blit
File "X:\Python38\lib\site-packages\matplotlib\backends\backend_tkagg.py", line 14 in blit
File "X:\Python38\lib\site-packages\matplotlib\widgets.py", line 1456 in _update
File "X:\Python38\lib\site-packages\matplotlib\widgets.py", line 1444 in onmove
File "X:\Python38\lib\site-packages\matplotlib\cbook\__init__.py", line 216 in process
File "X:\Python38\lib\site-packages\matplotlib\backend_bases.py", line 1797 in motion_notify_event
File "X:\Python38\lib\site-packages\matplotlib\backends\_backend_tk.py", line 352 in motion_notify_event
File "X:\Python38\lib\tkinter\__init__.py", line 1883 in __call__
File "X:\Python38\lib\tkinter\__init__.py", line 1420 in mainloop
File "X:\Python38\lib\site-packages\matplotlib\backends\_backend_tk.py", line 977 in mainloop
File "X:\Python38\lib\site-packages\matplotlib\backend_bases.py", line 3302 in show
File "X:\Python38\lib\site-packages\matplotlib\cbook\deprecation.py", line 413 in wrapper
File "X:\Python38\lib\site-packages\matplotlib\pyplot.py", line 263 in show
File "mpl_crash.py", line 14 in <module>
tk86t.dll!00007ffec1d0aca1() Unknown
tk86t.dll!00007ffec1d0c5b1() Unknown
> _tkagg.cp38-win_amd64.pyd!mpl_tk_blit(_object * self, _object * args) Line 247 C++
[Inline Frame] python38.dll!cfunction_call_varargs(_object *) Line 776 C
python38.dll!PyCFunction_Call(_object * func, _object * args, _object * kwargs) Line 791 C
[Inline Frame] python38.dll!_PyObject_MakeTpCall(_object * keywords, _object * const *) Line 159 C
[Inline Frame] python38.dll!_PyObject_Vectorcall(_object * nargsf, _object * const *) Line 122 C
<snip>
It's strange that data_ptr and pixelPtr differ, as they are initialized as block.pixelPtr = data_ptr + 4 * ((height - y2) * width + x1); and the second term is zero in your case?
The crash occurs when y2 suddenly is one off relative to the height for unknown reason. Also, this is a rare event. It takes several hundreds of resizes of the Window to eventually crash.
This resize crash looks different from the alloc: invalid block: I also reported. I'm not sure yet that any of these two issues are related to the original issue of moving the cursor.
The core of the issue is that the figure bbox is not represented in pixel units but is transformed from inches, so there can be rounding errors when converting them to pixels.
With #14461 the crash in TK_PHOTO_PUT_BLOCK_NO_COMPOSITE is clearly gone. I also no longer seem to get any alloc: invalid block crash, so maybe that was due to a memory corruption when the out of bounds blit did not crash right away.
Activity
cgohlke commented on Jun 5, 2019
It took me about a minute of interacting with the plot to reproduce the crash with mpl-3.1.
The crash is in Python's tcl86t.dll. Unfortunately there are not debug symbols for that DLL.
Faulthandler:
Stack trace:
cgohlke commented on Jun 5, 2019
Also got this crash in the TK_PHOTO_PUT_BLOCK_NO_COMPOSITE call. The Tk_PhotoImageBlock pixelPtr seems not accessible.
| Name | Value | Type -- | -- | -- | -- ▶ | args | 0x0000027d526e2cc0 {ob_refcnt=1 ob_type=0x00007ffec6897a40 {python38.dll!_typeobject PyTuple_Type} {...} } | _object * ◢ | block | {pixelPtr=0x0000027d5ade7c40 <Error reading characters of string.> width=1200 height=845 ...} | Tk_PhotoImageBlock | ◢ pixelPtr | 0x0000027d5ade7c40 <Error reading characters of string.> | unsigned char * | | <Unable to read memory> | unsigned char | width | 1200 | int | height | 845 | int | pitch | 4800 | int | pixelSize | 4 | int | ▶ offset | 0x000000bd0b3ec8d0 {0, 1, 2, 3} | int[4] ▶ | data_ptr | 0x0000027d5ade8f00 "ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ... | unsigned char * | height | 844 | int | interp | 0x0000027d49d90010 {...} | Tcl_Interp * | o0 | 0 | int | o1 | 1 | int | o2 | 2 | int | o3 | 3 | int | photo | 0x0000027d4a185e10 | void * ▶ | photo_name | 0x0000027d526be6a0 "pyimage366" | const char * ▶ | self | 0x0000027d4c6c4090 {ob_refcnt=8 ob_type=0x00007ffec6895ae0 {python38.dll!_typeobject PyModule_Type} {...} } | _object * | width | 1200 | int | x1 | 0 | int | x2 | 1200 | int | y1 | 0 | int | y2 | 845 | intanntzer commented on Jun 6, 2019
It's strange that data_ptr and pixelPtr differ, as they are initialized as block.pixelPtr = data_ptr + 4 * ((height - y2) * width + x1); and the second term is zero in your case?
cgohlke commented on Jun 6, 2019
Here's a trace of values printed right before the TK_PHOTO_PUT_BLOCK_NO_COMPOSITE call:
The crash occurs when y2 suddenly is one off relative to the height for unknown reason. Also, this is a rare event. It takes several hundreds of resizes of the Window to eventually crash.
This resize crash looks different from the alloc: invalid block: I also reported. I'm not sure yet that any of these two issues are related to the original issue of moving the cursor.
cgohlke commented on Jun 6, 2019
Here's another trace where I also printed canvas.figure.bbox:
The value 426.99999999999994 is rounded up to 427, one larger than the image height.
anntzer commented on Jun 6, 2019
Managed to repro it on Linux as well.
The core of the issue is that the figure bbox is not represented in pixel units but is transformed from inches, so there can be rounding errors when converting them to pixels.
cgohlke commented on Jun 6, 2019
With #14461 the crash in TK_PHOTO_PUT_BLOCK_NO_COMPOSITE is clearly gone. I also no longer seem to get any alloc: invalid block crash, so maybe that was due to a memory corruption when the out of bounds blit did not crash right away.