Tetris-like experiment, a lot of lagging

Dear all

I have a macbook pro and I use matlab 2019 and PTB3 for the creation of an experiment which is like tetris. There are some X dropping from the top of the screen and the user has to move the cursor to catch these X at the lower level of the screen.

The code is fine and it works however, some times, there is a bit of lag that can be felt when running the experiment. It is like the whole tetris-like experiment gets into slow motion.

Is there any step/way to fix this?

I see these lines on the command line after running my code:

PTB-INFO: Retina display. Enabling panel fitter for scaled Retina compatibility mode.

PTB-INFO: Psychtoolbox imaging pipeline starting up for window with requested imagingmode 33793 …
PTB-INFO: Will use 8 bits per color component framebuffer for stimulus drawing.
PTB-INFO: Enabling panel fitter. Providing virtual framebuffer of 1792 x 1120 pixels size.
PTB-INFO: Will use 8 bits per color component framebuffer for stimulus post-processing (if any).

Does it have to do with my MacBook screen specs?

I develop on a macbook pro, and timing on my retina display is terrible (but good enough for developing, but I’d never use it for data collection…) You should be testing on an external display that should be better (though that depends on bugs and your GPU). You cannot at this stage trust macOS to deliver good timing anymore for any data collection…

1 Like

Thanks for the reply. I also use my MacBook pro for development. But I cannot even do some beta testing. I will use an external monitor to run my experiment and see if the lag disappears. Thanks for the tip.

Hi again.

In my script I use some commands like Screen('Preference', 'SkipSyncTests', 0); and [w, ~] = Screen('OpenWindow', screenNumber, [0 0 0]);, Priority(MaxPriority(w)); but still there is a slight lag when using an external monitor with my MacBook.

Have you found any specific command that helps with the lag?

I don’t have any Mac more modern than MBP 2017, so ofc. this could be some new types of macOS bugs. But wrt. timing, Retina display visual timing is at least expected to be fine with the PsychImaging('AddTask', 'General', 'UseRetinaResolution'); task, or maybe with one or two of the video resolutions you can select in the display settings UI – different settings trigger different macOS video rescaling bugs that affect timing, but at least on my MBP 2017 one or two of them worked ok’ish.

But the lag could also be caused by your script, so the first check would be running some of our demos and see if they drop frames, and follow various posts on this forum wrt. optimizations. Or test on a non-mac if your script lags.

Dear Mario,

Thanks a lot for the help.

I will try to add your command and see if things improve. Indeed, I have a more modern MBP 19 and thus new bugs can be the problem. If I can provide more info let me know.

Concerning the code, it has been previously used successfully without problems and I have only modified some parts that do not affect the stimulus or frames number. So, I suspect the problem is related to my computer.

Moreover, when I use an external monitor, things get better but there is still some small lag. In that case, I have to use an adaptor like this to connect my external monitor to my MBP19. Again, this could be the problem or even the screen. I will try to modify the display resolution from settings and see if this helps.

More help from my side beyond this response - without any guarantee of any success - would require paid support → help PsychPaidSupportAndServices

That sounds like trouble caused by macOS. A few observations:

  • MBP 2019 has the new AMD Navi graphics with the new RDNA gpu architecture, which needed different graphics drivers than older GCN generations. Given that in 2019 Apple already knew they would ditch IntelMacs and AMD/Intel graphics and roll their own proprietary solution, i wouldn’t be surprised if they half-assed driver support for these new AMD gpu’s and performance would be way poorer than expected. Maybe a script that worked fine on other/older Macs would need extra optimizations to deal with potentially poor Apple graphics drivers for Navi.

  • If you run an external display, always run it at its native resolution and refresh rate, or extra lag and timing artifacts may be introduced by the displays panel scaler.

  • Our own timestamping and scripts like VBLSyncTest should at least give some rough idea if lag is caused by your script/poor graphics performance. If it suggests skipped frames, then there are likely ones, if it says everything is fine then it may still be broken – impossible to tell without PsychtoolboxKernelDriver support on your MBP 2019, or with other new macOS bugs, unless you use careful photodiode measurements.

  • Here’s a link to a project that tries to get Linux to work ok’ish on MBP 2018 and later, in case you’d want to try. I’d expect visual stimulation timing and capabilities to be much better under Linux if you manage to navigate all the remaining pitfalls or hacks to get it installed and working at all: https://t2linux.org

1 Like

Dear Mario.

Thanks a lot for all this information.

Just to add that VBLSyncTest seems to fail when I run it on my MBP19 using my native screen (no external monitor).

>> VBLSyncTest
Tried to prepare a new configuration phase via PsychImaging('PrepareConfiguration'), but did not finalize the previous phase yet.
You must call the PsychImaging('OpenWindow', ...); command at least once to open an onscreen
window according to the provided settings, before you can specify settings for additional onscreen windows.

The most likely reason you see this error message is because your script aborted with some error
before it managed to open the onscreen window. In that case it is best practice to execute a 'clear all'
command at the Matlab/Octave prompt before you restart your script.

