?
Solved

DirectInput Force Feedback Issue

Posted on 2005-02-25
5
Medium Priority
?
712 Views
Last Modified: 2013-12-26
Having a problem initializing the LPDIRECTINPUTEFFECT object.  Program crashes when attemping to start effect.  Code is as follows (the Vertex getX( ) function returns a float):

void HapticSystem::generateForce(Vertex* v, float magnitude) {
      
    DIEFFECT eff;
      DICONSTANTFORCE cf;
      LPDIRECTINPUTEFFECT g_pEffect;


      LONG     rglDirection[3] = { (LONG)v->getX(), (LONG)v->getY(), (LONG)v->getZ() };  
      DWORD    rgdwAxes[3]     = { DIJOFS_X, DIJOFS_Y, DIJOFS_Z};
      
      cf.lMagnitude = (LONG)magnitude;

      ZeroMemory(&eff, sizeof(eff));

      eff.cAxes                              = 3;
      eff.dwSize                  = sizeof(DIEFFECT);
    eff.dwFlags                 = DIEFF_CARTESIAN | DIEFF_OBJECTOFFSETS;
    eff.dwDuration              = INFINITE;
    eff.dwSamplePeriod          = 0;
    eff.dwGain                  = DI_FFNOMINALMAX;
    eff.dwTriggerButton         = DIEB_NOTRIGGER;
    eff.dwTriggerRepeatInterval = 0;
    //eff.cAxes                   = g_dwNumForceFeedbackAxis;
    eff.rgdwAxes                = rgdwAxes;
    eff.rglDirection            = rglDirection;
    eff.lpEnvelope              = 0;
    eff.cbTypeSpecificParams    = sizeof(DICONSTANTFORCE);
    eff.lpvTypeSpecificParams   = &cf;
    eff.dwStartDelay            = 0;

      
      devices[0]->CreateEffect( GUID_ConstantForce, &eff, &g_pEffect, NULL );
      
                g_pEffect->Start( 1, 0);
      
      return;
}
0
Comment
Question by:system
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
5 Comments
 
LVL 17

Expert Comment

by:davebytes
ID: 13411147
Did you try error checking at all?

if (devices[0]==NULL) ... handle it
HRESULT result = devices[0]->CreateEffect...
if (result!=S_OK) ... handle it
if (g_pEffect==NULL) ... handle it
// then...
g_pEffect->Start()

I haven't touched DI effects in about two years, so I'm just going with general programming approach to debug.

It is possible that you are getting an error back from the CreateEffect, and not checking that it is ok and that the g_pEffect pointer is actually valid before referencing it.  General rule of thumb is, even if done with DEBUG only wrappering, always have a build that can do full error checking of return results and allocated/created objects.

If that doesn't show any issue, write back, and I can maybe sanity-check the parameter block.

-d
0
 

Author Comment

by:system
ID: 13412234
I have adjusted the code accordingly .. .albeit it a hack fix to show the source of the problem
The code executes to completion but always outputs cout   UNABLE TO START THE FORCE FEEDBACK EFFECT \n
everytime its called. I realize it has something to do with my init of g_peffect but I am at a loss
of what the error is as my syntax matches examples given in samples of the directX SDK.


void HapticSystem::generateForce(Vertex* v, float magnitude){
      
    DIEFFECT eff;
      DICONSTANTFORCE cf;
      LPDIRECTINPUTEFFECT g_pEffect;


      LONG     rglDirection[3] = { (LONG)v->getX(), (LONG)v->getY(), (LONG)v->getZ() };  // Positive x = east
      DWORD    rgdwAxes[3]     = { DIJOFS_X, DIJOFS_Y, DIJOFS_Z};  // X- and y-axis
      
      cf.lMagnitude = (LONG)magnitude;

      ZeroMemory(&eff, sizeof(eff));

      eff.cAxes                              = 3;      // Three axes
      eff.dwSize                  = sizeof(DIEFFECT);
    eff.dwFlags                 = DIEFF_CARTESIAN | DIEFF_OBJECTOFFSETS;
    eff.dwDuration              = INFINITE;
    eff.dwSamplePeriod          = 0;
    eff.dwGain                  = DI_FFNOMINALMAX;
    eff.dwTriggerButton         = DIEB_NOTRIGGER;
    eff.dwTriggerRepeatInterval = 0;
    //eff.cAxes                   = g_dwNumForceFeedbackAxis;
    eff.rgdwAxes                = rgdwAxes;
    eff.rglDirection            = rglDirection;
    eff.lpEnvelope              = 0;
    eff.cbTypeSpecificParams    = sizeof(DICONSTANTFORCE);
    eff.lpvTypeSpecificParams   = &cf;
    eff.dwStartDelay            = 0;

      devices[0]->CreateEffect( GUID_ConstantForce, &eff, &g_pEffect, NULL );

      if (devices[0]==NULL) {
            cout << "  DEVICES ENUMERATION HAS FAILED \n";

            if (g_pEffect==NULL) {
            cout << "  EFFECT FAILED \n";
            }
      
            return;
      }

// then...
      

      //g_pEffect->SetParameters( &eff, DIEP_DIRECTION | DIEP_TYPESPECIFICPARAMS | DIEP_START );
      
      if ( g_pEffect ) {
      
            cout << "  STARTING THE FORCE FEEDBACK EFFECT \n";
            g_pEffect->Start( 1, 0);

      }
      else
            cout << "  UNABLE TO START THE FORCE FEEDBACK EFFECT \n";
      
      return;
}
0
 
LVL 17

Accepted Solution

by:
davebytes earned 1000 total points
ID: 13412996
You didn't do ALL of my suggestions.. ;) ;)

HRESULT result = devices[0]->CreateEffect...
if (result!=S_OK) ... handle it

Check the DX sdk for the error result codes from that function, put a breakpoint in or a debug output, and see what the error really is.  That's a necessary starting point, but should tell you something.  Usually -- sometimes it's a generic error code, which tells zilch.

Also, have you tried running some of the FF samples in the SDK?  If they don't work on your machine, that'd tell you something as well.  If they do work, they're another comparison source for finding what's wrong.

-d
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

As game developers, we quickly learn that Artificial Intelligence (AI) doesn’t need to be so tough.  To reference Space Ghost: “Moltar, I have a giant brain that is able to reduce any complex machine into a simple yes or no answer. (http://www.youtu…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question