FleX icon indicating copy to clipboard operation
FleX copied to clipboard

Multiple callbacks for same stage

Open gaborpapp opened this issue 5 years ago • 2 comments

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?

gaborpapp avatar Jul 01 '19 14:07 gaborpapp

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

Cheers, Miles

mmacklin avatar Jul 02 '19 00:07 mmacklin

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 );
	}
}

gaborpapp avatar Jul 02 '19 05:07 gaborpapp