Issue with TextStim (and MovieStim)

I think I am having an issue with TextStim (see error message below) and I would appreciate any insights on how to solve it.

Obs: The experiment runs fine most times, but I get this error in 1 out of 6 runs approx. The experiment breaks towards the end of it, around trial 34 to 39. I think it is a memory issue caused not by the videos but by TextStim but I don’t know exactly.

Experiment Descrtiption: The experiment consist of 40 short videos. After each video participants answer a multiple choice question. The response options are displayed as four TextStim in four rows. When participants hover the mouse over a response, their color is set to green to indicate current selection. I only have four TextStim objects and I set the text on each trial, so is not that I am creating hundreds of TextStims along the experiment. I also have one MovieStim object and I load each video to it each trial.

The error always happens after playing a video, when the text should be displayed:

Psychopy version used: 2024.2.1, run from a virtual environment

Traceback (most recent call last):
File “C:\venvs\psy2024\lib\site-packages\pyglet\graphics_init_.py”, line 452, in _get_domain
domain = domain_map[key]
KeyError: ((‘v2f/dynamic’, ‘t3f/dynamic’, ‘c4B/dynamic’), 7, False)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “C:\Users\Externdator\Documents\THESES_EXPERIMENTS\masc_leen_anastasija\main.py”, line 12, in
e.run_exp()
File “C:\Users\Externdator\Documents\THESES_EXPERIMENTS\masc_leen_anastasija\masc_exp.py”, line 700, in run_exp
self._run_trials(video_list, clips_path)
File “C:\Users\Externdator\Documents\THESES_EXPERIMENTS\masc_leen_anastasija\masc_exp.py”, line 530, in _run_trials
self._show_questions(video_idx + 1)
File “C:\Users\Externdator\Documents\THESES_EXPERIMENTS\masc_leen_anastasija\masc_exp.py”, line 382, in _show_questions
idx_response, click_time, click_coords = self._option_selection()
File “C:\Users\Externdator\Documents\THESES_EXPERIMENTS\masc_leen_anastasija\masc_exp.py”, line 440, in _option_selection
self._draw_response_options()
File “C:\Users\Externdator\Documents\THESES_EXPERIMENTS\masc_leen_anastasija\masc_exp.py”, line 331, in _draw_response_options
self.c.draw()
File “C:\venvs\psy2024\lib\site-packages\psychopy\visual\text.py”, line 736, in draw
self.setText()
File “C:\venvs\psy2024\lib\site-packages\psychopy\visual\text.py”, line 395, in setText
setAttribute(self, ‘text’, text, log)
File “C:\venvs\psy2024\lib\site-packages\psychopy\tools\attributetools.py”, line 140, in setAttribute
setattr(self, attrib, value)
File “C:\venvs\psy2024\lib\site-packages\psychopy\tools\attributetools.py”, line 29, in set
newValue = self.func(obj, value)
File “C:\venvs\psy2024\lib\site-packages\psychopy\visual\text.py”, line 386, in text
self._setTextShaders(text)
File “C:\venvs\psy2024\lib\site-packages\psychopy\visual\text.py”, line 404, in setTextShaders
self.pygletTextObj = pyglet.text.Label(
File "C:\venvs\psy2024\lib\site-packages\pyglet\text_init
.py", line 452, in init
super(Label, self).init(document, x, y, width, height,
File "C:\venvs\psy2024\lib\site-packages\pyglet\text_init
.py", line 273, in init
super(DocumentLabel, self).init(document,
File “C:\venvs\psy2024\lib\site-packages\pyglet\text\layout.py”, line 820, in init
self.document = document
File “C:\venvs\psy2024\lib\site-packages\pyglet\text\layout.py”, line 929, in _set_document
self._init_document()
File “C:\venvs\psy2024\lib\site-packages\pyglet\text\layout.py”, line 1043, in _init_document
self._update()
File “C:\venvs\psy2024\lib\site-packages\pyglet\text\layout.py”, line 980, in _update
self._create_vertex_lists(left + line.x, top + line.y,
File “C:\venvs\psy2024\lib\site-packages\pyglet\text\layout.py”, line 1476, in create_vertex_lists
box.place(self, i, x, y, context)
File “C:\venvs\psy2024\lib\site-packages\pyglet\text\layout.py”, line 370, in place
vertex_list = layout.batch.add(n_glyphs * 4, GL_QUADS, group,
File "C:\venvs\psy2024\lib\site-packages\pyglet\graphics_init
.py", line 368, in add
domain = self.get_domain(False, mode, group, formats)
File "C:\venvs\psy2024\lib\site-packages\pyglet\graphics_init
.py", line 458, in _get_domain
domain = vertexdomain.create_domain(*formats)
File “C:\venvs\psy2024\lib\site-packages\pyglet\graphics\vertexdomain.py”, line 140, in create_domain
return VertexDomain(attribute_usages)
File “C:\venvs\psy2024\lib\site-packages\pyglet\graphics\vertexdomain.py”, line 189, in init
attribute.buffer = vertexbuffer.create_mappable_buffer(
File “C:\venvs\psy2024\lib\site-packages\pyglet\graphics\vertexbuffer.py”, line 115, in create_mappable_buffer
return MappableVertexBufferObject(size, target, usage)
File “C:\venvs\psy2024\lib\site-packages\pyglet\graphics\vertexbuffer.py”, line 389, in init
super(MappableVertexBufferObject, self).init(size, target, usage)
File “C:\venvs\psy2024\lib\site-packages\pyglet\graphics\vertexbuffer.py”, line 308, in init
glBufferData(target, self.size, None, self.usage)
OSError: exception: access violation reading 0x0000000000000130

Thanks so much for your help!

Are you using cloud storage?

If not, here are alternative solutions

Hi! Thanks for your reply! I understand that I am having an issue when drawing and showing the text stimuli as the movies are played correctly but it is when the response options should be drawn after the movie that the error occurs.

If you are using Coder then I’m not able to help much. Here are a couple of other threads that might be relevant.

If you are running in a virtual environment, could you try a more recent version?

Thank you! I went through those post already.

I found this in the description of TextStim:

Performance OBS: in general, TextStim is slower than many other visual stimuli, i.e. it takes longer to change some attributes. In general, it’s the attributes that affect the shapes of the letters: text , height , font , bold etc. These make the next .draw() slower because that sets the text again. You can make the draw() quick by calling re-setting the text (myTextStim.text = myTextStim.text ) when you’ve changed the parameters.

Since I am changing the text size as they hover over the text, I will try removing that as next step. Otherwise TextBox2 could be an option instead of TextStim.

I generally advise Textbox2 over text components nowadays.