From 3ccf7415c88dabce1c2efeb79d7a3daf3a7a8dba Mon Sep 17 00:00:00 2001 From: Felix Domke Date: Wed, 31 Aug 2005 00:10:05 +0000 Subject: [PATCH] - fix actions bug: iterator could become corrupted --- lib/actions/action.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/actions/action.cpp b/lib/actions/action.cpp index 25db199e..494c252d 100644 --- a/lib/actions/action.cpp +++ b/lib/actions/action.cpp @@ -126,6 +126,8 @@ void eActionMap::bindKey(const std::string &device, int key, int flags, const st void eActionMap::keyPressed(int device, int key, int flags) { + std::list > call_list; + /* iterate active contexts. */ for (std::multimap::const_iterator c(m_bindings.begin()); c != m_bindings.end();) { @@ -177,8 +179,8 @@ void eActionMap::keyPressed(int device, int key, int flags) PyTuple_SetItem(pArgs, 0, PyString_FromString(k->first.c_str())); PyTuple_SetItem(pArgs, 1, PyString_FromString(k->second.m_action.c_str())); ++k; - ePython::call(i->second.m_fnc, pArgs); - Py_DECREF(pArgs); + Py_INCREF(i->second.m_fnc); + call_list.push_back(std::pair(i->second.m_fnc, pArgs)); } else ++k; } @@ -187,11 +189,18 @@ void eActionMap::keyPressed(int device, int key, int flags) PyObject *pArgs = PyTuple_New(2); PyTuple_SetItem(pArgs, 0, PyInt_FromLong(key)); PyTuple_SetItem(pArgs, 1, PyInt_FromLong(flags)); - ePython::call(i->second.m_fnc, pArgs); - Py_DECREF(pArgs); + Py_INCREF(i->second.m_fnc); + call_list.push_back(std::pair(i->second.m_fnc, pArgs)); } } } + + for (std::list >::iterator i(call_list.begin()); i != call_list.end(); ++i) + { + ePython::call(i->first, i->second); + Py_DECREF(i->first); + Py_DECREF(i->second); + } } eAutoInitPtr init_eActionMap(eAutoInitNumbers::actions, "eActionMap"); -- 2.30.2