The exception may occur because a visual is discarded but still in memory due to a memory leak.
I was having a similar problem. I found the exception occurring in a visual which was supposed to be garbage collected. Fixing the memory leaks in the visual solved the problem.