Repository: spyder-ide/spyder

Issue:
Segmentation fault while painting flags
## Description

### What steps will reproduce the problem?

<!--- You can use Markdown here --->

1 - open spyder
2 - create a new file
3 - Add several lines of gibbrish eg:
```
asdfasdfsa
asdfasdfas
asdfasdfas
asdfasdf
asdfasfd
```
4 - wait until the editor displays flags for the gibbrish
5 - select the gibbrish and press backspace. Leave one line of gibbrish.


If this didn't work, close spyder and repeat. It happens for me ~ 10% of the time.

What is happening is:
 - a paint event comes
 - it calls `compute_flag_pos`
 - `editor.blockBoundingRect(block)` is called.
 - The rest is in the C traceback.
 

C traceback:
```
Process:               Python [25078]
Path:                  /usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/Resources/Python.app/Contents/MacOS/Python
Identifier:            org.python.python
Version:               3.7.7 (3.7.7)
Code Type:             X86-64 (Native)
Parent Process:        ??? [1]
Responsible:           Python [25078]
User ID:               502

Date/Time:             2020-03-28 13:58:31.855 +0100
OS Version:            Mac OS X 10.15.3 (19D76)
Report Version:        12
Bridge OS Version:     3.0 (14Y908)
Anonymous UUID:        3106AA5D-92F8-7F2F-88AA-C53A5B0C167B

Sleep/Wake UUID:       756676EA-1FAB-4130-9B4F-49D2760D577C

Time Awake Since Boot: 250000 seconds
Time Since Wake:       2400 seconds

System Integrity Protection: enabled

Crashed Thread:        0  CrBrowserMain  Dispatch queue: com.apple.main-thread

Exception Type:        EXC_BAD_ACCESS (SIGSEGV)
Exception Codes:       KERN_INVALID_ADDRESS at 0x00007fb949d3b8ac
Exception Note:        EXC_CORPSE_NOTIFY

VM Regions Near 0x7fb949d3b8ac:
    MALLOC_TINY            00007fafa9300000-00007fafa9400000 [ 1024K] rw-/rwx SM=PRV  
--> 
    Stack Guard            00007ffeed848000-00007ffeed849000 [    4K] ---/rwx SM=NUL  

Thread 0 Crashed:: CrBrowserMain  Dispatch queue: com.apple.main-thread
0   libsystem_kernel.dylib        	0x00007fff69b027fa __pthread_kill + 10
1   libsystem_pthread.dylib       	0x00007fff69bbfbc1 pthread_kill + 432
2   libsystem_c.dylib             	0x00007fff69a193a2 raise + 26
3   libsystem_platform.dylib      	0x00007fff69bb442d _sigtramp + 29
4   ???                           	000000000000000000 0 + 0
5   QtGui                         	0x0000000114a619c2 QTextEngine::validate() const + 210
6   QtGui                         	0x0000000114a5e58a QTextEngine::itemize() const + 42
7   QtGui                         	0x0000000114a6dcc1 QTextLayout::beginLayout() + 33
8   QtWidgets                     	0x000000011457c1b3 QPlainTextDocumentLayout::layoutBlock(QTextBlock const&) + 227
9   QtWidgets                     	0x000000011457bfba QPlainTextDocumentLayout::blockBoundingRect(QTextBlock const&) const + 74
10  QtWidgets                     	0x000000011457e9a6 QPlainTextEdit::blockBoundingRect(QTextBlock const&) const + 70
11  QtWidgets.so                  	0x0000000113ff19df meth_QPlainTextEdit_blockBoundingRect(_object*, _object*) + 111
12  org.python.python             	0x00000001013dadd3 _PyMethodDef_RawFastCallKeywords + 235
13  org.python.python             	0x00000001013da45c _PyCFunction_FastCallKeywords + 41
14  org.python.python             	0x000000010146fa6c call_function + 628
15  org.python.python             	0x0000000101468a47 _PyEval_EvalFrameDefault + 6767
16  org.python.python             	0x00000001014702cd _PyEval_EvalCodeWithName + 1698
17  org.python.python             	0x00000001013da424 _PyFunction_FastCallKeywords + 212
18  org.python.python             	0x000000010146fad9 call_function + 737
19  org.python.python             	0x0000000101468ae2 _PyEval_EvalFrameDefault + 6922
20  org.python.python             	0x00000001014702cd _PyEval_EvalCodeWithName + 1698
21  org.python.python             	0x00000001013da09c _PyFunction_FastCallDict + 444
22  org.python.python             	0x00000001013db1a3 _PyObject_Call_Prepend + 131
23  org.python.python             	0x00000001013da569 PyObject_Call + 136
24  sip.cpython-37m-darwin.so     	0x0000000113d834c0 sip_api_call_procedure_method + 208
25  QtWidgets.so                  	0x0000000113fa7db7 sipQWidget::paintEvent(QPaintEvent*) + 103
26  QtWidgets                     	0x00000001143ff738 QWidget::event(QEvent*) + 1096
27  QtWidgets.so                  	0x0000000113fa8c80 sipQWidget::event(QEvent*) + 192
28  QtWidgets                     	0x00000001143c377d QApplicationPrivate::notify_helper(QObject*, QEvent*) + 269
29  QtWidgets                     	0x00000001143c4b82 QApplication::notify(QObject*, QEvent*) + 594
30  QtWidgets.so                  	0x0000000113f923ca sipQApplication::notify(QObject*, QEvent*) + 234
31  QtCore                        	0x0000000110df2574 QCoreApplication::notifyInternal2(QObject*, QEvent*) + 212
32  QtWidgets                     	0x00000001143f83f1 QWidgetPrivate::drawWidget(QPaintDevice*, QRegion const&, QPoint const&, int, QPainter*, QWidgetBackingStore*) + 2929
33  QtWidgets                     	0x00000001143d111b 0x1143b3000 + 123163
34  QtWidgets                     	0x00000001143ff95d QWidget::event(QEvent*) + 1645
35  QtWidgets                     	0x0000000114510c05 QMainWindow::event(QEvent*) + 277
36  QtWidgets.so                  	0x0000000113ee6e70 sipQMainWindow::event(QEvent*) + 192
37  QtWidgets                     	0x00000001143c377d QApplicationPrivate::notify_helper(QObject*, QEvent*) + 269
38  QtWidgets                     	0x00000001143c4b82 QApplication::notify(QObject*, QEvent*) + 594
39  QtWidgets.so                  	0x0000000113f923ca sipQApplication::notify(QObject*, QEvent*) + 234
40  QtCore                        	0x0000000110df2574 QCoreApplication::notifyInternal2(QObject*, QEvent*) + 212
41  QtWidgets                     	0x00000001143cc539 0x1143b3000 + 103737
42  QtWidgets                     	0x00000001143ccd9d 0x1143b3000 + 105885
43  QtWidgets                     	0x0000000114402da0 QWidget::repaint(QRect const&) + 176
44  QtWidgets                     	0x0000000114405d86 0x1143b3000 + 339334
45  QtCore                        	0x0000000110e238cc QMetaObject::activate(QObject*, int, int, void**) + 3132
46  QtCore.so                     	0x0000000110a6f71f pyqtBoundSignal_emit(_object*, _object*) + 655
47  org.python.python             	0x00000001013dadd3 _PyMethodDef_RawFastCallKeywords + 235
48  org.python.python             	0x00000001013df701 _PyMethodDescr_FastCallKeywords + 81
49  org.python.python             	0x000000010146fb06 call_function + 782
50  org.python.python             	0x0000000101468a2e _PyEval_EvalFrameDefault + 6742
51  org.python.python             	0x00000001013da830 function_code_fastcall + 106
52  org.python.python             	0x00000001013db1a3 _PyObject_Call_Prepend + 131
53  org.python.python             	0x00000001013da569 PyObject_Call + 136
54  QtCore.so                     	0x0000000110a73120 PyQtSlot::call(_object*, _object*) const + 320
55  QtCore.so                     	0x0000000110a72f16 PyQtSlot::invoke(void**, _object*, void*, bool) const + 374
56  QtCore.so                     	0x0000000110a73a15 PyQtSlotProxy::unislot(void**) + 85
57  QtCore.so                     	0x0000000110a7398a PyQtSlotProxy::qt_metacall(QMetaObject::Call, int, void**) + 58
58  QtCore                        	0x0000000110e2337d QMetaObject::activate(QObject*, int, int, void**) + 1773
59  QtWidgets                     	0x0000000114584cf8 0x1143b3000 + 1907960
60  QtCore                        	0x0000000110e238cc QMetaObject::activate(QObject*, int, int, void**) + 3132
61  QtWidgets                     	0x00000001145b5378 0x1143b3000 + 2106232
62  QtCore                        	0x0000000110e238cc QMetaObject::activate(QObject*, int, int, void**) + 3132
63  QtGui                         	0x0000000114ce495e QTextDocument::blockCountChanged(int) + 62
64  QtGui                         	0x0000000114a947fe QTextDocumentPrivate::finishEdit() + 686
65  QtGui                         	0x0000000114ac5074 QTextCursor::removeSelectedText() + 708
66  QtGui                         	0x0000000114ac5449 QTextCursor::deletePreviousChar() + 841
67  QtWidgets                     	0x00000001145abecd 0x1143b3000 + 2068173
68  QtWidgets                     	0x00000001145aab40 QWidgetTextControl::processEvent(QEvent*, QPointF const&, QWidget*) + 80
69  QtWidgets                     	0x0000000114580fa4 QPlainTextEdit::keyPressEvent(QKeyEvent*) + 468
70  QtWidgets.so                  	0x0000000113ff395b meth_QPlainTextEdit_keyPressEvent(_object*, _object*) + 139
71  org.python.python             	0x00000001013dadd3 _PyMethodDef_RawFastCallKeywords + 235
72  org.python.python             	0x00000001013da45c _PyCFunction_FastCallKeywords + 41
73  org.python.python             	0x000000010146fa6c call_function + 628
74  org.python.python             	0x0000000101468a47 _PyEval_EvalFrameDefault + 6767
75  org.python.python             	0x00000001014702cd _PyEval_EvalCodeWithName + 1698
76  org.python.python             	0x00000001013da424 _PyFunction_FastCallKeywords + 212
77  org.python.python             	0x000000010146fad9 call_function + 737
78  org.python.python             	0x0000000101468a47 _PyEval_EvalFrameDefault + 6767
79  org.python.python             	0x00000001014702cd _PyEval_EvalCodeWithName + 1698
80  org.python.python             	0x00000001013da424 _PyFunction_FastCallKeywords + 212
81  org.python.python             	0x000000010146fad9 call_function + 737
82  org.python.python             	0x0000000101468ae2 _PyEval_EvalFrameDefault + 6922
83  org.python.python             	0x00000001014702cd _PyEval_EvalCodeWithName + 1698
84  org.python.python             	0x00000001013da09c _PyFunction_FastCallDict + 444
85  org.python.python             	0x00000001013db1a3 _PyObject_Call_Prepend + 131
86  org.python.python             	0x00000001013da569 PyObject_Call + 136
87  sip.cpython-37m-darwin.so     	0x0000000113d834c0 sip_api_call_procedure_method + 208
88  QtWidgets.so                  	0x0000000113ed3e77 sipQPlainTextEdit::keyPressEvent(QKeyEvent*) + 103
89  QtWidgets                     	0x00000001143ff4ff QWidget::event(QEvent*) + 527
90  QtWidgets                     	0x00000001144a722d QFrame::event(QEvent*) + 45
91  QtWidgets                     	0x0000000114580884 QPlainTextEdit::event(QEvent*) + 772
92  QtWidgets.so                  	0x0000000113ff2c2b meth_QPlainTextEdit_event(_object*, _object*) + 139
93  org.python.python             	0x00000001013dadd3 _PyMethodDef_RawFastCallKeywords + 235
94  org.python.python             	0x00000001013da45c _PyCFunction_FastCallKeywords + 41
95  org.python.python             	0x000000010146fa6c call_function + 628
96  org.python.python             	0x0000000101468a47 _PyEval_EvalFrameDefault + 6767
97  org.python.python             	0x00000001014702cd _PyEval_EvalCodeWithName + 1698
98  org.python.python             	0x00000001013da09c _PyFunction_FastCallDict + 444
99  org.python.python             	0x00000001013db1a3 _PyObject_Call_Prepend + 131
100 org.python.python             	0x00000001013da569 PyObject_Call + 136
101 sip.cpython-37m-darwin.so     	0x0000000113d83388 sip_api_call_method + 200
102 QtWidgets.so                  	0x0000000113ed333b sipQPlainTextEdit::event(QEvent*) + 123
103 QtWidgets                     	0x00000001143c377d QApplicationPrivate::notify_helper(QObject*, QEvent*) + 269
104 QtWidgets                     	0x00000001143c4ccc QApplication::notify(QObject*, QEvent*) + 924
105 QtWidgets.so                  	0x0000000113f923ca sipQApplication::notify(QObject*, QEvent*) + 234
106 QtCore                        	0x0000000110df2574 QCoreApplication::notifyInternal2(QObject*, QEvent*) + 212
107 QtWidgets                     	0x000000011441e261 0x1143b3000 + 438881
108 QtWidgets                     	0x000000011441d641 0x1143b3000 + 435777
109 QtWidgets                     	0x00000001143c377d QApplicationPrivate::notify_helper(QObject*, QEvent*) + 269
110 QtWidgets                     	0x00000001143c4b82 QApplication::notify(QObject*, QEvent*) + 594
111 QtWidgets.so                  	0x0000000113f923ca sipQApplication::notify(QObject*, QEvent*) + 234
112 QtCore                        	0x0000000110df2574 QCoreApplication::notifyInternal2(QObject*, QEvent*) + 212
113 QtGui                         	0x0000000114989038 QGuiApplicationPrivate::processKeyEvent(QWindowSystemInterfacePrivate::KeyEvent*) + 152
114 QtGui                         	0x000000011496f41b QWindowSystemInterface::sendWindowSystemEvents(QFlags<QEventLoop::ProcessEventsFlag>) + 219
115 QtGui                         	0x000000011496a355 QWindowSystemInterface::flushWindowSystemEvents(QFlags<QEventLoop::ProcessEventsFlag>) + 581
116 libqcocoa.dylib               	0x000000011f391308 0x11f363000 + 189192
117 libqcocoa.dylib               	0x000000011f3914d8 0x11f363000 + 189656
118 com.apple.AppKit              	0x00007fff2f683b98 -[NSWindow(NSEventRouting) _reallySendEvent:isDelayedEvent:] + 6512
119 com.apple.AppKit              	0x00007fff2f682005 -[NSWindow(NSEventRouting) sendEvent:] + 349
120 libqcocoa.dylib               	0x000000011f3948e5 0x11f363000 + 202981
121 com.apple.AppKit              	0x00007fff2f680ccf -[NSApplication(NSEvent) sendEvent:] + 2739
122 libqcocoa.dylib               	0x000000011f39b93a 0x11f363000 + 231738
123 com.apple.AppKit              	0x00007fff2f4cc0cf -[NSApplication run] + 707
124 libqcocoa.dylib               	0x000000011f398013 0x11f363000 + 217107
125 QtCore                        	0x0000000110dedb8f QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) + 431
126 QtCore                        	0x0000000110df2b82 QCoreApplication::exec() + 130
127 QtWidgets.so                  	0x00000001140817d2 meth_QApplication_exec_(_object*, _object*) + 82
128 org.python.python             	0x00000001013dadd3 _PyMethodDef_RawFastCallKeywords + 235
129 org.python.python             	0x00000001013da45c _PyCFunction_FastCallKeywords + 41
130 org.python.python             	0x000000010146fa6c call_function + 628
131 org.python.python             	0x0000000101468a47 _PyEval_EvalFrameDefault + 6767
132 org.python.python             	0x00000001013da830 function_code_fastcall + 106
133 org.python.python             	0x000000010146fad9 call_function + 737
134 org.python.python             	0x0000000101468ae2 _PyEval_EvalFrameDefault + 6922
135 org.python.python             	0x00000001013da830 function_code_fastcall + 106
136 org.python.python             	0x000000010146fad9 call_function + 737
137 org.python.python             	0x0000000101468a47 _PyEval_EvalFrameDefault + 6767
138 org.python.python             	0x00000001013da830 function_code_fastcall + 106
139 org.python.python             	0x000000010146fad9 call_function + 737
140 org.python.python             	0x0000000101468a47 _PyEval_EvalFrameDefault + 6767
141 org.python.python             	0x00000001014702cd _PyEval_EvalCodeWithName + 1698
142 org.python.python             	0x0000000101466f35 PyEval_EvalCode + 51
143 org.python.python             	0x000000010149537c run_mod + 54
144 org.python.python             	0x00000001014943af PyRun_FileExFlags + 160
145 org.python.python             	0x0000000101493a66 PyRun_SimpleFileExFlags + 270
146 org.python.python             	0x00000001014ac276 pymain_main + 5445
147 org.python.python             	0x00000001014ac8e4 _Py_UnixMain + 56
148 libdyld.dylib                 	0x00007fff699bb7fd start + 1
```

