NVIDIAGameWorks / FleX

Other
670 stars 100 forks source link

ForceField issues (Debug v/s Release) #22

Open LRitesh opened 7 years ago

LRitesh commented 7 years ago

I'm running into a strange issue where I can get the radial Force Field working in Debug mode but not Release (VS 2015, Windows 10). There is probably something wrong on my side, but I've been at it for a while now and still can't fix it. Just wanted to throw it out there and see if anyone had any ideas.

Here's the relevant code:

In setup:

    // init force field
    mForceField = NvFlexExtForceField();
    ( vec3& )mForceField.mPosition = vec3( 0.0f );

    mForceField.mRadius = 100.0f;
    mForceField.mStrength = 30.0f;
    mForceField.mMode = eNvFlexExtModeForce;
    mForceField.mLinearFalloff = true;

    if( mForceFieldCallBack ) {
        NvFlexExtDestroyForceFieldCallback( mForceFieldCallBack );
    }

    mForceFieldCallBack = NvFlexExtCreateForceFieldCallback( mSolver );

and in the update loop

        // set force field
    NvFlexExtSetForceFields( mForceFieldCallBack, &mForceField, 1 );

    // unmap buffers
    NvFlexUnmap( positions );
    NvFlexUnmap( velocities );
    NvFlexUnmap( phases );

    // set active particles
    NvFlexBuffer* activeBuffer = NvFlexAllocBuffer( mLibrary, particleCount, sizeof( int ), eNvFlexBufferHost );

        int* activeIndices = ( int* )NvFlexMap( activeBuffer, eNvFlexMapWait );

    for( int i = 0; i < particleCount; ++i ) {
        activeIndices[i] = i;
    }

    NvFlexUnmap( activeBuffer );

    NvFlexSetActive( mSolver, activeBuffer, NULL );
    NvFlexSetActiveCount( mSolver, particleCount );

    // write to device (async)
    NvFlexSetParticles( mSolver, positions, NULL );
    NvFlexSetVelocities( mSolver, velocities, NULL );
    NvFlexSetPhases( mSolver, phases, NULL );

    // do flex update
    NvFlexUpdateSolver( mSolver, elapsed, 1, false);

    // get particle positions and velocities
    NvFlexGetParticles( mSolver, positions, NULL );
    NvFlexGetVelocities( mSolver, velocities, NULL );
    NvFlexGetPhases( mSolver, phases, NULL );

Thanks!