Reputation: 467
Here is my code:
from psychopy import visual, event, gui, data, core
import random, os
from random import shuffle
from PIL import Image
import glob
a = glob.glob("DDtest/targetimagelist1/*")
b = glob.glob("DDtest/distractorimagelist1/*")
c = glob.glob("DDtest/targetimagelist2/*")
d = glob.glob("DDtest/distractorimagelist3/*")
e = glob.glob("DDtest/targetimagelist4/*")
shuffle(c)
shuffle(d)
ac = a + c
bd = b + d
indices = random.sample(range(len(ac)),len(ac))
ac = list(map(ac.__getitem__, indices))
bd = list(map(bd.__getitem__, indices))
ace = ac+e
shuffle(ace)
target = ac
distractor = bd
recognition = ace
def studyphase():
loc = [1, 2]
location = random.choice(loc)
if location == 1:
pos1 = [-.05,-.05]
pos2 = [.05, .05]
else:
pos1 = [.05, .05]
pos2 = [-.05, -.05]
win = visual.Window(size=(1920, 1080), fullscr=True, screen=0, monitor='testMonitor', color=[-1,-1,-1])
distractorstim = visual.ImageStim(win=win, pos=pos1, size=[0.5,0.5])
distractorstim.autoDraw = True
targetstim = visual.ImageStim(win=win, pos=pos2, size=[0.5,0.5])
targetstim.autoDraw = True
targetstim.image = target[i]
distractorstim.image = distractor[i]
win.flip()
core.wait(.1)
def testphase():
win = visual.Window(size=(1920, 1080 ), fullscr=True, screen=0, monitor='testMonitor', color=[-1,-1,-1])
recognitionstim = visual.ImageStim(win=win, pos=[0,0], size=[0.5,0.5])
recognitionstim.autoDraw = True
recognitionstim.image = recognition[k]
old = visual.TextStim(win,text='OLD',pos=[-0.5,-0.5],font='Lucida Console')
new = visual.TextStim(win,text='NEW', pos=[0.5,-0.5],font='Lucida Console')
old.draw()
new.draw()
win.flip()
core.wait(.1)
for i in range(len(ac)):
studyphase()
for k in range(len(ace)):
testphase()
What this is supposed to do is take a bunch of pictures and display them in two different phases (study and test), however, when I run this code the program crashes about half way through the second loop, and I get the following error message:
python(55762,0xa0afe1a8) malloc: *** mach_vm_map(size=8388608) failed (error code=3)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug
Fatal Python error: (pygame parachute) Bus Error
However, if I run either the study loop or the test loop independently they run fine. Anyone know what might be causing this error? Any help will be greatly appreciated. :)
Edit: so apparently, if I move the win command outside the loop, it works.
Upvotes: 0
Views: 1348
Reputation: 5683
This issue was raised on the psychopy-users list a few years ago. It is quite likely caused by the images being too large (in pixels, not megabyte). So a solution would be to downscale them to approximately the resolution that you're going to display them, if possible. I found this by googling the error message.
You generate a new window and several new stimuli on every trial/presentation, since they are initiated within the functions and the functions are called in every iteration of the loop(s). Please see my answer to your earlier question for a strategy to create window/stimuli first and then update the properties that needs to change. This may even solve the problem on its own since creating new stimuli may fill up memory.
Upvotes: 2