Psychtoolbox code crashes Matlab when the mouse is double clicked

Hello. First post!

Not sure how to begin, so I’ll just dive into it =>

The computer is running Windows 10, Matlab 2021b (though, the same issue appeared on Matlab 2018a), fresh install of gstreamer (latest), fresh install of psychtoolbox (latest), Nvidia drivers version 512 (latest for the Quadro P2000 card).

Note: While I have experience with Python and BASH scripts, I started troubleshooting this issue knowing nothing about Matlab nor Psychtoolbox. I didn’t write this code and I’m not the researcher using it. The code worked a couple of weeks ago on this same computer and I don’t know of anything that changed to cause this issue. I’m still investigating the computer and the installation, but I’m posting this here to see if there is something that can be done programmically to resolve it.

At the start of the code, we’re supposed to press ‘5’ to begin, and then it’s supposed to not visibly respond to the mouse.

What is actually happening: When we click on the mouse, the Windows busy cursor appears for no discernible reason (CPU, RAM usage, and Hard Drive are all normal and have ample reserve ability). If we doubleclick while the busy cursor runs, Matlab becomes unresponsive and closes (taking the possibly helpful screen output to the grave with it).

The only success I’ve had with this issue is upgrading the graphics driver, which at least makes the program take longer to crash.

Sorry for the length of the post and the code snippit. I honestly don’t know enough to just include the important parts.

Any insight would be greatly appreciated.

Code begins:

function WMREM(subName, listenScan, condition, CurRun, ispractice)

%%
% 19TR14+4TR15+4TR=330 TRs (11 min, including padding time and ITI)
% optimized for wispic scanner
% feedback at the end of the run
% and at the end of each trial for pracitce run
%%
try

close all;
%    clear all;
clear mex;
IOPort('Closeall');
Screen('Closeall');

%test script
Screen('Preference', 'SkipSyncTests', 1);
rand('twister',sum(100*clock));

if length(subName) < 1; subName = 'tmp'; end;

if condition==0  % no overlap, low conflict
    filename=[subName '_Removal_low_' num2str(CurRun)];
elseif condition==1  %overlap, high conflict
    filename=[subName '_Removal_high_' num2str(CurRun)];
end

screenid = max(Screen('Screens'));
[win,rect] = Screen('OpenWindow',screenid);
HideCursor;

Screen('TextFont', win, 'Arial');

HideCursor;

%%parameters
nloc=6;
nori=6;
trialnumber=14; % 14 not 12
paddingtime=8;
step_size_orientation=2.5*pi/180; %in radian % USELESS?
Nsteps=round(180/step_size_orientation); % USELESS?

white=255;
black=0;
gray=(white+black)/2;
whiteforping=[255,255,255];
blackforping=[0,0,0];
grayforping=(whiteforping+blackforping)/2;
red=[255,0,0];
green=[0,255,0];

%key buttons
KbName('UnifyKeyNames');
yes_button=KbName('1!');
no_button=KbName('2@');

spatial_frequency=1;
radius=3;
thinthickness=0.08;

sample_dur1=1; %A and B
delay1=7;
rtcue_dur=0.75;
delay2_1=15.25;
ping_dur=0.25;
delay2_2=7.75;
sample_dur2=1;
delay3=1;
response_interval=4;

jitter_orientation=3*pi/180; % in radian
contrast=0.6;
pingcontrast=1;
devicenumber=[];

ifi = Screen('GetFlipInterval', win);

%% fMRI projecter
Distance=68.58;%cm
ScreenWidth=33.02;%cm
ScreenHeight=22.86;%cm

% Distance=45;%cm
% ScreenWidth=35;%cm
% ScreenHeight=20;%cm

%Resolution_IBP=[1200,1920];
Resolution_IBP=[rect(3), rect(4)];
PixelSize_IBP=ScreenWidth/Resolution_IBP(2);
degree_meter_IBP=2*Distance*tand(1/2);
pixel_per_degree=degree_meter_IBP/PixelSize_IBP;
disp(pixel_per_degree)
radius_in_pixel = round(radius * pixel_per_degree);
thinthickness_in_pixel = round(thinthickness * pixel_per_degree);
disp(thinthickness_in_pixel)
spatial_frequency_in_pixel = spatial_frequency / pixel_per_degree;

