question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unity crashing when calling Connect() method

See original GitHub issue

In 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:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
adabrucommented, Jan 8, 2021

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.

It atleast works for my test application receiving packages from a ESP32.

I’m glad it worked out for you in the end.

Would there be a way to kinda extend the BLE class from a separate Unity Script, with the intention of leaving your repo files untouched? Or may this intention be nonsense in the first place? ;D

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.

1reaction
adabrucommented, Jan 6, 2021

For debugging you can also try to disable+reenable your bluetooth functionality or reinserting the bluetooth-dongle.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unity crashes when trying to call method with C# from DLL ...
I have a DLL file that is wrote in C/C++, it works great as a console app. when i try the same thing...
Read more >
Unity crashing after a while loop with an invoke method is run
To achieve this, I'm using the Invoke method inside of a while loop, to call another method, but with a specified delay.
Read more >
Debugging Unity Crashes & Errors - The Easy Way - YouTube
Try Backtrace FREE - https://backtrace.io/create/?utm_campaign=Free%20Trial%20Signup&utm_source=Jason%20Weimann Learn how to catch and fix ...
Read more >
Unity Android crashes when calling Close() on socket #610
Hi,. I'm experiencing a very rare issue. It has been driving me crazy for several weeks. The app crashes on Android when calling...
Read more >
Troubleshooting and known issues (VS Tools for Unity)
It's an issue when a plugin ends up attaching a native thread to the runtime, which then does blocking calls to the OS....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found