sandervs / javahidapi

Automatically exported from code.google.com/p/javahidapi
Other
0 stars 0 forks source link

Closing hid device after writing causes Java vm to crash on Mac #61

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Open hid device
2. Write a couple messages to the device
3. Close the device
4. Repeat steps 1 through 3 until it crashes (see attached error log)

What is the expected output? What do you see instead?
I would expect that this does not crash the Java vm. Closing the hid device 
should never cause a crash but it is doing so occasionally. No Java exception 
is being thrown. If this is caused because a message is being written to the 
device while trying to close, there should be some way of determining that the 
operation is complete so it can be appropriately closed.

What version of the product are you using? On what operating system?
hidapi-1.1.jar on Mac OS X 10.9.3 (could not reproduce on Windows)

Please provide any additional information below.
The following is a sample application I used to reproduce the issue. The number 
of times through the loop before the crash occurs varies. Sometimes it happens 
after a few attempts but other times it will take 70 or so attempts to fail. 
Note that in the sample, the messages will need to be something specific to the 
hid device.

        int count = 1;
        HIDManager hidManager = null;

        try
        {
            ClassPathLibraryLoader.loadNativeHIDLibrary();
            hidManager = HIDManager.getInstance();

            while(true)
            {
                System.out.println(String.format("%d", count));

                HIDDeviceInfo[] hidDevices = hidManager.listDevices();

                for (HIDDeviceInfo deviceInfo : hidDevices)
                {
                    if (deviceInfo.getVendor_id() == <SOME_SPECIFIC_DEVICE_VENDOR_ID>)
                    {
                        System.out.println("Open");
                        HIDDevice device = deviceInfo.open();

                        if (device != null)
                        {
                            byte[] message1 = {0x00, 5, 0x02, 0x70, 0x33, 0x30, 0x03};
                            byte[] message2 = {0x00, 5, 0x04, 0x00, 0x06};
                            System.out.println("Write Messages");
                            device.write(message1);
                            device.write(message2);
                            device.close();
                            System.out.println("Closed Receiver");
                            break;
                        }
                    }
                }

                Thread.sleep(925);
                count++;
            }
        }
        catch (Exception ex)
        {
            System.out.println(ex.getMessage());
        }
        finally
        {
            if(hidManager != null)
            {
                hidManager.release();
            }
        }

Original issue reported on code.google.com by tgeo...@turningtechnologies.com on 7 Jul 2014 at 3:07