size_in_pixel = 2 * radius * pixel_per_degree;

xc = rect(3)/2;
yc = rect(4)/2;

width = Resolution_IBP(1);
height = Resolution_IBP(1);

%Eccentricity
Eccentricity_degree=8;
Eccentricity_meter_IBP=2*Distance*tand(Eccentricity_degree/2);
Eccentricity_pixel=Eccentricity_meter_IBP/PixelSize_IBP;
Offset_peri=round(Eccentricity_pixel);

%% Creating Stim
%0 20 40 60 80 100 120 140 160
orientation_in_degree = [20 50 80 110 140 170];  % corresponding to [20 50 80 110 140 170] in the manuscript
                        % Gratings start with 12 o'clcok and rotate clockwise

orientation_in_radian = orientation_in_degree.*pi/180;

gr_backgroundColorOffset = [0.5,0.5,0.5,0];

modulateColor=[];

[grating,gratingrect] = CreateProceduralSineGrating(win, width, height, gr_backgroundColorOffset, radius_in_pixel, 1);

% PsychImaging(‘PrepareConfiguration’);
% PsychImaging(‘AddTask’, ‘General’, ‘FloatingPoint32BitIfPossible’);
virtualSize=2*radius_in_pixel
[bullseye,bullseyerect] = CreateProceduralPolarGrating(win, virtualSize, virtualSize, [1 1 1], [0 0 0], radius_in_pixel);
radialFrequency = 0;
sigma = -1;
baseColor = [0.5 0.5 0.5 1];

%% define position shift angle (theta)
%theta=[0 pi/3 2*pi/3 pi 4*pi/3 5*pi/3];
theta=[300 0 60 120 180 240]./180*pi; %corresponding to [30 90 300 120 270 210] in the manuscript
                     %verified.
                     %X positive is down
                     %Y postive is right.  
for iloc=1:nloc
    grating_posrect{iloc}=CenterRectOnPoint(gratingrect, xc+Offset_peri*cos(theta(iloc)), yc+Offset_peri*sin(theta(iloc)));
    bullseye_posrect{iloc}=CenterRectOnPoint(bullseyerect, xc+Offset_peri*cos(theta(iloc)), yc+Offset_peri*sin(theta(iloc)));
end

wheelrect=CenterRect([0,0,2*radius_in_pixel,2*radius_in_pixel],rect);
for iloc=1:nloc
    wheel_posrect{iloc}=CenterRectOnPoint(wheelrect, xc+Offset_peri*cos(theta(iloc)), yc+Offset_peri*sin(theta(iloc)));
end

FixationRect=CenterRect([0,0,12,12],rect);
FixationRect=OffsetRect(FixationRect,0,0);

% cue_arrow0 = imread(‘arrow0.png’);
% cue_arrow0(find(cue_arrow0 < 50)) = 10;
% cue_arrow0(find(cue_arrow0 >= 50)) = gray;
%
% for iloc=1:nloc
% cue_theta{iloc}=imrotate(cue_arrow0, (-1)*theta(iloc)*180/pi, ‘loose’, ‘bilinear’);
% cue_theta{iloc}(find(cue_theta{iloc} ~= 10)) = gray;
% cue_theta{iloc}(find(cue_theta{iloc} == 10)) = black;
% cue_arrow{iloc} = Screen(‘MakeTexture’, win, cue_theta{iloc});
% end
%
% cue_rect = [0 0 35 35];
% cue_posrect=CenterRectOnPoint(cue_rect, xc, yc);

record=zeros(trialnumber,30);

%orientation_pool=[];

if CurRun==1 % create stim sequence
    trialcond = [];
    nori_pool = 1:1:nori;
    ori_both =nchoosek(nori_pool,2);
    ori_both=[ori_both; repmat(reshape(nori_pool,[],1),1,2)];
    ori_both_flp(:,[1 2])=ori_both(:,[2 1]);
    ori_both_two=[ori_both; ori_both_flp];

