Repository: nvaccess/nvda

Issue:
Very frequent error in Firefox when navigating from one page to another
**Reported by msuch on 2015-01-29 15:16**
This does not seem to really affect navigation, but the NVDA's error sound is heard and users wonder why.
It does not seem to happen when no braille display is connected.
It systematically produice the following error lines.
ERROR - queueHandler.flushQueue (16:02:45):
Error in func _handleUpdate from eventQueue
Traceback (most recent call last):
  File "queueHandler.pyc", line 50, in flushQueue
  File "virtualBuffers__init__.pyc", line 1262, in _handleUpdate
  File "braille.pyc", line 1475, in handleUpdate
  File "braille.pyc", line 774, in update
  File "textInfos\offsets.pyc", line 344, in expand
  File "virtualBuffers__init__.pyc", line 322, in _getUnitOffsets
  File "textInfos\offsets.pyc", line 326, in _getUnitOffsets
  File "virtualBuffers__init__.pyc", line 258, in _getLineOffsets
WindowsError: [1775](Error) A null context descriptor has been passed from client to host during a remote procedure call (RPC)
ERROR - queueHandler.flushQueue (16:02:45):
Error in func _handleUpdate from eventQueue
Traceback (most recent call last):
  File "queueHandler.pyc", line 50, in flushQueue
  File "virtualBuffers__init__.pyc", line 1262, in _handleUpdate
  File "braille.pyc", line 1475, in handleUpdate
  File "braille.pyc", line 774, in update
  File "textInfos\offsets.pyc", line 344, in expand
  File "virtualBuffers__init__.pyc", line 322, in _getUnitOffsets
  File "textInfos\offsets.pyc", line 326, in _getUnitOffsets
  File "virtualBuffers__init__.pyc", line 258, in _getLineOffsets
WindowsError: [1775](Error) A null context descriptor has been passed from client to host during a remote procedure call (RPC)



Discussion:
This is still true in Firefox 52.0.2:

```
ERROR - queueHandler.flushQueue (14:55:04):
Error in func _handleUpdate from eventQueue
Traceback (most recent call last):
  File "queueHandler.pyc", line 50, in flushQueue
  File "virtualBuffers\__init__.pyc", line 608, in _handleUpdate
  File "braille.pyc", line 1718, in handleUpdate
  File "braille.pyc", line 953, in update
  File "textInfos\offsets.pyc", line 348, in expand
  File "virtualBuffers\__init__.pyc", line 320, in _getUnitOffsets
  File "textInfos\offsets.pyc", line 330, in _getUnitOffsets
  File "virtualBuffers\__init__.pyc", line 250, in _getLineOffsets
WindowsError: [Error 1775] A null context handle was passed from the client to the host during a remote procedure call
```

An almost sure way to get this error is to type a search query into Google and press Enter. After pressing Enter the error occurs but the results page loads just fine.
I am unable to reproduce this. Steps taken:
- Open Firefox
- Go to https://www.google.com
- Type in something to search and press enter

I tried with and without "Google Instant"

- No Braille display
- Firefox version `52.0.2 (32-bit)`
- NVDA Version: `next-13950,c31e74f7`
- Windows 10 Version 1607 Build 14393.953
Same setup here, except on NVDA master. The key is probably to have a braille display connected. I can only reproduce this with braille (HumanWare Brailliant BI in my case).

Resolving patch:
diff --git a/source/virtualBuffers/__init__.py b/source/virtualBuffers/__init__.py
--- a/source/virtualBuffers/__init__.py
+++ b/source/virtualBuffers/__init__.py
@@ -3,7 +3,7 @@
 #A part of NonVisual Desktop Access (NVDA)
 #This file is covered by the GNU General Public License.
 #See the file COPYING for more details.
-#Copyright (C) 2007-2015 NV Access Limited, Peter Vágner
+#Copyright (C) 2007-2017 NV Access Limited, Peter Vágner
 
 import time
 import threading
@@ -605,6 +605,9 @@ def changeNotify(cls, rootDocHandle, rootID):
 	def _handleUpdate(self):
 		"""Handle an update to this buffer.
 		"""
+		if not self.VBufHandle:
+			# #4859: The buffer was unloaded after this method was queued.
+			return
 		braille.handler.handleUpdate(self)
 
 	def getControlFieldForNVDAObject(self, obj):


Test patch: