psychopy.visual.TextStim causing major crash

Here’s a minimal example. This is the main file:

from __future__ import division  # so that 1/3=0.333 instead of 1/3=0
from psychopy import visual
from psychopy import prefs
prefs.general['audioLib'] = ['pyo']
from psychopy import locale_setup, core, data, event, logging, sound, gui
from psychopy.constants import *  # things like STARTED, FINISHED
import numpy as np
from numpy import sin, cos, tan, log, log10, pi, average, sqrt, std, deg2rad, rad2deg, linspace, asarray
from numpy.random import random, randint, normal, shuffle
import os  
import sys 
from os import listdir
from os.path import isfile, join
from shutil import copyfile
from random import shuffle
import pandas as pd
import csv
import random 
import pyglet
import time
from pdb import set_trace
import random
import numpy as np
import pickle


from functions import *


debug = True

timer = core.Clock()


if debug:
    expInfo ={u'session': u'-999', u'participant': u'test'}
    expInfo['date'] = 'test'
    expInfo['expName'] = 'test'
else:
    expName = 'participant info'  
    expInfo = {u'gender': u'001', u'participant': u'',u'age': u''}
    dlg = gui.DlgFromDict(dictionary=expInfo, title=expName)
    if dlg.OK == False: core.quit()  
    expInfo['date'] = data.getDateStr()  
    expInfo['expName'] = expName

if debug:
    win = visual.Window(size=(800, 600), fullscr=False, screen=0, allowGUI=False, allowStencil=False,
    monitor='testMonitor', color=[0,0,0], colorSpace='rgb',
    blendMode='avg', useFBO=True,
    )
else:
    win = visual.Window(size=(1920, 1080), fullscr=False, screen=0, allowGUI=False, allowStencil=False,
        monitor='testMonitor', color=[0,0,0], colorSpace='rgb',
        blendMode='avg', useFBO=True,
        )
    
#Uncomment these two lines to prevent the crash   
#In fact, just uncommenting the first line prevents it! Draw not necessary
#search_text = visual.TextStim(win, 'TEST' , wrapWidth=2, height=0.16)
#search_text.draw()
 
win.flip()

noise_example = sound.Sound( 'noise_exp.wav', secs=1)
incorrect = sound.Sound( 'PureTone_F1500_t50.wav', secs=1)
noise = sound.Sound( 'PureTone_F1500_t50.wav', secs=1)
tone1 = sound.Sound( 'PureTone_F1500_t50.wav', secs=0.05)
tone2 = sound.Sound( 'PureTone_F1500_t50.wav', secs=0.05)


run_blocks(noise,timer,visual,win,event,incorrect,tone1,tone2)



win.close()
core.quit()

And this is the imported functions.py:

import csv
import pdb
import pickle
from psychopy import locale_setup, core, data, event, logging, sound, gui



def run_blocks(noise,timer,visual,win,event,incorrect,tone1,tone2):

    bPoints = 0
    for i in range(10):
     
        trial_details = {}
        probe_response = 't'
        noise.play()
        timer.reset()
        image = visual.ImageStim(win=win, image=  '2008_000041.jpg')
        responded = False

        for frameN in range(60):
            print 'FRAME, ',frameN
            if  frameN == 30 :
                tone1.play()

            image.draw()
            win.flip()
        for frameN in range(20):
            print 'FRAME2 ',frameN
            win.flip()
        response = event.getKeys(keyList = ['space'], timeStamped = timer)

         
        if True:


            search_text = visual.TextStim(win, 'TEST' , wrapWidth=2, height=0.16)

            search_text.draw()
            
            win.flip()
            
            keys = event.waitKeys(keyList=['q','p','space'],timeStamped=timer)

            rt_space = -999
            wait = True
            
            
            for k in keys:
                if k[0] == 'space':
                    rt_space = [k[0],k[1]]
                if k[0] == 'q' or k[0] == 'p':
                    wait = False
            while wait:
                keys = event.waitKeys(keyList=['q','p'],timeStamped=timer)
                letters = [t[0] for t in keys]
                if ('p' in letters) or ('q' in letters):
                    wait = False

      
            win.flip()
            core.wait(1.5)
            
        print 'C'

I have provided a zip file at https://s3-eu-west-1.amazonaws.com/video-comparisons/load.zip which you should be able to run to try and provoke the crash. My system is a Dell Optiplex 7040, Windows 7 Enterprise, PsychoPy 1.85.3, Anaconda 32-bit Python 2.7.

Cheers,

Fintan