% ori_c=randsample(6,252,true); %replaced by Shuffle
%%
ori_c=repmat(nori_pool,1,42);
ori_c=Shuffle(ori_c).’;
%%
ori_abc= [repmat(ori_both_two,6,1),ori_c];
probe_cue=repmat([1 3],126); %1 for report A, 3 for report C
probe_cue=Shuffle(probe_cue).’;

    for nrep = 1:length(ori_abc)
        if condition==0
            loc_abc = randsample(6,3).';
        elseif condition==1
            loc_ab = randsample(6,2).';
            loc_c = loc_ab(2);
            loc_abc = [loc_ab loc_c];
        end
        
        if probe_cue(nrep)==1
            loc_probed=loc_abc(1);
            ori_probed=ori_abc(nrep,1);
        elseif probe_cue(nrep)==3
            loc_probed=loc_abc(3);
            ori_probed=ori_abc(nrep,3);
        end
    
        trialcond = [trialcond;[ori_abc(nrep,1),ori_abc(nrep,2),ori_abc(nrep,3),loc_abc(1),loc_abc(2),loc_abc(3),probe_cue(nrep),loc_probed,ori_probed]];
    end
    
    %trialcond;
    trialcond = Shuffle(trialcond,2);
    save(['parameters_ovlp'  int2str(condition) '_' subName '.mat'],'trialcond');
else
    load(['parameters_ovlp'  int2str(condition) '_'  subName '.mat']); 
end
%trialcond %1-ori1 %2-ori2 %3-loc1 %4-loc2 %5-cueswitch %6-cue_order %7-ori_dist %8-loc_dist
%9-direction_ori %10-direction_loc
current_cond=trialcond(trialnumber*(CurRun-1)+1:trialnumber*CurRun,:);

orientation_a=current_cond(:,1)';
orientation_b=current_cond(:,2)';
orientation_c=current_cond(:,3)';
loc_a = current_cond(:,4)';
loc_b = current_cond(:,5)';
loc_c = current_cond(:,6)';
cue_probe=current_cond(:,7)';
loc_probed=current_cond(:,8)';
ori_probed=current_cond(:,9)';

%save(['run_cond' num2str(subName) '_' num2str(CurRun) '.mat'],'orientation_target', 'orientation_ntarget',...
   % 'loc_target','loc_ntarget', 'cue_switch','cue_order');

%response_times=repmat({0},1,trialnumber);
itipossiblility=[6 8 10];
ITIa=Shuffle(repmat(itipossiblility,1,12/3));
exindex=mod(CurRun,3);
if exindex==0
    exindex=3;
end
ITIex=itipossiblility(exindex);
ITIb = itipossiblility(itipossiblility~=ITIex);
ITI=Shuffle([ITIa,ITIb]);

test_jitter=randsample(90,trialnumber,true)-1;

for i=1:trialnumber
    samplejitter_orientation1(i)=(-1)^(round(rand))*jitter_orientation*rand(1);
    samplejitter_orientation2(i)=(-1)^(round(rand))*jitter_orientation*rand(1);
    samplejitter_orientation3(i)=(-1)^(round(rand))*jitter_orientation*rand(1);
    testjitter_orientation(i)=round((-1)^(round(rand))*test_jitter(i))*pi/180;
end

Screen('TextSize',win,24);
if condition==0
    instructions=['In this run the third item will always appear at a new location.'];
elseif condition==1
    instructions=['In this run the third item will always appear at the same location as the useless one.'];
end
instructions=WrapString(instructions,40);
Screen(win, 'FillRect', gray);
Screen('FillOval', win, white, FixationRect);
DrawFormattedText(win, instructions, 'center', 'center', black);
Screen('Flip',win);

if listenScan
     %wait for button box to send QWERTY '5%'

