AndreMiras / pycaw

Python Core Audio Windows Library
MIT License
385 stars 67 forks source link

NVDA crashes when registering empty MMNotificationClient #93

Closed mltony closed 8 months ago

mltony commented 8 months ago

Hi @AndreMiras, this is @mltony, developer of NVDA screenreader. I was trying to make use of your awesome pycaw library for one more purpose: in NVDA we would like to speak when microphone is muted/unmuted. I was trying to register a MMNotificationClient - but whenever it receives a notification it actually crashes the entire Python app - without any python stacktrace in the log. Basically I have an empty MMNotificationClient implementation without even any methods overloaded, I register it in DeviceEnumerator, and every time I adjust volume or mute microphone, it just quietly crashes NVDA. I only have a dump file created, which I'm not sure what to do with. I tried examples\notification_client_example.py from pycaw and it works beautifully when executed as a standalone python script. So my thinking is that there must be some difference in how NVDA handles COM calls vs how pycaw expects them to be handled that causes segmentation fault or access violation. Do you have any suggestions how to debug this further? I am not familiar with Com protocol, so not sure how to proceed. One thought I had in mind is regarding MTA. I read in callbacks.py in the comment for class AudioSessionNotification that MTA needs to be enabled in order for it to work. I actually didn't have to enable MTA at all for AudioSessionNotification, and it still works - which makes me think that NVDA must be enabling it somewhere else, although I couldn't find this line

sys.coinit_flags = 0

anywhere in NVDA. So wondering if any specific setting for MTA is required in order to make MMNotificationClient to work? Do you have any other ideas how can I debug this further? FWIW here is my NVDA branch that crashesNVDA - relevant files are source\audio\notifications.py and def initialize in source\audio\__init__.py Any suggestions would be appreciated. Thanks! P.S. We have recently integrated pycaw into NVDA and it works beautifully - and it will be included in the next release for adjusting left/right channel volume of applications.

mltony commented 8 months ago

Never mind, I ffigured it out. It turns out garbage collector ate my listener object. Once I stored it in a global variable - it works fine.