scratchfoundation / scratch-link

Device interoperability layer for Windows and MacOS
BSD 3-Clause "New" or "Revised" License
104 stars 84 forks source link

Windows BLE 'withResponse' write crashes for Vernier GDX-FOR #111

Closed evhan55 closed 5 years ago

evhan55 commented 5 years ago

Expected Behavior

GDX-FOR stays connected after connection is established

Actual Behavior

GDX-FOR crashes soon after connection is established, seemingly because of an issue with withResponse being set to true on line 339 of BLESession.cs

cwillisf commented 5 years ago

The write is returning protocol error 3 indicating "The attribute cannot be written". I haven't found an official source of information describing why this would happen but I have found a few posts on Stack Overflow and the like; they seem to suggest that calling CoInitializeSecurity would fix the issue. Unfortunately this is a native method so calling it from C# is non-trivial, though it shouldn't take too long to set it up.

Adding a call to CoInitializeSecurity is what we were trying to avoid by bumping the Windows 10 version requirement up from 15063 in #101, so it might be possible to relax the version requirement after adding the call.

Disabling withResponse seems to eliminate the error. I'm not sure if this is a reasonable solution but if it is it should be done as a change to the extension code. Currently the extension explicitly passes withResponse: true in the write request so arbitrarily turning it off seems like a bad idea.

evhan55 commented 5 years ago

@cwillisf I will investigate to see if the extension definitely needs that flag to be true

evhan55 commented 5 years ago

@cwillisf Setting withResponse to null on the client side seems to do it: https://github.com/LLK/scratch-vm/pull/1924