% start = KbCheck(devicenumber,‘5%’);
%
% byte = KbCheck(devicenumber,‘5%’);
%
% fprintf(‘Start byte: %d\n’,start);
%
% while byte == start
%
% byte = KbCheck(devicenumber,‘5%’);
%
% end

    triggerKey = KbName('5%');
    % loop for the start screening waiting for the scanner to start 
    goTime = 0;
    kb.keyWasDown=0;
    % wait for scanner to start
    while ~goTime % need to trigger the start
        [kb.keyIsDown, kb.secs, kb.keyCode] = KbCheck(-1); % query the keyboard
        if kb.keyIsDown && kb.keyCode(triggerKey) 
            triggerInd = find(kb.keyCode==1); % need to know what number the 't' key corresponds to on the system if we're going to disable it later (and each system is slightly different)...
            t0 = kb.secs;
            keyTime = kb.secs - t0; % first trigger will count as time zero
            %allKeyPresses(end+1,:) = [triggerKey keyTime]; % record
            goTime=1;
        end
    end
else
    KbWait;
end

t0=GetSecs;

HideCursor;
Screen(win, 'FillRect', gray);
Screen('FillOval', win, white, FixationRect);
Screen('Flip',win);
WaitSecs(paddingtime);

%record %1-orientation_target %2-orientation_ntarget %3-ITI %4-cue_order
%5-cue_switch %6-remembered_orientation1(after_jitter)
%7-remembered_orientation2 %8-samplejitter_ori %9-testjitter_ori1
%9-testjitter_ori2 %10-test_orientation1 %11-testjitter_ori2
%12-test_ori2 %13-response_ori1 %14-gotresp1 %15-resp1RT 
%16-response_ori2 %17-gotresp2 %18-resp2RT %19-angle_diff1
%20-angle_diff2 %21- %22- %23-performance1(1:<15, -1:<30,-99:>30deg)
%24-performance %25-sample_ori1_convt %26-sample_ori2_convt
%27-loc_target %28-loc_ntarget %29-ori_distance %30-loc_distance
record = struct;
for i=1:trialnumber
    
    record.ori_a=orientation_a;
    record.ori_b=orientation_b;
    record.ori_c=orientation_c;
    record.ITI=ITI;
    record.ITIex=ITIex;
    record.cue_probe=cue_probe;
    record.loc_a=loc_a;
    record.loc_b=loc_b;
    record.loc_c=loc_c;
    if cue_probe(i)==1
        ori_to_report=orientation_a(i);
        record.ori_to_report(i)=orientation_a(i);
    elseif cue_probe(i)==3
        ori_to_report=orientation_c(i);
        record.ori_to_report(i)=orientation_c(i);
    end
    
    remembered_orientation1=orientation_in_radian(orientation_a(i))+samplejitter_orientation1(i);
    remembered_orientation2=orientation_in_radian(orientation_b(i))+samplejitter_orientation2(i);
    remembered_orientation3=orientation_in_radian(orientation_c(i))+samplejitter_orientation3(i);
    
    test_orientation=orientation_in_radian(ori_to_report)+testjitter_orientation(i);
    
    record.rem_ori1(i)=remembered_orientation1;
    record.rem_ori2(i)=remembered_orientation2;
    record.rem_ori3(i)=remembered_orientation3;
    
    record.samplejitter_ori1(i)=samplejitter_orientation1(i);
    record.samplejitter_ori2(i)=samplejitter_orientation2(i);
    record.samplejitter_ori3(i)=samplejitter_orientation3(i);
    record.testjitter_ori(i)=testjitter_orientation(i);
    record.test_ori(i)=test_orientation;
    
    if cue_probe(i)==1
        record.ori_to_report_jittered(i)=remembered_orientation1;
        ori_to_report_jittered=remembered_orientation1;
    elseif cue_probe(i)==3
        record.ori_to_report_jittered(i)=remembered_orientation3;
        ori_to_report_jittered=remembered_orientation3;
    end
    record.loc_probed(i)=loc_probed(i);
    
    Screen(win, 'FillRect', gray);
    Screen('DrawTexture', win, grating, gratingrect, grating_posrect{loc_a(i)}, remembered_orientation1*180/pi, [], [], modulateColor, [], [], [180*rand(1)+180, spatial_frequency_in_pixel, contrast, 0]);
    Screen('DrawTexture', win, grating, gratingrect, grating_posrect{loc_b(i)}, remembered_orientation2*180/pi, [], [], modulateColor, [], [], [180*rand(1)+180, spatial_frequency_in_pixel, contrast, 0]);
    
    Screen('FillOval', win, white, FixationRect); 
    Screen('Flip',win);
    WaitSecs(sample_dur1);
    %sec8_5 = GetSecs-t0
    
    Screen(win, 'FillRect', gray);
    Screen('FillOval', win, white, FixationRect);
    Screen('Flip',win);
    WaitSecs(delay1);
    %sec9_5 = GetSecs-t0
    
    Screen(win, 'FillRect', gray);
    Screen('FillOval', win, white, FixationRect);
    Screen('FrameOval', win, white, wheel_posrect{loc_a(i)}, thinthickness_in_pixel); %%to be tested
    Screen('Flip',win);
    WaitSecs(rtcue_dur)
    
    Screen(win, 'FillRect', gray);
    Screen('FillOval', win, white, FixationRect);
    Screen('Flip',win);
    WaitSecs(delay2_1)
    
    Screen(win, 'FillRect', gray);
    Screen('FillOval', win, white, FixationRect);

