nvaccess / nvda

NVDA, the free and open source Screen Reader for Microsoft Windows
https://www.nvaccess.org/
Other
2.09k stars 630 forks source link

NVDA occasionally crashes when USB Braille display is disconnected #16218

Closed FelixGruetzmacher closed 3 months ago

FelixGruetzmacher commented 7 months ago

Steps to reproduce:

  1. Set the Braille display to automatic, and configure detection so that only standard HID Braille displays are detected.
  2. Repeatedly disconnect and reconnect a USB standard HID Braille display.

    Actual behavior:

    Most of the time, NVDA successfully keeps track of the connection status. In some cases (about 1 in 5), NVDA crashes (silently closes) when the Braille display is disconnected.

    Expected behavior:

    Disconnecting the Braille display should not cause NVDA to crash.

    NVDA logs, crash dumps and other attachments:

System configuration

NVDA installed/portable/running from source:

Installed.

NVDA version:

NVDA 2023.3.3 and 2024.1 beta 7.

Windows version:

Windows 11 Pro version 23H2 (Build 22631.3155)

Name and version of other software in use when reproducing the issue:

Other information about your system:

Other questions

Does the issue still occur after restarting your computer?

Yes.

Have you tried any other versions of NVDA? If so, please report their behaviors.

Occurs with 2023.3.3 and 2024.1 beta 7.

If NVDA add-ons are disabled, is your problem still occurring?

No add-ons present on this machine.

Does the issue still occur after you run the COM Registration Fixing Tool in NVDA's tools menu?

Yes.

CyrilleB79 commented 7 months ago

What about reloading the config (nvda+control+R)?

By chance, is there a link with #14872?

dkager commented 7 months ago

This behavior can also be observed on Bluetooth. Could be related to #13153.

seanbudd commented 5 months ago

Can you confirm which braille displays this is occurring on? Please reproduce this issue and provide a log file of the behaviour. Ensure your log level is set to debug in general preferences. We also need a crash dump - which you can find using the instructions from the previous wiki link.

FelixGruetzmacher commented 3 months ago

Using Windows event viewer I can verify that these are indeed crashes, but no minidump is created in %temp%. How can I explicitly request a dump on crash for NVDA itself?

FelixGruetzmacher commented 3 months ago

nvda.exe.3532.dmp I was able to create a dump. This was NVDA 2024.1. The crash happened when I switched from "automatic" to "no Braille display" while a Help Tech display was connected. This happens frequently, also when closing NVDA.

FelixGruetzmacher commented 3 months ago

Upon further inspection, the offending call is in the close() method of the hwIo.Hid class: hidDll.HidD_FreePreparsedData(self._pd) This works the first time, but calling it more than once is an error as the _pd pointer will have become invalid. It turns out that close() is called twice:

  1. In the Braille display driver as part of its termination,
  2. In the destructor Hid inherits from IoBase (this one's polymorphic and therefore easy to miss). I tested the hypothesis by deriving, in my driver module, a class MyHid from hwIo.Hid, giving it an empty del(). Since there is no implicit call to superclass destructors, this fixed the problem. That's if trying about 50 times counts. Note that this is a dirty hack. The good fix will be to guard hwIo.Hid.close() against multiple calls on the same instance. Does anyone feel like doing this?