# Screen freezing on opening screen('Flip')

**URL:** <https://psychtoolbox.discourse.group/t/screen-freezing-on-opening-screen-flip/3865>\
**Category:** Programming Help\
**Created:** [May 14, 2021, 7:32am UTC](https://psychtoolbox.discourse.group/t/screen-freezing-on-opening-screen-flip/3865 "2021-05-14T07:32:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mindexplorer](https://avatars.discourse-cdn.com/v4/letter/m/aeb1de/32.png) [@mindexplorer](https://psychtoolbox.discourse.group/u/mindexplorer)\
**Post date:** [May 14, 2021, 7:32am UTC](https://psychtoolbox.discourse.group/t/screen-freezing-on-opening-screen-flip/3865/1 "2021-05-14T07:32:39Z")

</div>

Hi,

I am having trouble getting my code to run. It keeps getting stuck on the beginning screen in which I have a bit of text saying “Press any key to begin”. The script I am using is below.

%% to open the screen  
screens=Screen(‘Screens’);  
screenNumber=max(screens);  
[w1,rect]=Screen(‘OpenWindow’,screenNumber,0); %Opens screen, generate w1(numeric window value) and rect (screen coordinates)  
[center(1),center(2)] = RectCenter(rect); %compute center of screen  
Priority(MaxPriority(w1)); %Prioritises experiment window so no pop ups occur  
HideCursor();

Screen(‘DrawText’,w1,‘Press any key to begin’,center(1)-100,center(2)-10,255);  
Screen(‘Flip’,w1);  
pause;  
Screen(‘Flip’,w1);  
WaitSecs(1);

Then the code goes into an if loop to present the stimuli. Sometimes if I wait long enough on the initial screen it will present the stimuli. So I know the stimuli works but I am not sure why my screen is getting frozen on this initial screen for so long.

When I close the window I get the following error message:

Error in function Flip: Invalid Window (or Texture) Index provided: It doesn’t correspond to an open window or texture.

Does anyone have any ideas how I can troubleshoot this please?

---

<div class="post-metadata">

**Author:** ![dcnieho](https://avatars.discourse-cdn.com/v4/letter/d/779978/32.png) [@dcnieho](https://psychtoolbox.discourse.group/u/dcnieho)\
**Post date:** [May 14, 2021, 1:27pm UTC](https://psychtoolbox.discourse.group/t/screen-freezing-on-opening-screen-flip/3865/2 "2021-05-14T13:27:26Z")

</div>

Don’t use pause but `KbStrokeWait`, see if that helps

---

<div class="post-metadata">

**Author:** ![mindexplorer](https://avatars.discourse-cdn.com/v4/letter/m/aeb1de/32.png) [@mindexplorer](https://psychtoolbox.discourse.group/u/mindexplorer)\
**Post date:** [May 17, 2021, 3:33am UTC](https://psychtoolbox.discourse.group/t/screen-freezing-on-opening-screen-flip/3865/3 "2021-05-17T03:33:01Z")

</div>

Ahh amazing thank you so much!
