Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

DirectInput Force Feedback Issue

Posted on 2005-02-25
5
Medium Priority
?
730 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
  • 2
3 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

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Question has a verified solution.

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

Artificial Intelligence comes in many forms, and for game developers, Path-Finding is an important ability for making an NPC (Non-Playable Character) maneuver through terrain.  A* is a particularly easy way to approach it.  I’ll start with the algor…
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…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Screencast - Getting to Know the Pipeline
Suggested Courses

572 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