Juan Pablo
Juan Pablo

Reputation:

Matlab Psychtoolbox keeps crashing when running complex scripts

I'm running psychtoolbox-3.0.10 in MATLAB R2011B in a Windows XP partition in a Macbook computer. I've been trying to run a script a Matlab for behavioral sciences course (see here. The file is called FunkyScreen.m.

It works for first 30 seconds (the first 80 lines or so) and then Matlab suddenly crashes and closes. I clicked on the 'details' button of the message and it shows me that the program probably stopped because of the mex files.

Questions:

The script is:

% FunkyScreen.m
%
% opens a window using psychtoolbox,
% makes the window do some funky things
%
% written for Psychtoolbox 3 on the PC by IF 3/2007
screenNum=0;
flipSpd=13;% a flip every 13 frames
[wPtr,rect]=Screen('OpenWindow',screenNum);
monitorFlipInterval=Screen('GetFlipInterval', wPtr); 
% 1/monitorFlipInterval is the frame rate of the monitor
black=BlackIndex(wPtr);
white=WhiteIndex(wPtr);
% blank the Screen and wait a second
Screen('FillRect',wPtr,black);
Screen(wPtr,'Flip');
HideCursor;
tic
while toc<1;
end
% make a rectangle in the middle of the screen flip colors and size
Screen('FillRect',wPtr,black);
vbl=Screen(wPtr,'Flip');% collect the time for the first flip with vbl
for i=1:10
Screen('FillRect',wPtr,[0 0 255], [100 150 200 250]);
vbl=Screen(wPtr, 'Flip', vbl+(flipSpd*monitorFlipInterval));
% flip 13 frames after vbl
Screen('FillRect',wPtr,[255 0 0], [100 150 400 450]);
vbl=Screen(wPtr, 'Flip', vbl+(flipSpd*monitorFlipInterval));
end
% blank the screen and wait a second
Screen('FillRect',wPtr,black);
vbl=Screen(wPtr,'Flip', vbl+(flipSpd*monitorFlipInterval));
tic
while toc<1;
end
% make circles flip colors & size
Screen('FillRect',wPtr,black);
vbl=Screen(wPtr,'Flip');
for i=1:10
Screen('FillOval',wPtr,[0 180 255], [ 500 500 600 600]);
vbl=Screen(wPtr, 'Flip', vbl+(flipSpd*monitorFlipInterval));
Screen('FillOval',wPtr,[0 255 0], [ 400 400 900 700]);
vbl=Screen(wPtr, 'Flip', vbl+(flipSpd*monitorFlipInterval));
end
% blank the Screen and wait a second
Screen('FillRect',wPtr,black);
vbl=Screen(wPtr,'Flip', vbl+(flipSpd*monitorFlipInterval));
tic
while toc<1;
end
% make lines that flip colors size & position
Screen('FillRect',wPtr,black);
vbl=Screen(wPtr,'Flip');
for i=1:10
Screen('DrawLine',wPtr,[0 255 255], 500, 200, 700 ,600, 5);
vbl=Screen(wPtr, 'Flip', vbl+(flipSpd*monitorFlipInterval));
Screen('DrawLine',wPtr,[255 255 0], 100, 600, 600 ,100, 5);
vbl=Screen(wPtr, 'Flip', vbl+(flipSpd*monitorFlipInterval));
end
% blank the Screen and wait a second
Screen('FillRect',wPtr,black);
vbl=Screen(wPtr,'Flip', vbl+(flipSpd*monitorFlipInterval));
tic
while toc<1;
end
% combine the stimuli
Screen('FillRect',wPtr,black);
vbl=Screen(wPtr,'Flip');
for i=1:10
Screen('FillRect',wPtr,[0 0 255], [100 150 200 250]);
Screen('DrawLine',wPtr,[0 255 255], 500, 200, 700 ,600, 5);
Screen('FillOval',wPtr,[0 180 255], [ 500 500 600 600]);
Screen('TextSize', wPtr , 150);
Screen('DrawText', wPtr, 'FUNKY!!', 200, 20, [255 50 255]);
vbl=Screen(wPtr, 'Flip', vbl+(flipSpd*monitorFlipInterval));
Screen('FillRect',wPtr,[255 0 0], [100 150 400 450]);
Screen('FillOval',wPtr,[0 255 0], [ 400 400 900 700]);
Screen('DrawLine',wPtr,[255 255 0], 100, 600, 600 ,100, 5);
vbl=Screen(wPtr, 'Flip', vbl+(flipSpd*monitorFlipInterval));
end
% blank the screen and wait a second
Screen('FillRect',wPtr,black);
vbl=Screen(wPtr,'Flip', vbl+(flipSpd*monitorFlipInterval));
tic
while toc<1;
end
Screen('CloseAll');
ShowCursor

Upvotes: 7

Views: 1659

Answers (1)

Dennis Jaheruddin
Dennis Jaheruddin

Reputation: 21563

Here is how you can (probably) eliminate the problem.

Step 1: Run the code, try to get an indication of where it crashes
Step 2: Possibly using the information from Step 1, devide your code in 2 halves.
Step 3: Run both halves separately, see which one crashes
Step 4: Keep repeating the steps above untill you have identified the culprit 
Step 5: Try to deal with the specific problem that is found

Upvotes: 1

Related Questions