Program is crashing (maybe) during data collection "break"

Hi everyone,

I am not a novice to psychtoolbox–I wrote my first experiment 20 years ago in Matlab–but recently I encountered a problem that might be coding problem or a Windows problem, and I was hoping someone could help or let me know if they encountered something similar.

Psychtoolbox version: 3.0.19 - Flavor: Manual Install, 18-Jul-2024
Platform: Windows 10 Enterprise
Matlab version 2016b (yes, it’s old, but I bought it with startup when I got this job and that version hasn’t been a problem until maybe now)

Allow me to describe the problem, and then I’ll provide the code, which may or may not be causing the problem.

I am running participants through a long RSVP target detection task. Participants control the timing of trials with their responses, which have no time pressure (we’re collecting accuracy but not RT). Every 20 trials, they get a self-paced break. Most participants got through the experiment without a hitch. But for a sizeable minority of participants, the program crashed randomly before they finished.

From interviewing participants, we discovered that it was happening during a self-paced break each time, and always when the participant wanted to take a “longer” break.

I tried it out and indeed found that if I let it sit on that self-paced break for long enough (about 30 seconds), the screen would turn black and the windows spinning ring would show up, and I’d get a message along the lines of “Matlab is not responding.”

I think that I fixed the problem by not allowing windows to give me any notifications of any kind. After changing that, the problem went away when I tested it out. We haven’t had a new participant yet. But my IT department thinks that it’s a problem with matlab or with my code, rather than a Windows setting.

I’ve never had this problem before with similar self-paced break experiments. It showed up after they gave me new computers (note July install date for psychtoolbox). We wrote this experiment, tested it ourselves (never with a long break), and then started to notice it happening with participants who took a long break.

But the other thing I changed slightly from previous experiments was the code. We decided we didn’t want people going through the breaks totally mindlessly, so we ask them to type. particular key instead of any key, and that key changes from break to break.

This is the code snippet:

% now start checking for a response
% we will start off with “thekey” being WRONG. Once it’s correct,
% this loop breaks and they can move on
while strcmpi(thekey,correct_key) == 0 % while they haven’t hit the right key
[keyIsDown,secs,keyCode]=KbCheck; % returns parameters after keypress
if keyIsDown==1 % if they press a key, record info and leave while loop
thekey = KbName(keyCode);
% first check for weird cases that are non-letter string presses
if iscell(thekey)
thekey = thekey{1}; % take the first key press / first item of key type
% this SHOULD convert it to char, regardless of key press type
% (e.g. alt)
end
if strcmpi(class(thekey),‘double’) % sometimes this is the type that comes out of a keypress
thekey = ‘null’; % we’ll just indicate it was a random key, and now it’s in type char
end
end
end

Could my code be causing some weird looping that’s sucking up memory and making matlab crash? Or do we think this is a windows problem after all?

Have you ever had windows yell at you that matlab is unresponsive merely because a participant is taking a while to respond? Is that a thing? Thanks!

Try adding a WaitSecs(0.001) at the end of the loop, to yield control so that the window can be reaponse to messages from the OS. Should fix that

This is indeed a MS-Windows peculiarity if no event processing has happened for more than a couple of seconds.

The WaitSecs() won’t work, as it doesn’t trigger even processing needed on MS-Windows to prevent that “not responding” message after long periods of inactivity. The timeout is somewhere around 7-10 seconds on Windows iirc.

Instead look at KbStrokeWait function to wait for a single key press and release, which is a convenience wrapper around KbWait, which triggers proper event processing for Windows (by calling GetMouse() periodically).