Search code examples
c++eventsattributesnodesmaya

deleteNode in Maya Api crashes Maya in Viewport 2.0


I have a Maya api cpp code that creates many MPxLocators of the same instance.

initializePlugin function:

pluginFn.registerNode(
      "unitNode",
       unitNode::id,
       &unitNode::creator,
       &unitNode::initialize,
       MPxNode::kLocatorNode,
       &unitNode::drawDbClassification);

    MHWRender::MDrawRegistry::registerDrawOverrideCreator(
     unitNode::drawDbClassification,
     unitNode::drawRegistrantId,
     unitNodeDrawOverride::Creator);

Node Creation function:

MDagModifier dagMod;
for (int i=0;i<100;i++)
     externalClass->objArray[i]=dagMod.createNode("unitNode", MObject::kNullObj);

Deletion (launched from node #15 for example after attribute change):

MDGModifier mdg;
mdg.deleteNode(externalClass->objArray[99]);

When a specific attribute is changed in one of these locators, I delete another given locator (so never itself). The MDGModifer::deleteNode function goes well, but maya then crashes instantaneously (only in Viewport 2.0, not in regular viewPort).

My assumption is that Maya still has in its queue to launch the prepareForDraw and draw functions for all locators, but as I deleted one of them, Maya is crashing. How can I safely delete a node following an attribute change ?


Solution

  • I ended up in using MGlobal::executeCommand("delete <nodename>"); which doesn't crash maya. It seems to do something else than the deleteNode api.