-
Notifications
You must be signed in to change notification settings - Fork 144
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
joystick Exception: E_HANDLE: Invalid handle (Console-only) #193
Comments
@cjroehrig How about including the exception and traceback in this bug report? FWIW I haven't looked into FreePIE for a long time but this could easily be the case where the |
@MarijnS95 Here's the output with traceback. Not much more info than what I described. Line 4 is the
|
That's unfortunate (but expected). Would you be able to attach the Visual Studio debugger and catch a C# exception (with stacktrace) before it bubbles to the Python engine? |
I wonder if vjoy or dxinput plugins are trying to get the hwnd from the host application and fails for the console |
@AndersMalmgren That's likely it, or we're resolving and passing it incorrectly somewhere. I had a personal console application utilizing vjoy and dxinput long ago and that worked just fine, and iirc had to pass |
Point of interest to investigate when debugging var handle = Process.GetCurrentProcess().MainWindowHandle;
|
Checked it, I was using the exact same EDIT: Is it possible that we're re-opening the console in some way, voiding this Window handle? Or otherwise spawning it after initialzing the plugin? Seems far-fetched, better wait for a C# trace. |
I just tried (without vjoy mind you) and I get a handle and I can read values from my gampad |
I'll tackle the C# trace in a couple days when I get a chance to sit down and figure out VisualStudio (I'm a unix guy). |
I got it to run within VisualStudio by opening up the FreePIE.Console.csproj file, editing the FreePIE.Console Debug properties to give the path to my test.py in the command-line arguments, and selecting Debug > Start without Debugging, but I get:
I've never used the GUI version of Visual Studio or debugged with it. I originally compiled FreePIE using the command-line BuildTools but it seems like VS-GUI isn't building the same thing and is missing the FreePIE globals (i.e. 'joystick', etc). Can you give me some tips about how to build the FreePIE.Console using the VisualStudio GUI? |
The console project is not mainted as properly as the GUI. In the properties for the plugin project change the build output path from the GUI to the console project That shuld do the trick |
Here is the traceback. After finally getting it to build correctly, it turns out the error doesn't happen when debugging under VS, so I inserted WriteLine(e.StackTrace) in all the catch blocks I could find.
|
I added a WriteLine after this and indeed the handle is zero. MSDN says the handle is non-zero only if the process has a GUI. |
I tried wrapping the SetCooperativeLevel call in JoystickPlugin.cs with a null check:
and I no longer get the E_HANDLE error, but don't get any joystick events either. I'll look into how to access DirectInput devices from console windows... |
I got things working by calling joystick.Poll() in JoystickState if the window handle is null. Here's my patch: |
Ah ok, when debugging you get the vs handle :) I will see what I can do |
I looked at your patch, but I cant get it to work. I removed And refactored the state code so now it does public JoystickState State
{
get { return state; }
}
public void Reset()
{
joystick.Poll();
state = joystick.GetCurrentState();
} Stil get the handle error |
I only do the Poll() if window handle was null when originally enumerating the devices in CreateGlobal (which indicates it is not a GUI app). I remember that and save it in a new private variable The idea with the Poll is that there is no event loop in a Console app, so you need to poll it every time you want to get the state (i.e. in State()). (I looked at the SlimDX code and GetCurrentState only returns the a copy of the current state, it doesn't update it.) I'm guessing that this issue will affect every other DirectX plugin that doesn't do polling, but at least it is a template for a solution. Here is the entire patched file: |
This error only happens in the Console version (v1.11.731.0 compiled with VisualStudio 2019) running on Windows 10v1903.
When run under the GUI, it works fine. I've had no other issues with the Console version (using mouse, keyboard, vJoy, etc). It happens even when run as administrator.
My attached joysticks are a vJoy (2.1.9) and an EDTracker 2.
It also happens when I attach and try to access a Logitech Wingman by name or index.
I diff'd the FreePIE source vs an older version (1.9.633.0) that was working (under Win7) and the only changes that seem promising are some changes to how the GlobalIndexer works and how the JoystickPlugin uses it (but I can't see anything specific to the Console version). When I get a chance I'll revert those and see if it fixes it.
Here's a simple example to demonstrate the issue (ensure at least one joystick is attached):
Using the Console version, I get the E_HANDLE exception and a traceback. Using the GUI it exits with no error.
The text was updated successfully, but these errors were encountered: