No CSV output when experiment ends prematurely: OSError/ _gdi32.swapbuffers(self.canvas.hdc)

OS Win10)
PsychoPy version (e.g. 3.0.1):
Standard Standalone? (y)
What are you trying to achieve?:

I’ve built an experiment which loops through a set of stimuli (N=20) up to 30 times (or fewer, if they manage > 95% correct answers) and then progresses to a test phase consisting of 4 loops.

Occasionally, the experiment works ok, but more often than not, I see the following error half way through the test phase:

_gdi32.swapbuffers(self.canvas.hdc)
OSError: exception: access violation reading 0x00000000

To my dismay, when this happens, there there is no .csv file (i.e output showing the experiment data) . Interestingly, the experiment doesn’t seem to officially ‘stop’ when my error message appears because the ‘green runnning man’ is still grey-ed out and the red stop button can be clicked (despite the display screen no longer showing). When I restart the experiment from the test phase, it runs until the end and gives me an output file (so the fact that I previously did not get data cannot be be due to not telling psychopy to write my data).

This has been very frustrating. Is there any way to (i) stop the error, (ii) salvage my data easily? I do get a txt document but it is completely empty.

There are 2 workarounds (both remove the error):

  1. Upgrade from 3.0.1 to 3.2.1, or:
  2. (If you need to use 3.0.1.) make the experiment smaller: if you have 2 separate performance contingent loops (which each loop through stimuli ~20 times each), divide these into 2 separate psychopy files. The fact this removes the error shows that v3.0.1 had difficulty with using many loops.