NVIDIAGameWorks / FleX

Other
650 stars 100 forks source link

Multiple callbacks for same stage #87

Open gaborpapp opened 5 years ago

gaborpapp commented 5 years ago

I'd like to register two solver callbacks at update end, but it seems that the second callback deletes the first one. Is it not possible to use multiple callbacks at the same stage?

mmacklin commented 5 years ago

Sorry, no, you can only register one callback per-stage. But of course your callback can call the functions itself.

Cheers, Miles

gaborpapp commented 5 years ago

Thanks Miles.

I managed to solve it by chaining the calls using the data returned by NvFlexRegisterSolverCallback. It works if there's a callback registered before mine, but I'm not sure how to detect if there's no callback. What does NvFlexRegisterSolverCallback returns then? I was expecting that NvFlexSolverCallback userData and/or function is NULL, but it does not seem to work.

void NvFlexSetMyForces( NvFlexMyCallback *c, ... )
{
    ...

    NvFlexSolverCallback callback;
    callback.function = applyMyCallback;
    callback.userData = c;

    c->mPreviousCallback = NvFlexRegisterSolverCallback( c->mSolver, callback,
        eNvFlexStageUpdateEnd );
}

void applyMyCallback( NvFlexSolverCallbackParams params )
{
    NvFlexMyCallback *c = (NvFlexMyCallback *)params.userData;

    ...

    if ( c->mPreviousCallback.function != NULL )
    {
        params.userData = c->mPreviousCallback.userData;
        c->mPreviousCallback.function( params );
    }
}