Sign in to follow this  
bradknox

Runtime error -- DirectInput Force Feedback in C#

Recommended Posts

bradknox    122
I'm trying to implement a simple loop that sends a constant force to my Logitech Force 3D Pro joystick. I'm using C# and DirectInput. I'm getting an error that I don't know how to debug. I'm getting the following exception: Exception: System.ArgumentException: Value does not fall within the expected range. at Microsoft.DirectX.DirectInput.EffectObject.InternalCreate(Guideff, Effect& die, Device dev) at Microsoft.DirectX.DirectInput.EffectObject..ctor(Guid eff, Effect die, Device dev) at WindowsApplication1.Form1.ffEffect() at the starred line in the code below: private void ffEffect() { ffAxes[0] = 5000; //See if joystick supports ConstantForce and set it. EffectObject eo = null; Effect e; foreach (EffectInformation ei in joystick.GetEffects(EffectType.All)) { //If the joystick supports ConstantForce, then apply it. if (DInputHelper.GetTypeCode(ei.EffectType) == (int)EffectType.ConstantForce) { // Fill in some generic values for the effect. e = new Effect(); e.SetDirection(new int[ffAxes.Length]); e.SetAxes(new int[ffAxes.Length]); e.ConditionStruct = new Condition[ffAxes.Length]; e.EffectType = EffectType.ConstantForce; e.Duration = (int)DI.Infinite; e.Gain = 10000; e.SamplePeriod = 0; e.TriggerButton = (int)Microsoft.DirectX.DirectInput.Button.NoTrigger; e.TriggerRepeatInterval = (int)DI.Infinite; e.Flags = EffectFlags.ObjectOffsets | EffectFlags.Cartesian; e.SetAxes(ffAxes); // Create the effect, using the passed in guid. try { Debug.WriteLine("ei.EffectGuid: " + ei.EffectGuid.ToString()); Debug.WriteLine("e: " + e.ToString()); Debug.WriteLine("joystick: " + joystick.ToString()); ******** eo = new EffectObject(ei.EffectGuid, e, joystick); } catch (ArgumentException ae) { Debug.WriteLine("Exception: " + ae); } } } if (eo == null) { throw new Exception("ConstantForce is not supported."); } } I can't figure out how to debug this further. It could be any of those three arguments, and the argument "e" has many member variables (if that's the right word). Also, the exception states "Value does not fall within the expected range". Is there any way to find out what value and what the expected range is? I think the problem has something to do with the comment "Fill in some generic values for the effect.", but proper values are not really defined in the documentation. The values printed before the exception are: ei.EffectGuid: 13541c20-8e33-11d0-9ad0-00a0c9a06e35 e: EffectType: ConstantForce UsesEnvelope: False StartDelay: 0 TriggerRepeatInterval: -1 TriggerButton: -1 Gain: 10000 SamplePeriod: 0 Duration: -1 Flags: ObjectOffsets, Cartesian EnvelopeStruct: FadeTime: 0 FadeLevel: 0 AttackTime: 0 AttackLevel: 0 CustomStruct: Samples: 0 SamplePeriod: 0 Channels: 0 Periodic: Period: 0 Phase: 0 Offset: 0 Magnitude: 0 Constant: Magnitude: 0 ConditionStruct: Microsoft.DirectX.DirectInput.Condition[] RampStruct: End: 0 Start: 0 joystick: Microsoft.DirectX.DirectInput.Device Any advice on this would be great. I'm currently stuck trying to get this working before being able to move on to more interesting things. Thanks!!!!!

Share this post


Link to post
Share on other sites
bradknox    122
It looks like this is a DirectX problem. I found some other forums that have mentioned it.

Here's one:
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1277362&SiteID=1

This claims to have a fix, but it didn't work for me.
http://graphicdna.blogspot.com/2007/01/managed-directinput-samples-bugs.html

It's too bad that Microsoft hasn't fixed a bug that's been known for at least a year and a half.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this