Call for Submission
NAB 2012 Best of the Best Show Reel
Submit your work today!
  • 1/3
You are here: Forum Home / Autodesk® Softimage® / XSI SDK / Operator Callbacks and Object User Data (C++)
  RSS 2.0 ATOM  

Operator Callbacks and Object User Data (C++)
Rate this thread
 
36080
 
Permlink of this thread   Subscribe to this thread
avatar
  • MaxFox
  • Posted: 28 October 2009 06:15 AM
  • Location: St. Peterburg
  • Total Posts: 5
  • Joined: 29 November 2008 05:54 AM

Greetings to all. I cannot solve a problem of use UserData in some Operator Callback Functions.
In <> _Init () Callback, I initialize structure as it is specified in SDK:

class CData
{
public:
   
LONG data;   
};
......
XSIPLUGINCALLBACK CStatus OperNameCPP1_Init( CRefin_ctxt )
{
   OperatorContext ctxt( in_ctxt ) 
;
   
CData= new CData;
   
p->data 123;
   
CValue cval (CValue::siPtrType) p;

 
ctxt.PutUserData( cval ) ;
   return 
CStatus::OK;
}

In <> _Update () Callback, I use this structure, and I change data:

XSIPLUGINCALLBACK CStatus OperNameCPP1_Update( CRefin_ctxt )
{
 OperatorContext ctxt( in_ctxt ) 
;
        
CDatap;
 
CValue cval ctxt.GetUserData()
 p 
(CData*)(CValue::siPtrType) cval;
 
Application().LogMessage(L"value user is: "+CValue( p->data ) )
 p
->data++;
 return 
CStatus::OK;
}

- And all works perfectly.
But at attempt to use this structure and to change data in
<> _Define () Callback or <> _PPGEvent Callback - XSI is crashing.

XSIPLUGINCALLBACK CStatus OperNameCPP1_PPGEvent(  CRefin_ctxt )
{
        PPGEventContext ctxt( in_ctxt ) 
;
 
//OperatorContext ctxtOp( in_ctxt )  [b]- a'm trying this[/b]
 //Context ctxtOp2( in_ctxt )        [b]-and  a'm trying this[/b]
   
PPGEventContext::PPGEvent eventID ctxt.GetEventID() ;
      if 
( eventID == PPGEventContext::siButtonClicked )
 {
          CData
p=nullptr;
 
CValue cval ctxt.GetUserData()
 p 
(CData*)(CValue::siPtrType) cval;
 
p->data++;        [b]// - Crash from this line !!!![/b]
        
}
}

In what there can be a reason? I tried to write down in UserData not the structure index, in usual data CValue (), but also they do not write/read in <> _Define () and <> _PPGEvent Callbacks



Replies: 0
avatar
  • mabxsi
  • Posted: 16 May 2010 04:07 PM

It’s probably a bug. You can try using the Set/GetGlobal command as a workaround.

-mab



Replies: 0
avatar
  • mslaf
  • Posted: 18 May 2010 08:22 AM

CData* p=nullptr;
(...)
p = (CData*)(CValue::siPtrType) cval;

doesn’t make sense without if ( p == NULL ) or if ( !p ). Check if the returned pointer isn’t NULL (use debugger if necessary). For storing values of simple types use parameters and avoid using COM based commands in C++ at all cost.

EDIT1: Another thing, that could cause this bug is, that you’re dealing with different objects in first two functions and different one in the the third function - they all derive from the Context class but it doesn’t mean they all refer to the same object (in terms of memory allocation).



Replies: 0




   
  Settings Choose Theme color: