From a257cbbfba998d26850b38cb4833ec093d4b1b4e Mon Sep 17 00:00:00 2001 From: David Rose Date: Fri, 2 Oct 2009 22:10:51 +0000 Subject: [PATCH] fix shutdown error --- direct/src/plugin/p3dPythonRun.cxx | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/direct/src/plugin/p3dPythonRun.cxx b/direct/src/plugin/p3dPythonRun.cxx index 72fc1ac261..7a51e48f26 100755 --- a/direct/src/plugin/p3dPythonRun.cxx +++ b/direct/src/plugin/p3dPythonRun.cxx @@ -45,6 +45,8 @@ P3DPythonRun(const char *program_name, const char *archive_file, _read_thread_continue = false; _program_continue = true; _session_terminated = false; + _taskMgr = NULL; + INIT_LOCK(_commands_lock); INIT_THREAD(_read_thread); @@ -116,7 +118,7 @@ P3DPythonRun(const char *program_name, const char *archive_file, //////////////////////////////////////////////////////////////////// P3DPythonRun:: ~P3DPythonRun() { - nassertv(_instances.empty()); + terminate_session(); // Close the write pipe, so the parent process will terminate us. _pipe_write.close(); @@ -1406,14 +1408,18 @@ terminate_session() { } _instances.clear(); - PyObject *result = PyObject_CallMethod(_taskMgr, (char *)"stop", (char *)""); - if (result == NULL) { - PyErr_Print(); - return; + if (!_session_terminated) { + if (_taskMgr != NULL) { + PyObject *result = PyObject_CallMethod(_taskMgr, (char *)"stop", (char *)""); + if (result == NULL) { + PyErr_Print(); + } else { + Py_DECREF(result); + } + } + + _session_terminated = true; } - Py_DECREF(result); - - _session_terminated = true; } ////////////////////////////////////////////////////////////////////