# Async Flips and non-fullscreen windows

**URL:** <https://psychtoolbox.discourse.group/t/async-flips-and-non-fullscreen-windows/3625>\
**Category:** Programming Help\
**Tags:** experiment-design\
**Created:** [January 19, 2021, 9:56am UTC](https://psychtoolbox.discourse.group/t/async-flips-and-non-fullscreen-windows/3625 "2021-01-19T09:56:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ian-Max-Andolina](https://yyz2.discourse-cdn.com/free1/user_avatar/psychtoolbox.discourse.group/ian-max-andolina/32/4_2.png) [@Ian-Max-Andolina](https://psychtoolbox.discourse.group/u/Ian-Max-Andolina)\
**Post date:** [January 19, 2021, 9:56am UTC](https://psychtoolbox.discourse.group/t/async-flips-and-non-fullscreen-windows/3625/1 "2021-01-19T09:56:26Z")

</div>

Using Ubuntu 20.10 with two X-screens, we are drawing into our main stimulus display (X-screen 1) using synchronous flips without issue. I also wanted to open a small non-fullscreen window on the operator screen (X-screen 0 showing the MATLAB interface), where I can lazily draw the subject eye position (i.e. timing or fidelity is totally not an issue). I use PsychImaging to open both windows. As I don’t want to cause any timing delays for my stimulus, I exerpimented with ASync flips. The first async flip is fine, but if I draw before it completes, then I get an error:

```auto
Error in function gluDisk: Usage error
Tried to draw into onscreen window with async flip pending and imaging pipeline off. Forbidden!

```

However, I **did** use the imaging pipeline to open both windows. My workaround is to use AsyncFlipCheck as a conditional for drawing, but just wondered if this was strictly necessary as the docs for asyncflip suggest we can draw during the async state when the imaging pipeline is used?

---

<div class="post-metadata">

**Author:** ![mariokleiner](https://avatars.discourse-cdn.com/v4/letter/m/13edae/32.png) [@mariokleiner](https://psychtoolbox.discourse.group/u/mariokleiner)\
**Post date:** [January 19, 2021, 6:38pm UTC](https://psychtoolbox.discourse.group/t/async-flips-and-non-fullscreen-windows/3625/2 "2021-01-19T18:38:28Z")

</div>

That’s because the pipeline didn’t really enable if you didn’t specify some ‘AddTask’ that actually requires it. `PsychImaging('OpenWindow')` on itself just turns into `Screen('OpenWindow')` in such scenarios, as the pipeline does come with a small amount of overhead if actually enabled, so one wants to avoid redundant enables. `PsychImaging('AddTask', 'General', 'UserVirtualFramebuffer') `will enable a minimal pipeline and then it likely would work.

But a better way for your case is just to call `Screen('Flip', win, [], [], 2)` to run that windowed window without vsync or blocking waits for flip completion. Much simpler, less overhead, given that you won’t mind some potential minimal tearing.

-mario

---

<div class="post-metadata">

**Author:** ![Ian-Max-Andolina](https://yyz2.discourse-cdn.com/free1/user_avatar/psychtoolbox.discourse.group/ian-max-andolina/32/4_2.png) [@Ian-Max-Andolina](https://psychtoolbox.discourse.group/u/Ian-Max-Andolina)\
**Post date:** [January 21, 2021, 12:18am UTC](https://psychtoolbox.discourse.group/t/async-flips-and-non-fullscreen-windows/3625/3 "2021-01-21T00:18:49Z")

</div>

Indeed, I just reread the documentation for `PsychImaging('AddTask', 'General', 'UseFastOffscreenWindows')` and see it doesn’t enable the pipeline if used alone (this is my basic setup if I don’t enable a 32bit buffer etc.), thats why it gave me that error.

And yes, the asynchronous `Screen('Flip',win,[],[],2)` works just as well (or better) for my purpose. I remember testing a few years ago and came away with the impression the AsyncFlip was faster, but I just did some profiling and both AsyncFlip and Flip[dontsync=2] take about 1.1ms to return, so there is not any advantage as far as I can see.

The resultant performance is great (at least on Linux). Our main stimulus is procedurally animated in real-time and no frames are lost on the stimulus display when also drawing the eye position and some other stuff to the non-fullscreen window. I initially put in a frame-throttle (draw the eye position every N frames of the stimulus to reduce overhead), but can see no difference with that throttle engaged in terms of performance and dropped frames.