I will restart configuration now and forget the previously made PsychImaging('AddTask', ...); settings.
Warning: Tried to prepare a new configuration phase, but you did not finalize the previous phase yet! 
> In PsychImaging (line 1660)
  In VBLSyncTest (line 281) 

ans =


PTB-INFO: This is Psychtoolbox-3 for Apple OS X, under Matlab 64-Bit (Version 3.0.17 - Build date: Apr 18 2021).
PTB-INFO: OS support status: OSX version 11.0 is not yet tested or officially supported at all for this Psychtoolbox release.
PTB-INFO: Type 'PsychtoolboxVersion' for more detailed version information.
PTB-INFO: Most parts of the Psychtoolbox distribution are licensed to you under terms of the MIT License, with
PTB-INFO: some restrictions. See file 'License.txt' in the Psychtoolbox root folder for the exact licensing conditions.

PTB-INFO: For information about paid priority support, community membership and commercial services, please type
PTB-INFO: 'PsychPaidSupportAndServices'.

PTB-WARNING: Pageflipping wasn't used at all during refresh calibration [0 of 301].
PTB-WARNING: Visual presentation timing is broken on your system and all followup tests and workarounds will likely fail.
PTB-WARNING: On this Apple macOS system you probably don't need to even bother asking anybody for help.
PTB-WARNING: Just upgrade to Linux if you care about trustworthy visual timing and stimulation.

PTB-INFO: OpenGL-Renderer is ATI Technologies Inc. :: AMD Radeon Pro 5500M OpenGL Engine :: 2.1 ATI-4.6.20
PTB-INFO: Renderer has 4080 MB of VRAM and a maximum 3829 MB of texture memory.
PTB-INFO: VBL startline = 1920 , VBL Endline = -1
PTB-INFO: Beamposition queries unsupported or defective on this system. Using basic timestamping as fallback.
PTB-INFO: Timestamps returned by Screen('Flip') will be therefore less robust and accurate.
PTB-INFO: Measured monitor refresh interval from VBLsync = 16.674718 ms [59.971028 Hz]. (300 valid samples taken, stddev=2.138964 ms.)
PTB-INFO: Reported monitor refresh interval from operating system = 16.666756 ms [59.999680 Hz].
PTB-INFO: Small deviations between reported values are normal and no reason to worry.

WARNING: Couldn't compute a reliable estimate of monitor refresh interval! Trouble with VBL syncing?!?


One or more internal checks (see Warnings above) indicate that synchronization
of Psychtoolbox to the vertical retrace (VBL) is not working on your setup.

This will seriously impair proper stimulus presentation and stimulus presentation timing!
Please read 'help SyncTrouble' for information about how to solve or work-around the problem.
You can force Psychtoolbox to continue, despite the severe problems, by adding the command
Screen('Preference', 'SkipSyncTests', 1); at the top of your script, if you really know what you are doing.

Error using Screen
See error message printed above.

Error in PsychImaging (line 2330)
            [win, winRect] = Screen('OpenWindow', screenid, clearcolor, winRect, pixelSize, numbuffers, stereomode, multiSample, imagingMode, specialFlags,
            clientRect, fbOverrideRect, vrrParams);

Error in VBLSyncTest (line 295)
    w = PsychImaging('OpenWindow',screenNumber, 0, [], [], [], stereo);

Yes, that looks pretty bad, timing-wise. But also i don’t know why you’d get the pageflip warning, given that our PsychtoolboxKernelDriver can not operate your AMD gpu and should not be used at all, maybe some bug in our detection logic for unsupported gpus. It’s baffling how it could even do the pageflip test on your 3.0.17 PTB under these conditions.

  1. Update to the lastet PTB 3.0.18, your 3.0.17 is unsupported.
  2. Uninstall the useless for your machine PsychtoolboxKernelDriver and reboot.
  3. Retry with different display resolution settings from the display settings GUI.

For any further questions → PsychPaidSupportAndServices.

Dear community and @mariokleiner,

I have a solution to this issue that is a bit crazy and I wanted to share it with the community to help other users.

Apparently, for some unknown reason, then I launch Matlab by clicking on the app icon, the Matlab and PTB lag.

On the other hand, after reading a looot of topics in mathworks forums, if I launch matlab via the terminal by typing /Applications/MATLAB_R2022a.app/bin/matlab -nodesktop and then type desktop to open the GUI, everything works perfectly.

It solved my issue as crazy as it sounds, and the Tetris PTB code works like a charm.


Sounds indeed crazy, so some really weird Matlab bug on macOS? That’s a new one.
I’d recommend reporting this to Mathworks as a bug report, this should not happen.

Indeed. it has been reported a lot of times in MathWorks forums.

Maybe provide a few links to such reports in the MW forums, for myself and others as a reference.


Sure here are only some:

For the record, only the answer (solution) provided here did the trick for me.

1 Like