% Screen(‘DrawTexture’, win, grating, gratingrect, grating_posrect{loc_a(i)}, remembered_orientation1180/pi, [], [], modulateColor, [], [], [180rand(1)+180, spatial_frequency_in_pixel, contrast, 0]);
% this=[bullseye_posrect{loc_a(1)}.’,bullseye_posrect{loc_a(2)}.’,bullseye_posrect{loc_a(3)}.’,bullseye_posrect{loc_a(4)}.’,bullseye_posrect{loc_a(5)}.’,bullseye_posrect{loc_a(6)}.’]
randphase = 180*rand(1)+180;
for thisping=1:6
Screen(‘DrawTexture’, win, bullseye, bullseyerect, bullseye_posrect{thisping},…
0, [], [], grayforping, [], [],…
[randphase, radialFrequency, pingcontrast, sigma, spatial_frequency_in_pixel, 0, 0, 0]);
end

    Screen('Flip',win);
    WaitSecs(ping_dur)
    
    Screen(win, 'FillRect', gray);
    Screen('FillOval', win, white, FixationRect);
    Screen('Flip',win);
    WaitSecs(delay2_2)
    
    Screen(win, 'FillRect', gray);
    Screen('DrawTexture', win, grating, gratingrect, grating_posrect{loc_c(i)}, remembered_orientation3*180/pi, [], [], modulateColor, [], [], [180*rand(1)+180, spatial_frequency_in_pixel, contrast, 0]);
    
    Screen('FillOval', win, white, FixationRect);
    Screen('Flip',win);
    WaitSecs(sample_dur2);
    %sec10 = GetSecs-t0
    
    Screen(win, 'FillRect', gray);
    Screen('FillOval', win, white, FixationRect);
    Screen('Flip',win);
    WaitSecs(delay3);
    %sec18 = GetSecs-t0
 
    
    t1=GetSecs;
    gotResponse = 0;
    test_theta = test_orientation;
    
    xwheel=round(xc+Offset_peri*cos(theta(loc_probed(i))));
    ywheel=round(yc+Offset_peri*sin(theta(loc_probed(i))));
    current_frame = 0;
    %SetMouse(xwheel,ywheel,win);        
    %ShowCursor;        vvffb
    %SetMouse(xc,yc,win);
    SetMouse(round(cos(test_theta)*radius_in_pixel+xwheel), round(-sin(test_theta)*radius_in_pixel+ywheel),win);
    Screen('FrameOval', win, black, wheel_posrect{loc_probed(i)}, thinthickness_in_pixel);
    Screen('DrawLine', win, black, -cos(test_theta)*radius_in_pixel+xwheel, sin(test_theta)*radius_in_pixel+ywheel, ...
        cos(test_theta)*radius_in_pixel+xwheel, -sin(test_theta)*radius_in_pixel+ywheel, thinthickness_in_pixel);
    Screen('Flip', win);
    while (GetSecs-t0)<(i*(sample_dur1+delay1+rtcue_dur+delay2_1+ping_dur+delay2_2+sample_dur2+delay3+response_interval)+sum(ITI(1,1:i-1))+paddingtime)
        if gotResponse == 0
            [xPos, yPos, buttons] = GetMouse(win);
            test_theta=atan2((ywheel-yPos),(xPos-xwheel)); %start with rightward axis and rotate counterclockwise. i.e. angular coordinate
                                                                                                 %range from -pi to pi
            
            if (xPos > (.99*(xc*2))) || (xPos < (.01*(xc*2)))||(yPos > (.99*(yc*2))) || (yPos < (.01*(yc*2)))
                SetMouse(round(cos(test_theta)*radius_in_pixel+xwheel), round(-sin(test_theta)*radius_in_pixel+ywheel),win);
            end
        end
        
        if any(buttons)
            gotResponse = 1;
            timeoutDir = nan;
            record.gotResp1(i) = 1;
            record.gotResp12(i) = nan;
            if current_frame ==0
                record.RT1(i) = GetSecs - t1;
            end
            current_frame=current_frame+1;
        else
            gotResponse = 0;
            timeoutDir = 1;
            record.gotResp1(i) = 0;
            record.gotResp12(i) = 1;
            record.RT1(i) = GetSecs - t1;
        end
                    
        response_orientation = test_theta;
        
        record.ori_resp(i) = response_orientation;
        
        % Calculate RespError
        %record(i,19) = circ_dist(sample_orientation,response_orientation);
        
        if mod(ori_to_report_jittered,pi)>pi/2
            ori_to_report_jt_convt=3*pi/2-ori_to_report_jittered;
        else
            ori_to_report_jt_convt=pi/2-ori_to_report_jittered;    %converted to start with rightward axis and rotate counterclockwise. i.e. angular coordinate 
        end
        
        record.ori_to_report_jt_convt(i)=ori_to_report_jt_convt;
        
        %angle_diff=ori_to_report_jt_convt-mod(response_orientation,pi);
        angle_diff=mod(response_orientation,pi)-mod(ori_to_report_jt_convt,pi);
        
        if angle_diff>pi/2
            %angle_diff=pi-angle_diff;
            angle_diff=angle_diff - pi;
        elseif angle_diff<-pi/2
            angle_diff=angle_diff+pi;
        end
        
        record.angle_diff(i)=angle_diff;
        
        if gotResponse == 1
            if abs(angle_diff) < 15*pi/180
                record.resp_good(i) = 1;
                text1 = [num2str(abs(round(angle_diff/pi*180))) ' degrees off'];
                %text1='Good!';
            elseif abs(angle_diff) < 30*pi/180
                record.resp_good(i) = -1;
                text1 = [num2str(abs(round(angle_diff/pi*180))) ' degrees off'];
                %text1='OK!';
            else
                record.resp_good(i) = -99;
                text1 = [num2str(abs(round(angle_diff/pi*180))) ' degrees off'];
                %text1='Poor!';
            end
        else
            record.resp1_good(i) = nan;
            text1='No Response!';
        end
        
        Screen('FrameOval', win, black, wheel_posrect{loc_probed(i)}, thinthickness_in_pixel);
        if gotResponse == 0
            Screen('DrawLine', win, black, -cos(test_theta)*radius_in_pixel+xwheel, sin(test_theta)*radius_in_pixel+ywheel, ...
                cos(test_theta)*radius_in_pixel+xwheel, -sin(test_theta)*radius_in_pixel+ywheel, thinthickness_in_pixel);
        else
            Screen('DrawLine', win, black, -cos(test_theta)*radius_in_pixel+xwheel, sin(test_theta)*radius_in_pixel+ywheel, ...
                cos(test_theta)*radius_in_pixel+xwheel, -sin(test_theta)*radius_in_pixel+ywheel, thinthickness_in_pixel*2);
        end
        Screen('FillOval', win, white, FixationRect);
        Screen('Flip', win);
    end
    %sec30_75 = GetSecs-t0
    
    
    
    %HideCursor;

