| Reference | Downloads | Github

Experiment crashing on iPhone

URL of experiment:

Description of the problem: My experiment/game now works on a touchscreen laptop without error (apart from an issue with blank instructions which I’m sure I can solve).

However, it is intended for use on mobile devices and seems to crash on my phone after about three trials.

Here is a pilot link you should be able to try:

Any ideas?

Best wishes,


First let me just say that this is a very impressive bit of design when it all works! I never really put together all of what it was doing when we were troubleshooting it, but a darts game with reasonable physics and dynamic scaling with “distance” is really an impressive demonstration of the flexibility of PsychoPy and Pavlovia and a nice bit of programming to boot. This would be non-trivial in python or JS alone, being able to do it in both is awesome.

Back to the matter at hand. I wasn’t able to use your pilot link but I cloned your repository and ran my own pilot on my Android phone. It worked through the first break and a couple of trials after that, then put a black square around the dart image and crashed. I then tried it in Chrome’s mobile-interface-simulation mode on my laptop (it’s in the dev console, the little tablet+phone icon in the top left next to the mouse icon) and it worked straight through.

So this is really narrowly something that happens only on mobile devices (not just in browser simulating being in mobile mode), and that’s more difficult to troubleshoot. It may actually be easier for you on an iPhone. The instructions here tell you how to pull up a JS console on your iPhone: Try that and see if you get any informative messages.

Thanks for the compliment. My Python coding has entirely been learned via customising PsychoPy experiments created in builder, and it looks like I will continue to avoid learning to program in Javascript.

I couldn’t find the setting for a JS console in Safari on my iPhone, so I’ll ask around for help. I’ve been using Chrome on my iPhone (this is my first Apple device after a string of Androids) but my wife got the same black square you experienced on her Android.

On thing the black square makes me thing of is the mask parameter. In Python the default is mask=None which autotranslates to mask=null which gives an error. Without the mask parameter it works but there is a warning:

log4javascript.min.js:1 WARN unknown | setting the mask of ImageStim: dart with argument: undefined.
log4javascript.min.js:1 WARN unknown | setting the value of attribute: mask in PsychObject: dart as: undefined

It’s clearly very close if it’s working in an emulator. I was wondering if the problem was due to one of the warnings, but all the others seem to be based on text stimuli:

Deprecation Warning: text style property 'font' is now deprecated, please use the 'fontFamily','fontSize',fontStyle','fontVariant' and 'fontWeight' properties from now on

WARN unknown | setting the value of attribute: seed in PsychObject: TrialHandler as: undefined

Best wishes,


My only thought about that is that unless these warnings are present on some trials but not others, it doesn’t explain why you get through some trials and then it fails rather than it just failing immediately. The fact that it fails after N trials could suggest a memory issue, but that seems unlikely and it would probably fail in a slightly different way. Unfortunately I’m just not experienced enough with developing for mobile browsers to really know what could be causing this.

@jon is there anyone who might have better insight into this kind of problem?

A friend has given me a pointer as to how to debug Javascript on mobile devices by attaching them to a computer. They used instructions from

I’ve also found some possibities for using iTunes libraries to debug an iPhone on a Windows computer, but I haven’t had a chance to try them yet. In the meantime my friend sent me this screenshot from her setup.

No error but the number by the last warning keeps incrementing.

WARN unknown | setting the value of attribute: text in PsychObject: instructions as: undefined

Instructions is causing an issue online, but I didn’t think it was the main problem. It’s coming up blank when it should be $blockinstruct[repeat.thisN] (currently set every frame in an attempt to fix it not working every repeat). I’ll therefore focus on that in the first instance, but I’d be surprised if it solved the issue.

I think that the error message

WebGL: CONTEXT_LOST_WEBGL: loseContext: context lost

occurs when the browser decides to crash out instead of staying in what it feels to be an infinite loop.

