Jump to content

Issue with SpareParms and callback functions


Recommended Posts

Greetings!

I have recently started using the hdk to build a custom plug-in (which consist of a SOP Node that modify a heightfield) and I have encountered a deadend (actually more than one, but this forum provided me a lot of help ^^)

In a few words, I am creating a SpareParm by getting the OP_Director (OPgetDirector()) and adding a PRM_Template with method addNodeSpareParm(). My issue is that if I provide a callback function, it is not called back (no result and in debug mode, any breakpoints in the callback function are never reached). I have no issue with parameters normally given when creating the node (I mean when using the newSopOperator() function, a button parameter call back its function correctly).

To fully explain my process: I am creating a node with a path parameter (PRM_File) where I can provide a custom file. This custom file is read and depending on its content, I need to add parameters to the node. From my researches, SpareParms were the only approach suitable. Maybe I am wrong and I will be grateful if you can point me in the direction of a better method.

For instance, this file could give me the parameter ‘width’ with a range and the node would create an integer parameter that would make possible to change the width of the input heightfield.

But the SpareParms that are created do not seem to call the cookMySop() function when modified and adding a callback function that would use the forceRecook() function is not called (as explain above).

Does this issue ring any bell?

Thanks in advance

Luc

Link to comment
Share on other sites

  • 2 weeks later...

Up ! ^^

I went to write a small SOP node that show my issue. It should be ok to compile it with hcustom. This SOP simply has a button (Button1), that when clicked create a new button (Button2, as a SpareParm) with a callback method to create a new buton (button3). But Button3 is never created.

void
newSopOperator(OP_OperatorTable* table)
{
    table->addOperator(new OP_Operator(
        "testSpareParm",
        "TestSpareParm",
        SOP_TestSpareParm::myConstructor,
        SOP_TestSpareParm::myTemplateList,
        1,
        1,
        NULL));
}

static int buttonCallBack2(void* data, int index, fpreal t, const PRM_Template*)
{
    SOP_TestSpareParm* me = static_cast<SOP_TestSpareParm*>(data);

    if (!me)
        return 0;

    OP_Director* director = OPgetDirector();

    PRM_Name bn = PRM_Name("button3", "Button3");
    PRM_Template button = PRM_Template(PRM_CALLBACK, 1, &bn, 0, 0, 0);
    director->addNodeSpareParm(me, &button);

    return 1;
}

static int buttonCallBack(void* data, int index, fpreal t, const PRM_Template*)
{
    SOP_TestSpareParm* me = static_cast<SOP_TestSpareParm*>(data);

    if (!me)
        return 0;

    OP_Director* director = OPgetDirector();

    PRM_Name bn = PRM_Name("button2", "Button2");
    PRM_Template button = PRM_Template(PRM_CALLBACK, 1, &bn, 0, 0, 0, buttonCallBack2);
    director->addNodeSpareParm(me, &button);
    
    return 1;
}

static PRM_Name names[] = {
    PRM_Name("button1",    "Button1"),
};

PRM_Template SOP_TestSpareParm::myTemplateList[] = {

    PRM_Template(PRM_CALLBACK,    1, &names[0], 0, 0, 0, buttonCallBack),
    PRM_Template(),
};

OP_Node* SOP_TestSpareParm::myConstructor(OP_Network* net, const char* name, OP_Operator* op)
{
    return new SOP_TestSpareParm(net, name, op);
}

SOP_TestSpareParm::SOP_TestSpareParm(OP_Network* net, const char* name, OP_Operator* op) : SOP_Node(net, name, op)
{
    mySopFlags.setManagesDataIDs(true);
}

SOP_TestSpareParm::~SOP_TestSpareParm() {}

OP_ERROR SOP_TestSpareParm::cookMySop(OP_Context& context)
{
    OP_AutoLockInputs inputs(this);
    if (inputs.lock(context) >= UT_ERROR_ABORT)
        return error();

    fpreal now = context.getTime();

    return error();
}

 

Do you see something wrong with theses few lines ?

Cheers !

SOP_TestSpareParm.C

SOP_TestSpareParm.h

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...