-
Notifications
You must be signed in to change notification settings - Fork 82
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
Assertion / Illegal instruction on macOS when calling HidApi::new
in different threads
#127
Comments
Hi! Because of the not very well defined nature of the underlying C library (regarding multithreading), we used to prevent creating a second instance of a Hidapi object, by acquiring a lock. Unfortunately we may have not tested on macos (due to nobody owning a mac). I recommend you look at the hidapi C library if it should be possible to use it from multiple threads in macos. B.t.w. it could totally be, that the problem only occurs because you are not on the main thread. I have some experience in the far past with macos not allowing certain things on a normal spawned thread (IO related & gpu related). If it really can not work, I will probably add a check just for macos to not allow creating more than one API instance. |
Unfortunately, running everything on the main thread is not possible for my use case. I've had a look at the library, and found some existing issues which might be related:
I've tried to use The workaround I have for now is to spawn a dedicated thread for My current assumption is that this line https://github.com/libusb/hidapi/blob/d0856c05cecbb1522c24fd2f1ed1e144b001f349/mac/hid.c#L443 associates the I'll hopefully find some time to work on a proper fix for this, either directly in |
That's correct, When This is much easier to manage from Rust (#30), where you could have an |
Stumbled on the same issue when using hidapi 2.4.1. In my application new thread is created each time when somebody wants to do something with the device.
So I added another thread to std::thread::spawn(|| {
let _hid = hidapi::HidApi::new();
loop {
std::thread::sleep(std::time::Duration::from_secs(3600));
}
}); |
Just wanted to note that I have reached the same endpoint with hidapi on MacOS Sequia 15.1. I cannot run this line inside egui without it crashing:
|
I've run into an issue on macOS where calling
HidApi::new
from different threads leads to an abort of the process, with an exception for an illegal instruction.Looking at the stacktrace, it seems to be cause by a
CFAssertMismatchedTypeID
assertion somewhere in Core Foundation.Are there any special precautions that have to be taken when using
hidapi
from multiple threads? I couldn't find anything in the documentation.Stacktrace
Repo with code to reproduce: https://github.com/tiwalun/hidapi-repro
The text was updated successfully, but these errors were encountered: