Prevent crash from terminated ocSpeech (PR #13634)
Supersedes PR #13569
Summary of the issue:
NVDA was crashing when resetting the configuration to factory defaults.
NVDA terminates the ocSpeech native module when resetting the config, however there is a pending callback to a now deleted python function.
Steps to reproduce:
- Run NVDA
- In the Keyboard section of the Preferences dialog, turn "Speak command keys" on.
- Reset your configuration to factory defaults
- Note that NVDA crashes
Description of fix:
Changes the design of the ocSpeech module.
Both initialization and termination are blocked if a callback is about to happen.
The "tokens" for prior initialization of ocSpeech are collected by the ocSpeech system.
When an async task reaches completion, the origin token is checked for validity, the callback is not called for a now invalid token.
Initialization now requires the callback to be specified.