### Traceback
```python-traceback
Fatal Python error: Segmentation fault

Thread 0x0000700008da4000 (most recent call first):
  File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 2590 in proxy_bypass_macosx_sysconf
  File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/urllib/request.py", line 2614 in proxy_bypass
  File "/usr/local/lib/python3.7/site-packages/requests/utils.py", line 745 in should_bypass_proxies
  File "/usr/local/lib/python3.7/site-packages/requests/utils.py", line 761 in get_environ_proxies
  File "/usr/local/lib/python3.7/site-packages/requests/sessions.py", line 700 in merge_environment_settings
  File "/usr/local/lib/python3.7/site-packages/requests/sessions.py", line 524 in request
  File "/usr/local/lib/python3.7/site-packages/requests/sessions.py", line 546 in get
  File "/Users/quentinpeter/pyscripts/spyder/spyder/plugins/completion/kite/client.py", line 120 in perform_http_request
  File "/Users/quentinpeter/pyscripts/spyder/spyder/plugins/completion/kite/client.py", line 104 in _get_status
  File "/Users/quentinpeter/pyscripts/spyder/spyder/plugins/completion/kite/client.py", line 109 in get_status

Thread 0x0000700012b16000 (most recent call first):
  File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/threading.py", line 300 in wait
  File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/threading.py", line 552 in wait
  File "/usr/local/lib/python3.7/site-packages/jupyter_client/channels.py", line 158 in run
  File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/threading.py", line 926 in _bootstrap_inner
  File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/threading.py", line 890 in _bootstrap

Thread 0x000070001250d000 (most recent call first):
  File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/selectors.py", line 558 in select
  File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/asyncio/base_events.py", line 1750 in _run_once
  File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/asyncio/base_events.py", line 541 in run_forever
  File "/usr/local/lib/python3.7/site-packages/tornado/platform/asyncio.py", line 148 in start
  File "/usr/local/lib/python3.7/site-packages/jupyter_client/threaded.py", line 188 in run
  File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/threading.py", line 926 in _bootstrap_inner
  File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/threading.py", line 890 in _bootstrap

Thread 0x0000700011f04000 (most recent call first):
  File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/threading.py", line 296 in wait
  File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/threading.py", line 552 in wait
  File "/usr/local/lib/python3.7/site-packages/IPython/core/history.py", line 829 in run
  File "/usr/local/lib/python3.7/site-packages/IPython/core/history.py", line 58 in needs_sqlite
  File "</usr/local/lib/python3.7/site-packages/decorator.py:decorator-gen-24>", line 2 in run
  File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/threading.py", line 926 in _bootstrap_inner
  File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/threading.py", line 890 in _bootstrap

Thread 0x0000700011a01000 (most recent call first):
  File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/socket.py", line 212 in accept
  File "/Users/quentinpeter/pyscripts/spyder/spyder/app/mainwindow.py", line 3291 in start_open_files_server
  File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/threading.py", line 870 in run
  File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/threading.py", line 926 in _bootstrap_inner
  File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/threading.py", line 890 in _bootstrap

Current thread 0x0000000116c00dc0 (most recent call first):
  File "/Users/quentinpeter/pyscripts/spyder/spyder/plugins/editor/panels/scrollflag.py", line 203 in compute_flag_ypos
  File "/Users/quentinpeter/pyscripts/spyder/spyder/plugins/editor/panels/scrollflag.py", line 233 in paintEvent
  File "/Users/quentinpeter/pyscripts/spyder/spyder/plugins/editor/utils/debugger.py", line 141 in update_breakpoints
  File "/Users/quentinpeter/pyscripts/spyder/spyder/plugins/editor/widgets/base.py", line 380 in keyPressEvent
  File "/Users/quentinpeter/pyscripts/spyder/spyder/plugins/editor/widgets/codeeditor.py", line 3798 in insert_text
  File "/Users/quentinpeter/pyscripts/spyder/spyder/plugins/editor/widgets/codeeditor.py", line 3904 in keyPressEvent
  File "/Users/quentinpeter/pyscripts/spyder/spyder/plugins/editor/widgets/codeeditor.py", line 3778 in event
  File "/Users/quentinpeter/pyscripts/spyder/spyder/app/mainwindow.py", line 3663 in run_spyder
  File "/Users/quentinpeter/pyscripts/spyder/spyder/app/mainwindow.py", line 3764 in main
  File "/Users/quentinpeter/pyscripts/spyder/spyder/app/start.py", line 204 in main
  File "/Applications/Spyder.app/Contents/MacOS/Spyder", line 6 in <module>
```

