prevent dangling pointers by clearing the active assembly after it was deleted

This commit is contained in:
Stefan Tröger 2013-10-21 21:49:54 +02:00
parent 64ec142d61
commit c1d799e831
2 changed files with 42 additions and 23 deletions

View File

@ -79,6 +79,16 @@ static PyObject * setActiveAssembly(PyObject *self, PyObject *args)
Py_Return; Py_Return;
} }
static PyObject* clearActiveAssembly(PyObject* self, PyObject* args) {
ActiveAsmObject = 0;
ActiveGuiDoc =0;
ActiveAppDoc =0;
ActiveVp =0;
Py_Return;
}
/* module functions */ /* module functions */
static PyObject* getActiveAssembly(PyObject* self, PyObject* args) static PyObject* getActiveAssembly(PyObject* self, PyObject* args)
{ {
@ -95,9 +105,14 @@ static PyObject * getActiveAssembly(PyObject *self, PyObject *args)
/* registration table */ /* registration table */
struct PyMethodDef AssemblyGui_Import_methods[] = { struct PyMethodDef AssemblyGui_Import_methods[] = {
{ "setActiveAssembly" ,setActiveAssembly ,METH_VARARGS, { "setActiveAssembly" ,setActiveAssembly ,METH_VARARGS,
"setActiveAssembly(AssemblyObject) -- Set the Assembly object in work."}, "setActiveAssembly(AssemblyObject) -- Set the Assembly object in work."
},
{ "getActiveAssembly" ,getActiveAssembly ,METH_VARARGS, { "getActiveAssembly" ,getActiveAssembly ,METH_VARARGS,
"getActiveAssembly() -- Returns the Assembly object in work."}, "getActiveAssembly() -- Returns the Assembly object in work."
},
{ "clearActiveAssembly" ,clearActiveAssembly ,METH_VARARGS,
"clearActiveAssembly() -- Removes the current active Assembly as object in work"
},
{NULL, NULL} /* end of table marker */ {NULL, NULL} /* end of table marker */
}; };

View File

@ -35,6 +35,8 @@
using namespace AssemblyGui; using namespace AssemblyGui;
extern Assembly::ItemAssembly* ActiveAsmObject;
PROPERTY_SOURCE(AssemblyGui::ViewProviderItemAssembly,AssemblyGui::ViewProviderItem) PROPERTY_SOURCE(AssemblyGui::ViewProviderItemAssembly,AssemblyGui::ViewProviderItem)
ViewProviderItemAssembly::ViewProviderItemAssembly() ViewProviderItemAssembly::ViewProviderItemAssembly()
@ -43,6 +45,8 @@ ViewProviderItemAssembly::ViewProviderItemAssembly()
ViewProviderItemAssembly::~ViewProviderItemAssembly() ViewProviderItemAssembly::~ViewProviderItemAssembly()
{ {
if(getObject() == ActiveAsmObject)
Gui::Command::doCommand(Gui::Command::Doc,"AssemblyGui.clearActiveAssembly()");
} }
bool ViewProviderItemAssembly::doubleClicked(void) bool ViewProviderItemAssembly::doubleClicked(void)