Skip to content

Commit 8fd1227

Browse files
committed
Fix bug with clearing callbacks within a callback handler
- iterator was invalidated
1 parent 1a7e466 commit 8fd1227

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

PythonScript/src/NotepadPlusWrapper.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,23 +95,30 @@ void NotepadPlusWrapper::notify(SCNotification *notifyCode)
9595
break;
9696
}
9797

98+
99+
std::list<PyObject*> callbacks;
100+
98101
while (callbackIter.first != callbackIter.second)
99102
{
100-
103+
callbacks.push_back(callbackIter.first->second);
104+
++callbackIter.first;
105+
}
106+
107+
108+
for (std::list<PyObject*>::iterator listIter = callbacks.begin(); listIter != callbacks.end(); ++listIter)
109+
{
101110
PyGILState_STATE state = PyGILState_Ensure();
102111
try
103112
{
104113
s_inEvent = true;
105-
call<PyObject*>(callbackIter.first->second, params);
114+
call<PyObject*>((*listIter), params);
106115
s_inEvent = false;
107116
}
108117
catch(...)
109118
{
110119
PyErr_Print();
111120
}
112121
PyGILState_Release(state);
113-
114-
++callbackIter.first;
115122
}
116123

117124
}

0 commit comments

Comments
 (0)