| Reference | Downloads | Github

Online video study causing WebGL errors

URL of experiment:

Description of the problem:
We have encountered a variable error that is reported in the javascript console as a WebGL Loss of Context error. This is particularly prevalent on Mac computers. Here is the behavior we have observed:

MovieStim appears to be frozen and TextStim, ImageStim & Rect disappear
MovieStim repeatedly shows a frozen version of a previous video in our trial loop, instead of playing the correct current video in the trial loop. Typically the audio for the correct video plays during display of the frozen frame of the previous video.
We initially thought it was because we had a problem with the URL and for some reason the program wasn’t able to track down the url. On debugging we found out the url is correct, and we can access it without any problem.
TextStim, ImageStim & Rect disappear:
These components disappear, and reappear if we change the size of the window.

In the javascript console, these problems occur with a WebGL warning. The image shows what the warning looks like for the video problem:

And the text/polygon problem:

On further investigation think we don’t have any direct control over this problem of “CONTEXT_LOST”, as this is not an error to catch and handle. What we understood about this error is that it is related to the browser releasing resources to reduce load on GPU.

Things we tried:

  • Changed video backend choices - moviepy, avbin, opencv. No difference, so all videos are currently set to use moviepy.
  • Ran a version with fewer videos (only 4) and increased repetitions of the trial loop to run for longer periods of time to simulate the time used for a longer list of videos. This did not change the error, we encountered the same error at approximately the same experimental time as when running a single repetition of a longer list of unique videos.
  • We tried to reinitialise MovieStim variable in the FrameRoutine, this kind of solved the problem but then we were left with the final frame of moviestim persisting on the on screen. For hiding this video frame we tried
    a) setautoDraw(false) : Still resulted in WebGL problem
    b) changing opacity or size : Still resulted in WebGL problem.

Things we wanted to try but couldn’t:
Creating an eventlistener to identify if WebGL context lost error has been thrown, if true we would reinitalise components such as MovieStim,ImageStim,TextStim and Rect and restore context.

How to reproduce:
Windows machine:
Processor Intel(R) Core™ i9-9900X CPU @ 3.50GHz, 3504 Mhz, 10 Core(s), 20 Logical Processor(s) Installed Physical Memory (RAM) 64.0 GB
Running the experiment on chrome on the above mentioned machine never produced a glitch/error as it had no need to release resources.

Mac machines:
A) MacBook Pro 2019 - 2.6 GHz 6-Core Intel Core i7, 32GB 2667 MHz DDR4, Intel UHD Graphics 630 1536 MB
B) MacBook Pro 2016 - 2.6 GHz Intel Core i7, 16 GB 2133 MHz LPDDR3, Intel Graphics 530 1536 MB
C) iMac 2018
It has run on A for about 9.5 minutes, B for 21 minutes, and C for about 9.5-10 minutes. Chrome as the web browser for A&B, unknown browser for C.

We released the task to 10 participants through mTurk (unknown hardware configurations) to see if some computers would be able to get through it. 0/10 were able to complete it, and some reported errors very early on, earlier than we have ever seen errors. The only saved data was from a participant who was able to get through 4 videos. According to the data file, that person was using a Mac computer.


  1. First of all is the code correctly set up? by this we mean, aren’t we breaking any syntactic / structural rule while using a component?
  2. Any suggestions for further ways to approach this problem?
  3. Does reinitialising work, if yes how to hide it on the frames where we don’t want it to be displayed?
  4. Is there a way to handle WebGL, that pavlovia endorses and that we should know and follow?
1 Like

Just a note that I’m also getting webGL errors (CONTEXT_LOST_WEBGL: loseContext: context lost), that result in texts not rendering. I’m playing rather big (i.e. long) audio files, that play ok even after losing context, but no texts are visibile until a new audio file is loaded.

Changing the size of the window makes the components reappear. Which is nice, but not really optimal, as I would prefer subjects to be immersed in the task and remain in full screen throughout the experiment. (Thanks fot the tip though @kristenk!!)

Happily for me this doesn’t prevent running the experiment and gathering data, but of course it would be nice to have things run smoothly for the participants. :slight_smile:

Running macOS 10.14.6 (2.6 GHz Intel Core i5, 8 GB 1600 MHz DDR3, Intel Iris 1536 MB) and Chrome 83.0.4103.116.