From 0955e0aabcc5ef808300ce66e7e3f7f51deb6926 Mon Sep 17 00:00:00 2001 From: Darren Ranalli Date: Wed, 13 Jan 2010 23:37:56 +0000 Subject: [PATCH] make sure DirectObject._addTask and ._clearTask are called only once per task create/destroy --- panda/src/event/pythonTask.cxx | 8 ++++++-- panda/src/event/pythonTask.h | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/panda/src/event/pythonTask.cxx b/panda/src/event/pythonTask.cxx index 7eba5c482a..a8f888289f 100644 --- a/panda/src/event/pythonTask.cxx +++ b/panda/src/event/pythonTask.cxx @@ -37,6 +37,7 @@ PythonTask(PyObject *function, const string &name) : _args = NULL; _upon_death = NULL; _owner = NULL; + _registered_to_owner = false; _generator = NULL; set_function(function); @@ -528,13 +529,14 @@ upon_death(AsyncTaskManager *manager, bool clean_exit) { //////////////////////////////////////////////////////////////////// void PythonTask:: register_to_owner() { - if (_owner != Py_None) { + if (_owner != Py_None && !_registered_to_owner) { #if defined(HAVE_THREADS) && !defined(SIMPLE_THREADS) // Use PyGILState to protect this asynchronous call. PyGILState_STATE gstate; gstate = PyGILState_Ensure(); #endif + _registered_to_owner = true; call_owner_method("_addTask"); #if defined(HAVE_THREADS) && !defined(SIMPLE_THREADS) @@ -550,13 +552,15 @@ register_to_owner() { //////////////////////////////////////////////////////////////////// void PythonTask:: unregister_from_owner() { - if (_owner != Py_None) { + // make sure every call to _clearTask corresponds to a call to _addTask + if (_owner != Py_None && _registered_to_owner) { #if defined(HAVE_THREADS) && !defined(SIMPLE_THREADS) // Use PyGILState to protect this asynchronous call. PyGILState_STATE gstate; gstate = PyGILState_Ensure(); #endif + _registered_to_owner = false; call_owner_method("_clearTask"); #if defined(HAVE_THREADS) && !defined(SIMPLE_THREADS) diff --git a/panda/src/event/pythonTask.h b/panda/src/event/pythonTask.h index 6f087e7d59..13874bc317 100644 --- a/panda/src/event/pythonTask.h +++ b/panda/src/event/pythonTask.h @@ -66,6 +66,7 @@ private: bool _append_task; PyObject *_upon_death; PyObject *_owner; + bool _registered_to_owner; PyObject *_dict; PyObject *_generator;