% time=GetSecs-t0;
% feedbacktext=['First item: ’ text1 ‘\n’ 'Second item: ’ text2];
% feedbacktext=WrapString(feedbacktext,100);
% Screen(win, ‘FillRect’, gray);
% Screen(‘FillOval’, win, white, FixationRect);
% DrawFormattedText(win, feedbacktext, ‘center’, ‘center’, black);
% Screen(‘Flip’,win);
% WaitSecs(1);

    %sec39 = GetSecs-t0
    
    Screen(win, 'FillRect', gray);
    Screen('FillOval', win, white, FixationRect);
    
    
    if ispractice==1
        text1=['You are: ' text1 ];
        text1=WrapString(text1,100);
        DrawFormattedText(win, text1, 'center', 'center', black);
        Screen('Flip',win);
        WaitSecs(4);
    else
        Screen('Flip',win);
    end
    
    while (GetSecs-t0)<(i*(sample_dur1+delay1+rtcue_dur+delay2_1+ping_dur+delay2_2+sample_dur2+delay3+response_interval)+sum(ITI(1,1:i))+paddingtime)
    end
    time=GetSecs-t0
    
end

mean_error=sum(abs(record.angle_diff))/trialnumber*180/pi;

try
    save(filename,'record','mean_error','loc_probed','ori_probed','loc_a','loc_b','loc_b','orientation_a','orientation_b','orientation_c');