## Versions

* Spyder version: 5.0.0.dev0 8b65abbc0
* Python version: 3.7.7
* Qt version: 5.12.6
* PyQt5 version: 5.12.3
* Operating System: Darwin 19.3.0

### Dependencies

```

# Mandatory:
applaunchservices >=0.1.7   :  0.2.1 (OK)
atomicwrites >=1.2.0        :  1.3.0 (OK)
chardet >=2.0.0             :  3.0.4 (OK)
cloudpickle >=0.5.0         :  1.2.2 (OK)
diff_match_patch >=20181111 :  20181111 (OK)
intervaltree                :  None (OK)
IPython >=4.0               :  7.10.2 (OK)
jedi =0.15.2                :  0.15.2 (OK)
nbconvert >=4.0             :  5.6.1 (OK)
numpydoc >=0.6.0            :  0.9.1 (OK)
parso =0.5.2                :  0.5.2 (OK)
pexpect >=4.4.0             :  4.7.0 (OK)
pickleshare >=0.4           :  0.7.5 (OK)
psutil >=5.3                :  5.6.5 (OK)
pygments >=2.0              :  2.4.2 (OK)
pylint >=0.25               :  2.4.4 (OK)
pyls >=0.31.9;<0.32.0       :  0.31.9 (OK)
qdarkstyle >=2.8            :  2.8.1 (OK)
qtawesome >=0.5.7           :  0.6.0 (OK)
qtconsole >=4.6.0           :  4.7.0.dev0 (OK)
qtpy >=1.5.0                :  1.9.0 (OK)
sphinx >=0.6.6              :  2.2.1 (OK)
spyder_kernels >=2.0.0dev0  :  2.0.0.dev0 (OK)
watchdog                    :  None (OK)
zmq >=17                    :  18.1.1 (OK)

# Optional:
cython >=0.21               :  0.29.14 (OK)
matplotlib >=2.0.0          :  3.1.2 (OK)
numpy >=1.7                 :  1.17.4 (OK)
pandas >=0.13.1             :  0.25.3 (OK)
scipy >=0.17.0              :  1.3.3 (OK)
sympy >=0.7.3               :  1.4 (OK)
```



