Response task freezes 30 minutes into the experiment

Hi,
I am using the latest version of PTB on windows and Matlab R2020a. This is my first experience using PTB. My script works fine for about 30 min but then the response task suddenly freezes. The task is a method of adjustment task where a random face image is presented and the participants adjust the face by flipping through an image file containing a 142 image continuum and submit a chosen image as thier response. I used the same task in Matlab without PTB and it works fine. Anyone got any idea why it suddenly freezes? The relevant bit of code is listed below. Many thanks!

 while time < inf
                [keyIsDown, t2, keyCode] = KbCheck;
                time = t2-t1;
                FlushEvents;
                if keyIsDown
                    if keyCode(right) % press right arrow key to move to next image
                        if af1 == stimulus % stimulus is length of image file, 142 images
                            af1 = 1; % af1 = random face image
                        else
                                af1 = af1+1;
                        end
                        texture = Screen('MakeTexture', window, firstface{af1});
                        Screen('DrawTexture', window, texture);
                        Screen('Flip', window);
                        elseif keyCode(left) % press left arrow key to move to previous image
                            if af1 == 1
                                af1 = stimulus;
                            else
                                    af1 = af1-1;
                            end
                            texture = Screen('MakeTexture', window, firstface{af1});
                            Screen('DrawTexture', window, texture);
                            Screen('Flip', window);
                            elseif keyCode(done) % submit response image
                                response_time(i,j) = time;
                                response(i,j) = af1;
                                break;

You should not keep making new textures without closing the old one first, for speed you can preload all your textures before your main experimental loop if you have enough memory…

Closing the old textures did the trick. Many thanks!