Hi guys. Yesterday i mention problem with userdata in Operators. I thought that each time i PutUserData to an OperatorContext it lies in this object instance, and each Operator would have its own UserData, with its own allocated memory for data structure. But as i said yesterday i mention that its not. The 1st Operator added to modelling stack would have pointer to 1st allocated dynamic memory in UserData. The 2nd Operator added to modelling stack would have 1st AND 2nd allocated dynamic memory in UserData. And so on. So i can't find out why does it happen. I wrote simple dummy plugin, to demonstrate the problem. This plugin simply create Operator and apply it to selected object edges.
To reproduce this problem select edge-loop and run: Application.avDuplicateStart() Then select another one edge-loop and run it again: Application.avDuplicateStart() And you see that on a second run it would print to log both pointers to allocated memory from UserData ( currently and previously applied ). On a third run it would print three of them and so on. Here is the source code of dummy plugin: https://www.dropbox.com/sh/pi33a9l8miilu1o/AAAftxU3ppDXo7_j2CxWCOK1a?dl=0 And here is a part of Operator callbacks: SICALLBACK avDuplicate_Init( CRef& in_ctxt ) { Application().LogMessage(L"Operator: init callback "); OperatorContext opCtxt( in_ctxt ); //std::shared_ptr<OperatorData> opDataPtr (new OperatorData); // create pointer to struct OpData allocated for curent CustomOperator in dynamic memory OperatorData* opDataPtr = new OperatorData; CValue opptrValue = (CValue::siPtrType) opDataPtr; OperatorData& opData = (*opDataPtr); opCtxt.PutUserData( opptrValue ); // set default value opData.merge = false; Application().LogMessage(L" [init] ptrValue" + CValue(opptrValue).GetAsText()); return CStatus::OK; } SICALLBACK avDuplicate_Define( CRef& in_ctxt ) { Application().LogMessage(L"Operator: define callback "); Context ctxt( in_ctxt ); CustomOperator oCustomOperator; Parameter oParam; CRef oPDef; Factory oFactory = Application().GetFactory(); oCustomOperator = ctxt.GetSource(); //! CUSTOMOPERATOR PARAMETERS: oPDef = oFactory.CreateParamDef(L"merge",CValue::siBool,siPersistable | siKeyable,L"",L"",CValue(false),0,1,0,1); oCustomOperator.AddParameter(oPDef,oParam); oCustomOperator.PutAlwaysEvaluate(true); oCustomOperator.PutDebug(0); return CStatus::OK; } SICALLBACK avDuplicate_Update( CRef& in_ctxt ) { Application().LogMessage(L"Operator: update callback "); OperatorContext opCtxt( in_ctxt ) ; CValue opptrValue = opCtxt.GetUserData(); OperatorData* opDataPtr = (OperatorData*)(CValue::siPtrType)opptrValue; OperatorData& opData = (*opDataPtr); // we would toggle this value to differentiate applied Operators opData.merge = opCtxt.GetParameterValue(L"merge"); Application().LogMessage(L" [update] ptrValue: " + CValue(opptrValue).GetAsText()); Application().LogMessage(L" [update] opData.merge: " + CValue(opData.merge).GetAsText()); return CStatus::OK; } SICALLBACK avDuplicate_Term( CRef& in_ctxt ) { Application().LogMessage(L"Operator: term callback "); OperatorContext opCtxt( in_ctxt ) ; CValue opptrValue = opCtxt.GetUserData(); OperatorData* opDataPtr = (OperatorData*)(CValue::siPtrType)opptrValue; delete opDataPtr; return CStatus::OK; }
------ Softimage Mailing List. To unsubscribe, send a mail to [email protected] with "unsubscribe" in the subject, and reply to confirm.