Discussion:
This is the bug I saw in https://github.com/spyder-ide/spyder/pull/11991 but this PR didn't fix it.
Video of me following the steps with the latest master:

![crash](https://user-images.githubusercontent.com/6740194/77845728-62dca980-71b1-11ea-86fd-a1b82d9a1506.gif)



Resolving patch:
diff --git a/spyder/plugins/editor/panels/scrollflag.py b/spyder/plugins/editor/panels/scrollflag.py
--- a/spyder/plugins/editor/panels/scrollflag.py
+++ b/spyder/plugins/editor/panels/scrollflag.py
@@ -70,9 +70,8 @@ def __init__(self, editor):
         self._update_list_timer = QTimer(self)
         self._update_list_timer.setSingleShot(True)
         self._update_list_timer.timeout.connect(self.update_flags)
-        self._todo_list = []
-        self._code_analysis_list = []
-        self._breakpoint_list = []
+        # Dictionnary with flag lists
+        self._dict_flag_list = {}
 
     @property
     def slider(self):
@@ -111,9 +110,13 @@ def update_flags(self):
         large files. Save all the flags in lists for painting during
         paint events.
         """
-        self._todo_list = []
-        self._code_analysis_list = []
-        self._breakpoint_list = []
+        self._dict_flag_list = {
+            'error': [],
+            'warning': [],
+            'todo': [],
+            'breakpoint': [],
+        }
+
         editor = self.editor
         block = editor.document().firstBlock()
         while block.isValid():
@@ -121,13 +124,22 @@ def update_flags(self):
             data = block.userData()
             if data:
                 if data.code_analysis:
-                    self._code_analysis_list.append((block, data))
-
-                if data.todo:
-                    self._todo_list.append((block, data))
-
-                if data.breakpoint:
-                    self._breakpoint_list.append((block, data))
+                    # Paint the errors and warnings
+                    for _, _, severity, _ in data.code_analysis:
+                        if severity == DiagnosticSeverity.ERROR:
+                            flag_type = 'error'
+                            break
+                    else:
+                        flag_type = 'warning'
+                elif data.todo:
+                    flag_type = 'todo'
+                elif data.breakpoint:
+                    flag_type = 'breakpoint'
+                else:
+                    flag_type = None
+
+                if flag_type is not None:
+                    self._dict_flag_list[flag_type].append(block.blockNumber())
 
             block = block.next()
 
@@ -205,75 +217,26 @@ def compute_flag_ypos(block):
 
                 return ceil(middle-self.FLAGS_DY/2)
 
-        def should_paint_block(block):
-            """Check if the block should be painted."""
-            if not block.isValid():
-                return False
-            # Don't paint local flags outside of the window
-            if paint_local and not (
-                    min_line <= block.blockNumber() + 1 <= max_line):
-                return False
-            return True
-
-        # Paint all the code analysis flags
-        for block, data in self._code_analysis_list:
-            if not should_paint_block(block):
-                continue
-            # Paint the warnings
-            for source, code, severity, message in data.code_analysis:
-                error = severity == DiagnosticSeverity.ERROR
-                if error:
-                    painter.setBrush(self._facecolors['error'])
-                    painter.setPen(self._edgecolors['error'])
-                    break
-            else:
-                painter.setBrush(self._facecolors['warning'])
-                painter.setPen(self._edgecolors['warning'])
-
-            rect_y = compute_flag_ypos(block)
-            painter.drawRect(rect_x, rect_y, rect_w, rect_h)
-
-        # Paint all the todo flags
-        for block, data in self._todo_list:
-            if not should_paint_block(block):
-                continue
-            # Paint the todos
-            rect_y = compute_flag_ypos(block)
-            painter.setBrush(self._facecolors['todo'])
-            painter.setPen(self._edgecolors['todo'])
-            painter.drawRect(rect_x, rect_y, rect_w, rect_h)
-
-        # Paint all the breakpoints flags
-        for block, data in self._breakpoint_list:
-            if not should_paint_block(block):
-                continue
-            # Paint the breakpoints
-            rect_y = compute_flag_ypos(block)
-            painter.setBrush(self._facecolors['breakpoint'])
-            painter.setPen(self._edgecolors['breakpoint'])
-            painter.drawRect(rect_x, rect_y, rect_w, rect_h)
-
-        # Paint the occurrences of selected word flags
-        if editor.occurrences:
-            painter.setBrush(self._facecolors['occurrence'])
-            painter.setPen(self._edgecolors['occurrence'])
-            for line_number in editor.occurrences:
+        # All the lists of block numbers for flags
+        dict_flag_lists = {
+            "occurrence": editor.occurrences,
+            "found_results": editor.found_results
+        }
+        dict_flag_lists.update(self._dict_flag_list)
+
+        for flag_type in dict_flag_lists:
+            painter.setBrush(self._facecolors[flag_type])
+            painter.setPen(self._edgecolors[flag_type])
+            for block_number in dict_flag_lists[flag_type]:
+                # Don't paint local flags outside of the window
                 if paint_local and not (
-                        min_line <= line_number + 1 <= max_line):
+                        min_line <= block_number + 1 <= max_line):
                     continue
-                block = editor.document().findBlockByNumber(line_number)
-                rect_y = compute_flag_ypos(block)
-                painter.drawRect(rect_x, rect_y, rect_w, rect_h)
-
-        # Paint the found results flags
-        if editor.found_results:
-            painter.setBrush(self._facecolors['found_results'])
-            painter.setPen(self._edgecolors['found_results'])
-            for line_number in editor.found_results:
-                if paint_local and not (
-                        min_line <= line_number + 1 <= max_line):
+                # Find the block
+                block = editor.document().findBlockByNumber(block_number)
+                if not block.isValid():
                     continue
-                block = editor.document().findBlockByNumber(line_number)
+                # paint if everything else is fine
                 rect_y = compute_flag_ypos(block)
                 painter.drawRect(rect_x, rect_y, rect_w, rect_h)
 
diff --git a/spyder/plugins/editor/widgets/editor.py b/spyder/plugins/editor/widgets/editor.py
--- a/spyder/plugins/editor/widgets/editor.py
+++ b/spyder/plugins/editor/widgets/editor.py
@@ -2188,7 +2188,7 @@ def analyze_script(self, index=None):
             return
         if index is None:
             index = self.get_stack_index()
-        if self.data:
+        if self.data and len(self.data) > index:
             finfo = self.data[index]
             if self.todolist_enabled:
                 finfo.run_todo_finder()


Test patch: