Closing window without waiting for AsychFlip

Hi everyone,

I’ve setup a Psychtoolbox experiment that uses a main loop to check for specific (3rd party hardware) input while calls to AsyncFlipBegin and AsyncFlipCheckEnd are being made to control what is drawn on the screen.

All the way at the end of that loop, the following code checks whether the escape-key is pressed:

[~, ~, code] = KbCheck(-1);
if code(27)
    running = 0;
    break;
end

Pressing esc immediately breaks the loop and should end the program.
Straight after the loop sca() is called. Exiting the loop works perfectly, I’ve checked with console output.

However, the problem is that it (sca) waits for asynchronous flips to finish (AsyncFlipEnd is in there), causing a 10 to 20-second delay for the window to close. I had no luck finding a psychtoolbox function to interrupt the AsyncFlipBegin call, nor could I find a solution on this forum.

Interrupting such an asynchronous event or closing down the Psychtoolbox/GL loop before a planned event seems pretty straightforward, so I probably overlooked something very simple.
Would you be able to point me in the right direction?

Thanks in advance

Max

Would it help to do AsyncFlipEnd right before you break out after ESC is pressed?

That’s intentional and necessary that you have to wait for async flips to complete before closing the window.

You could call Screen(‘CloseAll’) before sca; to force a shutdown, but that will print some angry warnings and is not recommended, as in some cases it can cause Matlab/Octave to hang or crash.

-mario

I don’t think so, calling AsyncFlipEnd would only shift the wait (that now happens in sca) forward, but not interrupt the wait.

I see, so there is no way to interrupt a pending async flip.
Too bad, I guess I will just use Screen(‘CloseAll’) and cross my fingers that matlab survives :slight_smile:

Thank you!