catch
end
%save(['record' subName '.mat'],'record','mean_error1','mean_error2','mean_error','loc_target','loc_ntarget','orientation_target','orientation_ntarget');
if mean_error<15
    performance_text='good';
elseif mean_error<30
    performance_text='OK';
else
    performance_text='poor';
end
meanacctext = ['You are: ' num2str(abs(round(mean_error))) ' degrees off'];
feedbacktext=['Your overall performance for this block is: ' performance_text '\n' meanacctext];
feedbacktext=WrapString(feedbacktext,40);
Screen(win, 'FillRect', gray);
Screen('FillOval', win, white, FixationRect);
DrawFormattedText(win, feedbacktext, 'center', 'center', black);
Screen('Flip',win);
WaitSecs(5);

Screen(win, 'FillRect', gray);
Screen('FillOval', win, white, FixationRect);
Screen('Flip',win);
WaitSecs(ITIex-5);

Screen('CloseAll');
IOPort('CloseAll');
ShowCursor;

catch
%this “catch” section executes in case of an error in the “try” section
%above. Importantly, it closes the onscreen window if its open.
Screen(‘CloseAll’);
Priority(0); %Usage: oldPriority=Priority([newPriority])
psychrethrow(psychlasterror); %same as ‘rethrow’: reissure error; rethrow(err),usually used in ‘try-catch’ statement

end %try…catch…

end

Try running one of the demos is the psychdemos folder which has something to do with text. If that stays on a blank screen, just let it stay there. May take some minutes. After that, text will appear. See if that fixes the issue for the bext run and with your other script. If not, search the forum for fontconfig trouble and follow instructions about clearing the cache and such that you find there

Thanks for the help! :slight_smile:

Tried, but this didn’t resolve. I’ll follow your suggestion to look for fontconfig issue. (Even though the program doesn’t use text, just pictures)

It was a shot in the dark. If there is no text rendering in the program, it won’t help.
Try diary on to hopefully store any potentially useful output (and add disp statement throughout the code to see how far the program gets). I won’t read the code, too long. Try to remove everything you can, so you produce a minimal example of the problem (and probably find out what is causing it while doing that). Another shot in the dark is that there is a Screen Flip somewhere with a deadline far in the future

There’s also echo on which goes nicely with diary on to automatically print all executed commands to the command window. Skimming, the script above does use text rendering, so that can’t be ruled out as one possible troublemaker. Repeated clicking with the mouse while the script is frozen for a while, e.g., long flip as Diederick suggested, would indeed bring the busy cursor and trouble on MS-Windows. For any further paid support from myself → help PsychPaidSupportAndServices.

Update => Solved

Thanks everyone! I ended up solving the issue by staging an Ubuntu computer and running Matlab from there. It’s a bit cumbersome, but it works flawlessly as a workaround while I figure out a better solution. (Currently experimenting with running it in a Docker container, or under WSL on the previous Windows computer)

Switching to native Linux is the best solution for most tasks.

Running Linux on top of Windows from a docker container or WSL2 will not provide any reliable timing and is not officially supported.