On 25/06/2015 at 08:00, xxxxxxxx wrote:
I have to note, the code I posted is not his code.
I might have mixed up some code from GVO and Message.
I've tested it now in GVO with a proper return (I was looking at some own code where I apply currentstatetoobject, but inside MSG_COMMAND (where it is allowed to insert objects), sorry for the confusion!) and it still crashes.
cd.doc = doc
This needs to be there, or the modelingcommand fails.
Either this: cd.doc = doc OR cd.doc = hh->GetDocument().
This is my code inside GVO (again, not from bamboudha, it may differ) (the concept should be the same) :
BaseObject* MyObjectData::GetVirtualObjects(BaseObject* op, HierarchyHelp* hh)
BaseDocument* doc = hh->GetDocument();
BaseObject* cube = BaseObject::Alloc(Ocube);
if (!cube) return nullptr;
cd.doc = doc;
cd.op = cube;
if (!SendModelingCommand(MCOMMAND_MAKEEDITABLE, cd))
cubeRes = static_cast<BaseObject*>(cd.result->GetIndex(0));
if (!cubeRes) return nullptr;
polyCube = (PolygonObject* )cubeRes;
if (!polyCube) return nullptr;
If he has something like this, or if he maybe inserts this in a parent, and returns the parent, it's the same as my approach.
And I have the crash as well if I try to free my cube.
Feel free to test it yourself...
I was wondering that maybe the ModelingCommand would free it itself, but that makes no sense, I guess, because with MCOMMAND_CURRENTSTATETOOBJECT you have to free it.
Maybe some input from the moderators would be nice?