After some investigation I’ve narrowed down the problem to updating the dart’s position and size. It’s as if there is only enough memory to do this a fixed number of times.

The relevant code is:
Begin Experiment

dart = new visual.ImageStim({"win": win, "name": "dart", "image": "dandelion_dart.png", "ori": 0, "pos": [0, (- 0.35)], "size": [0.25, 0.25], "color": white, "colorSpace": "rgb", "opacity": 1, "flipHoriz": false, "flipVert": false, "texRes": 128, "interpolate": true});

Begin Routine

dartx = 0;
darty = (- 0.35);
dartsize = [0.25, 0.25];
dartvx = 0;
dartvy = 0;
dartoldpos = [0, (- 0.35)];
inflight = (- 1);
drag = [0.95, 0.9];
framecount = 0;
dart.size = dartsize;
dart.pos = [dartx, darty];


Each Frame (improved from previous version when the size and position were updated even with no movement)

else {
                    if ((inflight === 2)) {
                        dartx = (dartx + dartvx);
                        darty = (darty + dartvy);
                        dartvx = (dartvx * drag[0]);
                        dartvy = (dartvy * drag[1]);
                        dartsize = [(dartsize[0] * 0.99), (dartsize[1] * 0.98)];
                        dart.size = dartsize;
                        if ((dartvy < 0.001)) {
                            inflight = 3;
if (((abs(dartvx) + abs(dartvy)) > 0)) {
    dart.pos = [dartx, darty];

End Routine


I’ve replaced the dart image with a polygon which seems to have solved the problem (by avoiding it). My guess is that there is some form of memory leakage in the/my image code. The same issue may still be true for polygons but at a much lower level.



Yes, I think that’s right. See here: Update every frame doesnt work

@jon this memory thing is rearing its head again.

Yes, our working hypothesis is that certain stimuli are using graphcs card memory and that this isn’t properly cleared by standard garbage collection. That fits with Wakefield’s issue - a phone would typically have less graphics memeory so crashes sooner, and a polygon doesn’t need to put a texture on the card so no leak. I’m hoping we’ll be able to get to this soon now (the deluge of urgent lockdown-induced issues is coming a little more under control!)

was there any update on this? I have a similar issue which can’t be resolved by switching out images to polygons.


Have you already ensured that you only update your image(s) when they actually change? The other thing I tried was reducing the frame rate of my animation (e.g. by only updating a constantly moving image every 5 or 10 frames).

yeah my image and textstim are now set to either constant or set every repeat.

I still have the issue that if someone exits fullscreen mode or their phone goes to sleep this happens:

(the background image should take up the whole screen).


That sounds like a different issue. Are you using different units for your images and your background?

there was initially different units within a nested loop (but not within the inner loop where the bug appears to occur) - changing them all to a consistent unit seems to fix the issue of the phone going to sleep, but not exiting fullscreen mode - is exiting fullscreen mode a problem for your study?

Now you come to mention it I’m even getting into full screen mode when piloting on Chrome on my iPhone.

ok i seem to have fixed it by setting a bunch of the offending articles to “set every repeat” instead of constant, even though logically there shouldnt be any issue with setting to constant.

What I take from this is that something funky is still going on here but that setting it to every repeat wipes the slate clean.

ignore: i tried it on a different phone and encountered problems, this is weird

Constant means that they won’t change, even if the environment changes – and probably everything gets translated to pixels in the background, so it could be that the underlying value need to be updated even if the value in your code doesn’t change.

yeah that makes sense - i’m not sure why it would still work on laptop then but it seems to be working now so that’s that for now haha thanks.

Any updates on this? I’m having a very similar issue and only happens at random times with random participants (or what seems to be random)

We have certainly made some progress in tracking this down and we’re checking that the scope of the fix (i.e. does it cure all cases or just some?). We’re confident we can have this fixed in 2020.2 release (due in the next few weeks) so that you can use the full range of live-updating stimuli again :slight_smile: