ganzo
12-22-2010, 07:11 PM
SOLVED
Ok I edited the post to make it easier to understand..
I have two nodes:
1. An MPxNode that has an output attribute sending an MPointArray, the amount of points are brought in through an input attribute.
2. An MPxLocatorNode with an input attribute receiving the MPointArray from the other node and displaying the point data through its draw function.
Debug mode: I can create both nodes and connect the output to input manually and all works. I can change the amount of points and the point array is passed on successfully to the locatorNode and the draw function updates the points correctly.
Release: If I follow the same steps taken during debug mode...that is create both nodes via "createNode" and then connect the output to input through the connection editor, maya crashes with "unhandled exception".
I populated the code with breakpoints to step through it in debug mode and looked at the debug output and there are no c++ exceptions or errors in each breakpoint around the precompute function when I connect the output to input attribute.
There is a "DoesNotExistException at memory location" on the output of my debug, but that shows up when I select the MPxLocatorNode. Still, like I said...during debug mode..everything works...it crashes on release version.
Here is the code for the MPxNode, sorry about the amount of status checks:
MObject node::a_Points;
MObject node::a_Amount;
MStatus node::initialize()
{
//-----------------------------------------------------------------
//Create input attribute a_Amount to get number of points.
MFnNumericAttribute nAttr;
a_Amount = nAttr.create("amount","amt",MFnNumericData::kInt,30,&status);
status = addAttribute(a_Amount);
//-----------------------------------------------------------------
// Create Output attribute of type MPointArray
MFnTypedAttribute tAttr;
a_Points = tAttr.create("outPoints","opnt",MFnData::kPointArray,&status);
status = addAttribute(a_Points);
//-----------------------------------------------------------------
//Create affect relationship a_Amount(input)->a_Points(output)
status = attributeAffects(a_Amount,a_Points);
return MS::kSuccess;
}
//#################################################################
//----------------------------------COMPUTE----------------------------------------
MStatus node::compute(const MPlug& plug, MDataBlock& data)
{
MStatus status;
if(plug != a_Points)
return MS::kUnknownParameter;
//-----------------------------------------------------------------
//Grab Inputs
MDataHandle h_aAmount = data.inputValue(a_Amount,&status);
int nAmount = h_aAmount.asInt();
//-----------------------------------------------------------------
//Grab Outputs
MDataHandle h_aPoints = data.outputValue(a_Points,&status);
MFnPointArrayData fn_aPoints;
MPointArray p_aPoints;
//--fill point array with data
MObject o_aPoints = fn_aPoints.create(p_aPoints,&status);
h_aPoints.set(o_aPoints);
status = data.setClean ( plug );
}
This is the code for the MPxLocatorNode:
MObject locatorNode::a_Points;
MObject locatorNode::a_PointsOut;
MStatus locatorNode::initialize()
{
MStatus status;
//---------------------------------------------------------------
//Create input attribute to receive point array
MFnTypedAttribute tAttr;
a_Points = tAttr.create("inPoints","ipnt",MFnData::kPointArray,&status);
status = addAttribute(a_Points);
//----------------------------------------------------------------
//Create output attribute - NOT USED REMOVED COMPUTE FUNCTION
MFnTypedAttribute oAttr;
a_PointsOut = tAttr.create("pointsOut","ptsO",MFnData::kPointArray,&status);
status = addAttribute(a_PointsOut);
//----------------------------------------------------------------
//Create affect relationship a_Points(input)->a_PointsOut(output)
status = attributeAffects(a_Points,a_PointsOut);
return MS::kSuccess;
}
//###################################################################
//--------------------------DRAW-------------------------------------
void CrackerGuideNode::draw( M3dView &view, const MDagPath &path, M3dView::DisplayStyle style, M3dView::DisplayStatus status )
{
view.beginGL();
MPointArray pts;
getPointData(pts);
//draw point data in array
view.endGL();
}
bool locatorNode::getPointData(MPointArray &pts) const
{
MStatus status;
MObject thisNode = thisMObject();
MPlug plug_aPoints(thisNode,a_Points);
MObject o_aPoints;
plug_aPoints.getValue(o_aPoints);
MFnPointArrayData fn_aPoints(o_aPoints);
fn_aPoints.copyTo(pts);
return true;
}
Ok I edited the post to make it easier to understand..
I have two nodes:
1. An MPxNode that has an output attribute sending an MPointArray, the amount of points are brought in through an input attribute.
2. An MPxLocatorNode with an input attribute receiving the MPointArray from the other node and displaying the point data through its draw function.
Debug mode: I can create both nodes and connect the output to input manually and all works. I can change the amount of points and the point array is passed on successfully to the locatorNode and the draw function updates the points correctly.
Release: If I follow the same steps taken during debug mode...that is create both nodes via "createNode" and then connect the output to input through the connection editor, maya crashes with "unhandled exception".
I populated the code with breakpoints to step through it in debug mode and looked at the debug output and there are no c++ exceptions or errors in each breakpoint around the precompute function when I connect the output to input attribute.
There is a "DoesNotExistException at memory location" on the output of my debug, but that shows up when I select the MPxLocatorNode. Still, like I said...during debug mode..everything works...it crashes on release version.
Here is the code for the MPxNode, sorry about the amount of status checks:
MObject node::a_Points;
MObject node::a_Amount;
MStatus node::initialize()
{
//-----------------------------------------------------------------
//Create input attribute a_Amount to get number of points.
MFnNumericAttribute nAttr;
a_Amount = nAttr.create("amount","amt",MFnNumericData::kInt,30,&status);
status = addAttribute(a_Amount);
//-----------------------------------------------------------------
// Create Output attribute of type MPointArray
MFnTypedAttribute tAttr;
a_Points = tAttr.create("outPoints","opnt",MFnData::kPointArray,&status);
status = addAttribute(a_Points);
//-----------------------------------------------------------------
//Create affect relationship a_Amount(input)->a_Points(output)
status = attributeAffects(a_Amount,a_Points);
return MS::kSuccess;
}
//#################################################################
//----------------------------------COMPUTE----------------------------------------
MStatus node::compute(const MPlug& plug, MDataBlock& data)
{
MStatus status;
if(plug != a_Points)
return MS::kUnknownParameter;
//-----------------------------------------------------------------
//Grab Inputs
MDataHandle h_aAmount = data.inputValue(a_Amount,&status);
int nAmount = h_aAmount.asInt();
//-----------------------------------------------------------------
//Grab Outputs
MDataHandle h_aPoints = data.outputValue(a_Points,&status);
MFnPointArrayData fn_aPoints;
MPointArray p_aPoints;
//--fill point array with data
MObject o_aPoints = fn_aPoints.create(p_aPoints,&status);
h_aPoints.set(o_aPoints);
status = data.setClean ( plug );
}
This is the code for the MPxLocatorNode:
MObject locatorNode::a_Points;
MObject locatorNode::a_PointsOut;
MStatus locatorNode::initialize()
{
MStatus status;
//---------------------------------------------------------------
//Create input attribute to receive point array
MFnTypedAttribute tAttr;
a_Points = tAttr.create("inPoints","ipnt",MFnData::kPointArray,&status);
status = addAttribute(a_Points);
//----------------------------------------------------------------
//Create output attribute - NOT USED REMOVED COMPUTE FUNCTION
MFnTypedAttribute oAttr;
a_PointsOut = tAttr.create("pointsOut","ptsO",MFnData::kPointArray,&status);
status = addAttribute(a_PointsOut);
//----------------------------------------------------------------
//Create affect relationship a_Points(input)->a_PointsOut(output)
status = attributeAffects(a_Points,a_PointsOut);
return MS::kSuccess;
}
//###################################################################
//--------------------------DRAW-------------------------------------
void CrackerGuideNode::draw( M3dView &view, const MDagPath &path, M3dView::DisplayStyle style, M3dView::DisplayStatus status )
{
view.beginGL();
MPointArray pts;
getPointData(pts);
//draw point data in array
view.endGL();
}
bool locatorNode::getPointData(MPointArray &pts) const
{
MStatus status;
MObject thisNode = thisMObject();
MPlug plug_aPoints(thisNode,a_Points);
MObject o_aPoints;
plug_aPoints.getValue(o_aPoints);
MFnPointArrayData fn_aPoints(o_aPoints);
fn_aPoints.copyTo(pts);
return true;
}
