Unity crashing when calling Connect() method
See original GitHub issueIn fact, I was probably a little too hasty when I said that “everything” worked. The scan works beautifully. However, when I try to connect a device with “ble.Connect()”, the Unity Editor hangs completely and has to be terminated via the Task Manager. I rebuilt the code of “Program.cs” in a Unity monobehavior and replaced any “Thread.Sleep” with coroutines. But it completely boils down to the “Connect()” method. More specifically to the “PollService()” routine inside the .dll.
ScanStatus PollService(Service* service, bool block) { ScanStatus res; unique_lock<mutex> lock(serviceQueueLock); if (block && serviceQueue.empty() && !serviceScanFinished) if (QuittableWait(serviceQueueSignal, lock)) return ScanStatus::FINISHED; if (!serviceQueue.empty()) { *service = serviceQueue.front(); serviceQueue.pop(); res = ScanStatus::AVAILABLE; } else if (serviceScanFinished) res = ScanStatus::FINISHED; else res = ScanStatus::PROCESSING; return res; }
I’m not sure why this would be a problem from inside Unity, but not from your VS project? May it have something to do with my Unity project settings? I know this is not too accurate information, but off the top of your head, do you have any idea what this could be? Please let me know, if you need further information. Or maybe you have a small example snippet of an implementation in Unity? I would be very grateful!
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (3 by maintainers)
Top GitHub Comments
Wow, thanks for uploading the Unity scene! I don’t have the opportunity to check it out at the the moment, but I’ll link it in the readme and try it out later.
I’m glad it worked out for you in the end.
At the moment its only purpose is to make the demo work 😃 There are some functions left over from the other project I am working on where I’m using the dll. So I wouldn’t be sure that you can use it as is. But it’s maybe really a good idea to make a generally usable BLE.cs. I’ll create an issue for that.
For debugging you can also try to disable+reenable your bluetooth functionality or reinserting the bluetooth-dongle.