AttachEngine: fix crash when referenced objects get deleted
... by verifying if the pointers equal to objects contained in all open documents. Not terribly good, but I can't think of a situation where doing this search might cause trouble.
This commit is contained in:
parent
2d8a7614c5
commit
71f70eb855
|
@ -111,6 +111,7 @@ Py::Object AttachEnginePy::getReferences(void) const
|
|||
{
|
||||
try {
|
||||
AttachEngine &attacher = *(this->getAttachEnginePtr());
|
||||
AttachEngine::verifyReferencesAreSafe(attacher.references);
|
||||
return Py::Object(attacher.references.getPyObject(),true);
|
||||
} ATTACHERPY_STDCATCH_ATTR;
|
||||
}
|
||||
|
@ -523,6 +524,7 @@ PyObject* AttachEnginePy::writeParametersToFeature(PyObject* args)
|
|||
}
|
||||
Part::AttachableObject* feat = static_cast<Part::AttachableObject*>(dobj);
|
||||
const AttachEngine &attacher = *(this->getAttachEnginePtr());
|
||||
AttachEngine::verifyReferencesAreSafe(attacher.references);
|
||||
feat->Support.Paste(attacher.references);
|
||||
feat->MapMode.setValue(attacher.mapMode);
|
||||
feat->MapReversed.setValue(attacher.mapReverse);
|
||||
|
|
|
@ -61,6 +61,8 @@
|
|||
#include "Attacher.h"
|
||||
#include <Base/Console.h>
|
||||
#include <App/OriginFeature.h>
|
||||
#include <App/Application.h>
|
||||
#include <App/Document.h>
|
||||
|
||||
using namespace Part;
|
||||
using namespace Attacher;
|
||||
|
@ -749,6 +751,7 @@ void AttachEngine::readLinks(const App::PropertyLinkSubList &references,
|
|||
std::vector<TopoDS_Shape> &storage,
|
||||
std::vector<eRefType> &types)
|
||||
{
|
||||
verifyReferencesAreSafe(references);
|
||||
const std::vector<App::DocumentObject*> &objs = references.getValues();
|
||||
const std::vector<std::string> &sub = references.getSubValues();
|
||||
geofs.resize(objs.size());
|
||||
|
@ -830,6 +833,23 @@ void AttachEngine::throwWrongMode(eMapMode mmode)
|
|||
throw Base::Exception(errmsg.str().c_str());
|
||||
}
|
||||
|
||||
void AttachEngine::verifyReferencesAreSafe(const App::PropertyLinkSubList &references)
|
||||
{
|
||||
const std::vector<App::DocumentObject*> links = references.getValues();
|
||||
const std::vector<App::Document*> docs = App::GetApplication().getDocuments();
|
||||
for(App::DocumentObject* lnk : links){
|
||||
bool found = false;
|
||||
for(App::Document* doc : docs){
|
||||
if(doc->isIn(lnk)){
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
if (!found){
|
||||
throw Base::Exception("AttachEngine: verifyReferencesAreSafe: references point to deleted object.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//=================================================================================
|
||||
|
||||
|
|
|
@ -342,6 +342,12 @@ public://helper functions that may be useful outside of the class
|
|||
|
||||
static GProp_GProps getInertialPropsOfShape(const std::vector<const TopoDS_Shape*> &shapes);
|
||||
|
||||
/**
|
||||
* @brief verifyReferencesAreSafe: checks if pointers in references still
|
||||
* point to objects contained in open documents. This guarantees the links
|
||||
* are valid. Throws Base::Exception if invalid links are found.
|
||||
*/
|
||||
static void verifyReferencesAreSafe(const App::PropertyLinkSubList& references);
|
||||
|
||||
public: //enums
|
||||
static const char* eMapModeStrings[];
|
||||
|
|
Loading…
Reference in New Issue
Block a user