# psychopy.visual.TextStim causing major crash

**URL:** <https://discourse.psychopy.org/t/psychopy-visual-textstim-causing-major-crash/3116>\
**Category:** Coding\
**Created:** [September 26, 2017, 1:00pm UTC](https://discourse.psychopy.org/t/psychopy-visual-textstim-causing-major-crash/3116 "2017-09-26T13:00:49Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![fnagle](https://avatars.discourse-cdn.com/v4/letter/f/d9b06d/32.png) [@fnagle](https://discourse.psychopy.org/u/fnagle)\
**Post date:** [September 26, 2017, 1:00pm UTC](https://discourse.psychopy.org/t/psychopy-visual-textstim-causing-major-crash/3116/1 "2017-09-26T13:00:49Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Michael](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/michael/32/16_2.png) [@Michael](https://discourse.psychopy.org/u/Michael)\
**Post date:** [September 26, 2017, 8:18pm UTC](https://discourse.psychopy.org/t/psychopy-visual-textstim-causing-major-crash/3116/2 "2017-09-26T20:18:28Z")

</div>

> [@fnagle](#):
>
> I will provide some sample code.

That really is necessary to get any useful suggestions.

---

<div class="post-metadata">

**Author:** ![fnagle](https://avatars.discourse-cdn.com/v4/letter/f/d9b06d/32.png) [@fnagle](https://discourse.psychopy.org/u/fnagle)\
**Post date:** [September 27, 2017, 10:39am UTC](https://discourse.psychopy.org/t/psychopy-visual-textstim-causing-major-crash/3116/3 "2017-09-27T10:39:18Z")

</div>

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

```auto
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](http://functions.py):

```auto
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](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

---

<div class="post-metadata">

**Author:** ![fnagle](https://avatars.discourse-cdn.com/v4/letter/f/d9b06d/32.png) [@fnagle](https://discourse.psychopy.org/u/fnagle)\
**Post date:** [September 27, 2017, 10:39am UTC](https://discourse.psychopy.org/t/psychopy-visual-textstim-causing-major-crash/3116/4 "2017-09-27T10:39:54Z")

</div>

Should I open a Github issue for this crash?

Cheers,  
Fintan

---

<div class="post-metadata">

**Author:** ![Michael](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/michael/32/16_2.png) [@Michael](https://discourse.psychopy.org/u/Michael)\
**Post date:** [September 27, 2017, 11:06am UTC](https://discourse.psychopy.org/t/psychopy-visual-textstim-causing-major-crash/3116/5 "2017-09-27T11:06:34Z")

</div>

> [@fnagle](#):
>
> Should I open a Github issue for this crash?

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?

---

<div class="post-metadata">

**Author:** ![fnagle](https://avatars.discourse-cdn.com/v4/letter/f/d9b06d/32.png) [@fnagle](https://discourse.psychopy.org/u/fnagle)\
**Post date:** [September 28, 2017, 11:12am UTC](https://discourse.psychopy.org/t/psychopy-visual-textstim-causing-major-crash/3116/6 "2017-09-28T11:12:24Z")

</div>

Hi Michael,

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

> [@Partial success getting PYO to work: help needed!](https://discourse.psychopy.org/t/partial-success-getting-pyo-to-work-help-needed/3091):
>
> Hello all, I need to get PYO to work on a Windows 7 Enterprise Dell Optiplex 7040. It’s a requirement as colleagues are also using PYO on existing equipment, and sound playback (in our detection experiment) is much quieter using PyGame/sounddevice. I tried first of all with the standalone PsychoPy install. Error: Portaudio uses interleaved callback. portaudio error in Pa\_OpenStream: Illegal combination of I/O devices portaudio error in Pa\_CloseStream (pa\_deinit): PortAudio not initialized por…

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
