psychopy.visual.TextStim causing major crash

Hello all,

I just encoutered a strange problem with psychopy.visual.TextStim. I had two calls to this function, both in functions in imported files into which win was passed as a variable. They both caused major crashes on Windows 7 (“This program has stopped responding…”) without any error messages.

One call was fixed by moving the function containing TextStim into the main file.

I also moved the other call, but it still caused a crash. I was able to fix this one by doing a simple call to TextStim() before the call in question.

Has anyone else experienced anything like this? If so I will provide some sample code.

Cheers,
Fintan

That really is necessary to get any useful suggestions.

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

Should I open a Github issue for this crash?

Cheers,
Fintan

No, because it hasn’t been demonstrated that this is a PsychoPy problem per se.

Didn’t see the bug you mention and your task seemed to run for me regardless of whether that line was commented or not. That was using the standalone version on a Mac.

Is there a particular reason why you need to run this under an Anaconda setup? What happens if you just use the standalone?

Hi Michael,

I ended up using Anaconda as it was the only way I could figure out to make PYO work, as detailed in

I still haven’t managed to get PYO to work with the standalone distribution, only with Anaconda. When I remove the audio code from the example above, and run it from the standalone Coder, the crash doesn’t happen - so it could either be an interaction with Anaconda or an interaction with the audio code.

Cheers,
Fintan